-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-template-github-workflows.yml
More file actions
148 lines (134 loc) · 5.33 KB
/
Copy pathsync-template-github-workflows.yml
File metadata and controls
148 lines (134 loc) · 5.33 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
---
# Reserved head branch prefix: chore/sync-boilerplate-workflows/<run_id> (automation only; supersession targets this stream).
name: Sync boilerplate files (GitHub workflows)
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
actions: write
contents: write
id-token: write
pull-requests: write
jobs:
sync:
name: Sync boilerplate files
runs-on: ubuntu-latest
env:
BRANCH_NAME: chore/sync-boilerplate-workflows/${{ github.run_id }}
COMMIT_MESSAGE: 'chore: auto-sync boilerplate files'
steps:
- uses: actions/checkout@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Sync files
id: sync
uses: michen00/boilerplate-sync@main
with:
sources: |
- source: michen00/template
default_files:
- .github/workflows/delete-bot-branches-for-closed-prs.yml
- .github/workflows/lint-github-actions.yml
- .github/workflows/pre-commit-autoupdate.yml
github-token: ${{ secrets.GITHUB_TOKEN }}
fail-on-error: 'true'
- name: Exit if no changes
if: steps.sync.outputs.has-changes == 'false'
run: |
echo '::notice::No changes detected. Exiting.'
exit 0
- name: Stage changes and create branch
run: |
set -e
git add .
git switch -c ${{ env.BRANCH_NAME }}
echo "::debug::$(git diff --cached || echo 'no changes')"
set +e
git diff --cached --quiet
exit_code=$?
set -e
if [ $exit_code -eq 0 ]; then
echo '::error::Sync action reported changes, but no files were staged. ' \
'This may indicate gitignore conflicts or other issues.'
exit 1
fi
echo '::notice::Changes staged. Proceeding with commit.'
git push -u origin ${{ env.BRANCH_NAME }}
- name: Commit changes
uses: iarekylew00t/verified-bot-commit@v2
with:
ref: ${{ env.BRANCH_NAME }}
auto-stage: false
if-no-commit: error
update-local: false
message: ${{ env.COMMIT_MESSAGE }}
files: |
.*
**/.*
**/*
- name: Build PR body
id: pr-body
uses: actions/github-script@v9
with:
result-encoding: string
script: |
const summary = JSON.parse(`${{ steps.sync.outputs.summary }}`);
let body = `## Boilerplate Sync\n\nThis PR updates project files from their boilerplate sources.\n\n`;
// Updated + Created files
const updated = [...summary.updated, ...summary.created];
if (updated.length > 0) {
body += `<details>\n<summary>Updated (${updated.length} file${updated.length === 1 ? '' : 's'})</summary>\n\n`;
for (const r of updated) {
body += `- \`${r.config.local_path}\`\n`;
}
body += `\n</details>\n\n`;
}
// Skipped files
if (summary.skipped.length > 0) {
body += `<details>\n<summary>Skipped (${summary.skipped.length} file${summary.skipped.length === 1 ? '' : 's'})</summary>\n\n`;
for (const r of summary.skipped) {
const reason = r.error || 'No changes detected';
body += `- \`${r.config.local_path}\` - ${reason}\n`;
}
body += `\n</details>\n\n`;
}
// Failed files (expanded by default)
if (summary.failed.length > 0) {
body += `<details open>\n<summary>Failed (${summary.failed.length} file${summary.failed.length === 1 ? '' : 's'})</summary>\n\n`;
for (const r of summary.failed) {
body += `- \`${r.config.local_path}\` - ${r.error}\n`;
}
body += `\n</details>\n\n`;
}
return body;
- name: Create pull request
id: create-pr
uses: peter-evans/create-pull-request@v8
with:
base: ${{ github.event.repository.default_branch }}
branch: ${{ env.BRANCH_NAME }}
title: ${{ env.COMMIT_MESSAGE }}
body: ${{ steps.pr-body.outputs.result }}
commit-message: ${{ env.COMMIT_MESSAGE }}
signoff: true
sign-commits: true
token: ${{ secrets.GITHUB_TOKEN }}
delete-branch: true
- name: Supersede older boilerplate PRs
if: steps.create-pr.outputs.pull-request-number != ''
uses: ./.github/actions/supersede-boilerplate-prs
with:
stream-prefix: chore/sync-boilerplate-workflows
successor-pr-number: ${{ steps.create-pr.outputs.pull-request-number }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger required checks
if: steps.create-pr.outputs.pull-request-number != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }}
run: |
echo "::info::PR #$PR_NUMBER created. Triggering required checks..."
# Trigger CI workflow to ensure checks run
gh workflow run ci.yml --ref ${{ env.BRANCH_NAME }} || echo "::warning::Failed to trigger CI workflow (may already be running)"