-
Notifications
You must be signed in to change notification settings - Fork 3
276 lines (238 loc) · 9.54 KB
/
Copy pathupdate-repository.yml
File metadata and controls
276 lines (238 loc) · 9.54 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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Update Repository Index and README
on:
pull_request_target:
types: [closed]
permissions:
contents: write
pull-requests: write
issues: write
jobs:
check-label:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
outputs:
has_valid_label: ${{ steps.check-label.outputs.has_valid_label }}
steps:
- name: Check for validation-passed label
id: check-label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.APP_INSTALLATION_TOKEN }}
script: |
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const hasValidLabel = labels.some(label => label.name === 'validation-passed');
console.log(`Pull request has validation-passed label: ${hasValidLabel}`);
core.setOutput('has_valid_label', hasValidLabel ? 'true' : 'false');
update-index:
needs: check-label
runs-on: ubuntu-latest
if: needs.check-label.outputs.has_valid_label == 'true'
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.APP_INSTALLATION_TOKEN }}
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v46
with:
files: "commands/**"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install script dependencies
run: npm install
working-directory: .github/scripts
- name: Update repo index
id: update_index
env:
GITHUB_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
run: |
# Get list of changed files from the action output
CHANGED_FILES="${{ steps.changed-files.outputs.added_files }} ${{ steps.changed-files.outputs.modified_files }}"
# Run the Node.js script to update the index
node .github/scripts/update-repo-index.js "$CHANGED_FILES"
# Check if there are changes to commit
if git diff --name-only | grep -q "repo-index.json"; then
echo "changes_made=true" >> $GITHUB_OUTPUT
else
echo "changes_made=false" >> $GITHUB_OUTPUT
fi
- name: Commit and push if index changed
if: steps.update_index.outputs.changes_made == 'true'
env:
GITHUB_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
run: |
# Set git config
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Stage changes
git add .github/repo-index.json
# Stash changes
git stash push -m "repo-index update by workflow"
# Pull latest changes with rebase
RETRY_COUNT=0
MAX_RETRIES=5
RETRY_DELAY=5
while ! git pull --rebase origin main; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Pull failed after $MAX_RETRIES attempts."
git rebase --abort || echo "Rebase abort failed, continuing..."
git stash pop || echo "Stash pop failed after pull failure."
exit 1
fi
echo "Pull failed, retrying in $RETRY_DELAY seconds... (Attempt $RETRY_COUNT/$MAX_RETRIES)"
sleep $RETRY_DELAY
RETRY_DELAY=$((RETRY_DELAY * 2)) # Exponential backoff
done
# Apply stashed changes
if ! git stash pop; then
echo "Stash pop failed, likely due to conflicts after rebase. Manual intervention required."
exit 1
fi
# Re-add changes after stash pop
git add .github/repo-index.json
# Commit and push
git commit -m "chore: update repository index with enhanced metadata [skip ci]"
git push origin main
update-readme:
needs: [check-label, update-index]
runs-on: ubuntu-latest
if: needs.check-label.outputs.has_valid_label == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
ref: main
# Ensure we get the latest code including changes from previous job
fetch-depth: 0
token: ${{ secrets.APP_INSTALLATION_TOKEN }}
- name: Fetch latest changes
run: |
# Fetch the latest changes from the remote repository
git fetch origin main
# Force checkout to the latest commit on main (including changes from previous job)
git checkout -B main origin/main
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install script dependencies
run: npm install
working-directory: .github/scripts
- name: Update Applications list in README
id: update_readme
run: node .github/scripts/update-readme-list.js
- name: Commit and push if README changed
if: steps.update_readme.outputs.changes_made == 'true'
env:
GITHUB_TOKEN: ${{ secrets.APP_INSTALLATION_TOKEN }}
run: |
# Set git config
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Stage changes
git add README.md
# Check if there are changes to commit
if git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
# Stash changes
git stash push -m "readme update by workflow"
# Pull latest changes with rebase
RETRY_COUNT=0
MAX_RETRIES=5
RETRY_DELAY=5
while ! git pull --rebase origin main; do
RETRY_COUNT=$((RETRY_COUNT + 1))
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
echo "Pull failed after $MAX_RETRIES attempts."
git rebase --abort || echo "Rebase abort failed, continuing..."
git stash pop || echo "Stash pop failed after pull failure."
exit 1
fi
echo "Pull failed, retrying in $RETRY_DELAY seconds... (Attempt $RETRY_COUNT/$MAX_RETRIES)"
sleep $RETRY_DELAY
RETRY_DELAY=$((RETRY_DELAY * 2)) # Exponential backoff
done
# Apply stashed changes
if ! git stash pop; then
echo "Stash pop failed, likely due to conflicts after rebase. Manual intervention required."
exit 1
fi
# Re-add README.md in case stash pop changed the staged status
git add README.md
# Commit and push
git commit -m "docs: Update README with latest applications list [skip ci]"
git push origin main
remove-validation-label:
needs: [update-readme]
runs-on: ubuntu-latest
if: always()
steps:
- name: Remove validation-passed label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.APP_INSTALLATION_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'validation-passed'
});
console.log('Successfully removed validation-passed label');
} catch (error) {
// If the label doesn't exist, don't fail the workflow
if (error.status === 404) {
console.log('Label validation-passed not found on this PR, continuing');
} else {
console.error('Error removing label:', error);
throw error;
}
}
remove-command-update-label:
needs: [update-readme]
runs-on: ubuntu-latest
if: always()
steps:
- name: Remove command-update label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.APP_INSTALLATION_TOKEN }}
script: |
try {
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo
});
const hasCommandUpdateLabel = labels.some(label => label.name === 'command-update');
if (hasCommandUpdateLabel) {
await github.rest.issues.removeLabel({
issue_number: context.payload.pull_request.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: 'command-update'
});
console.log('Successfully removed command-update label');
} else {
console.log('Label command-update not found on this PR, skipping removal');
}
} catch (error) {
// If the label doesn't exist, don't fail the workflow
if (error.status === 404) {
console.log('Label command-update not found on this PR, continuing');
} else {
console.error('Error removing label:', error);
throw error;
}
}