-
-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (173 loc) · 7.78 KB
/
Copy pathwiki-maintenance.yml
File metadata and controls
202 lines (173 loc) · 7.78 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
name: Maintain Wiki Publication
on:
workflow_call:
permissions:
contents: read
env:
FORCE_COLOR: '1'
jobs:
publish:
name: Publish Wiki Master
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
env:
WIKI_PUBLISH_BRANCH: master
WIKI_PREVIEW_BRANCH: pr-${{ github.event.pull_request.number }}
steps:
- name: Checkout main branch
uses: actions/checkout@v7
with:
token: ${{ github.token }}
ref: main
submodules: recursive
fetch-depth: 0
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v7
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Detect wiki repository
id: detect_wiki
run: |
if [ -e .github/wiki ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Mark workspace as safe for git
if: steps.detect_wiki.outputs.exists == 'true'
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config --global --add safe.directory "$GITHUB_WORKSPACE/.github/wiki"
- name: Prepare wiki publish branch from preview branch
if: steps.detect_wiki.outputs.exists == 'true'
id: prepare_publish
uses: ./.dev-tools-actions/.github/actions/wiki/prepare-publish-branch
with:
publish-branch: ${{ env.WIKI_PUBLISH_BRANCH }}
preview-branch: ${{ env.WIKI_PREVIEW_BRANCH }}
- name: Push wiki publish branch
if: steps.detect_wiki.outputs.exists == 'true'
working-directory: .github/wiki
run: git push --force-with-lease origin HEAD:"${WIKI_PUBLISH_BRANCH}"
- name: Validate wiki publish branch
if: steps.detect_wiki.outputs.exists == 'true'
uses: ./.dev-tools-actions/.github/actions/wiki/validate-publish-branch
with:
publish-branch: ${{ env.WIKI_PUBLISH_BRANCH }}
preview-branch: ${{ env.WIKI_PREVIEW_BRANCH }}
expected-preview-sha: ${{ steps.prepare_publish.outputs.expected-preview-sha }}
- name: Delete wiki preview branch
if: steps.detect_wiki.outputs.exists == 'true'
uses: ./.dev-tools-actions/.github/actions/wiki/delete-preview-branch
with:
preview-branch: ${{ env.WIKI_PREVIEW_BRANCH }}
- uses: ./.dev-tools-actions/.github/actions/summary/write
with:
markdown: |
## Wiki Publish Summary
- Publish branch: `${{ env.WIKI_PUBLISH_BRANCH }}`
- Preview branch: `${{ env.WIKI_PREVIEW_BRANCH }}`
- Wiki repository detected: `${{ steps.detect_wiki.outputs.exists }}`
- Expected preview SHA: `${{ steps.detect_wiki.outputs.exists == 'true' && steps.prepare_publish.outputs.expected-preview-sha || 'skipped' }}`
- Publish validation: `${{ steps.detect_wiki.outputs.exists == 'true' && 'completed' || 'skipped' }}`
- Preview cleanup: `${{ steps.detect_wiki.outputs.exists == 'true' && format('{0} deleted', env.WIKI_PREVIEW_BRANCH) || 'skipped' }}`
cleanup_closed_preview:
name: Delete Closed PR Wiki Preview
if: github.event_name == 'pull_request_target' && github.event.pull_request.merged == false
runs-on: ubuntu-latest
permissions:
contents: write
env:
WIKI_PREVIEW_BRANCH: pr-${{ github.event.pull_request.number }}
steps:
- name: Checkout main branch
uses: actions/checkout@v7
with:
token: ${{ github.token }}
ref: main
submodules: recursive
fetch-depth: 0
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v7
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Detect wiki repository
id: detect_wiki
run: |
if [ -e .github/wiki ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Mark wiki workspace as safe for git
if: steps.detect_wiki.outputs.exists == 'true'
run: git config --global --add safe.directory "$GITHUB_WORKSPACE/.github/wiki"
- name: Delete wiki preview branch
if: steps.detect_wiki.outputs.exists == 'true'
uses: ./.dev-tools-actions/.github/actions/wiki/delete-preview-branch
with:
preview-branch: ${{ env.WIKI_PREVIEW_BRANCH }}
- uses: ./.dev-tools-actions/.github/actions/summary/write
with:
markdown: |
## Wiki Preview Cleanup Summary
- Wiki repository detected: `${{ steps.detect_wiki.outputs.exists }}`
- Deleted preview branch: `${{ steps.detect_wiki.outputs.exists == 'true' && env.WIKI_PREVIEW_BRANCH || 'skipped' }}`
- Trigger: `${{ steps.detect_wiki.outputs.exists == 'true' && 'closed pull request without merge' || 'wiki repository not present' }}`
cleanup_orphaned_previews:
name: Delete Orphaned Wiki Previews
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: read
steps:
- name: Checkout main branch
uses: actions/checkout@v7
with:
token: ${{ github.token }}
ref: main
submodules: recursive
fetch-depth: 0
- name: Checkout dev-tools workflow action source
uses: actions/checkout@v7
with:
repository: php-fast-forward/dev-tools
ref: ${{ github.repository == 'php-fast-forward/dev-tools' && (github.event_name == 'pull_request_target' && github.event.pull_request.base.sha || github.sha) || 'main' }}
path: .dev-tools-actions
sparse-checkout: |
.github/actions
- name: Detect wiki repository
id: detect_wiki
run: |
if [ -e .github/wiki ]; then
echo "exists=true" >> "$GITHUB_OUTPUT"
else
echo "exists=false" >> "$GITHUB_OUTPUT"
fi
- name: Mark wiki workspace as safe for git
if: steps.detect_wiki.outputs.exists == 'true'
run: git config --global --add safe.directory "$GITHUB_WORKSPACE/.github/wiki"
- name: Delete wiki branches for closed pull requests
if: steps.detect_wiki.outputs.exists == 'true'
id: cleanup
uses: ./.dev-tools-actions/.github/actions/wiki/cleanup-orphaned-previews
- uses: ./.dev-tools-actions/.github/actions/summary/write
with:
markdown: |
## Wiki Orphan Cleanup Summary
- Wiki repository detected: `${{ steps.detect_wiki.outputs.exists }}`
- Deleted preview branches: `${{ steps.detect_wiki.outputs.exists == 'true' && (steps.cleanup.outputs.deleted || '0') || '0' }}`
- Retained preview branches: `${{ steps.detect_wiki.outputs.exists == 'true' && (steps.cleanup.outputs.skipped || '0') || '0' }}`
- Unresolved preview branches: `${{ steps.detect_wiki.outputs.exists == 'true' && (steps.cleanup.outputs.unresolved || '0') || '0' }}`