-
Notifications
You must be signed in to change notification settings - Fork 0
192 lines (160 loc) · 5.7 KB
/
Copy pathupdate-repo.yml
File metadata and controls
192 lines (160 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Update APK Repository
on:
workflow_dispatch:
inputs:
project:
description: 'Specific project to update (leave empty for all)'
required: false
type: string
dry_run:
description: 'Dry run (do not create PR)'
required: false
type: boolean
default: false
rebuild:
description: 'Force rebuild all packages (re-download and re-process)'
required: false
type: boolean
default: false
permissions:
contents: write
pull-requests: write
jobs:
generate:
runs-on: ubuntu-latest
container:
image: alpine:latest
steps:
- name: Install dependencies
run: |
apk add --no-cache git python3 py3-pip py3-yaml openssl bash curl abuild
- name: Checkout main branch
uses: actions/checkout@v4
with:
path: main
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
path: gh-pages
continue-on-error: true
- name: Initialize gh-pages if not exists
shell: bash
run: |
if [ ! -d "gh-pages/.git" ]; then
mkdir -p gh-pages
cd gh-pages
git init
git checkout -b gh-pages
echo "# APK Repository" > README.md
git add README.md
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -m "Initialize gh-pages branch"
fi
- name: Setup RSA signing key
if: ${{ vars.APK_SIGNING_KEY != '' }}
shell: bash
run: |
echo "${{ secrets.APK_PRIVATE_KEY }}" > /tmp/signing.key
chmod 600 /tmp/signing.key
- name: Generate APK repository
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd main
ARGS="--config projects.yaml --output ../gh-pages"
if [ -n "${{ github.event.inputs.project }}" ]; then
ARGS="$ARGS --project '${{ github.event.inputs.project }}'"
fi
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
ARGS="$ARGS --dry-run"
fi
if [ "${{ github.event.inputs.rebuild }}" = "true" ]; then
ARGS="$ARGS --rebuild"
fi
if [ -n "${{ vars.APK_SIGNING_KEY }}" ]; then
ARGS="$ARGS --private-key /tmp/signing.key"
else
ARGS="$ARGS --no-sign"
fi
eval python3 scripts/generate_repo.py $ARGS
- name: Check for changes
if: ${{ github.event.inputs.dry_run != 'true' }}
id: changes
shell: bash
run: |
cd gh-pages
git add -A
if git diff --cached --quiet; then
echo "has_changes=false" >> $GITHUB_OUTPUT
echo "No changes detected"
else
echo "has_changes=true" >> $GITHUB_OUTPUT
echo "Changes detected:"
git diff --cached --name-only
fi
- name: Create Pull Request
if: ${{ github.event.inputs.dry_run != 'true' && steps.changes.outputs.has_changes == 'true' }}
shell: bash
run: |
# Install GitHub CLI
apk add --no-cache github-cli
cd gh-pages
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create unique branch name
BRANCH_NAME="update-repo/${{ github.run_id }}"
git checkout -b "$BRANCH_NAME"
# Commit changes
if [ -n "${{ github.event.inputs.project }}" ]; then
COMMIT_MSG="chore: update ${{ github.event.inputs.project }} packages"
else
COMMIT_MSG="chore: update all packages"
fi
git commit -m "$COMMIT_MSG"
# Push branch
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git"
git push -u origin "$BRANCH_NAME"
# Create PR
cd ../main
if [ -n "${{ github.event.inputs.project }}" ]; then
PR_TITLE="Update APK packages: ${{ github.event.inputs.project }}"
else
PR_TITLE="Update APK packages: all projects"
fi
# Get list of changed files
CHANGED_FILES=$(cd ../gh-pages && git diff --name-only HEAD~1 2>/dev/null || echo "New repository initialization")
# Create PR body
PR_BODY="## Summary
Automated update of APK repository packages.
**Triggered by:** ${{ github.actor }}
**Run ID:** ${{ github.run_id }}
## Changes
\`\`\`
${CHANGED_FILES}
\`\`\`
---
🤖 Generated by GitHub Actions"
gh pr create \
--base gh-pages \
--head "$BRANCH_NAME" \
--title "$PR_TITLE" \
--body "$PR_BODY"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Summary
shell: bash
run: |
if [ "${{ github.event.inputs.dry_run }}" = "true" ]; then
echo "## Dry Run Complete" >> $GITHUB_STEP_SUMMARY
echo "No changes were made." >> $GITHUB_STEP_SUMMARY
elif [ "${{ steps.changes.outputs.has_changes }}" = "true" ]; then
echo "## PR Created" >> $GITHUB_STEP_SUMMARY
echo "A pull request has been created to update the APK repository." >> $GITHUB_STEP_SUMMARY
else
echo "## No Changes" >> $GITHUB_STEP_SUMMARY
echo "No package updates were needed." >> $GITHUB_STEP_SUMMARY
fi