-
Notifications
You must be signed in to change notification settings - Fork 0
319 lines (243 loc) · 11.9 KB
/
reset_test_repo.yml
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
name: 🔂 Reset Test Repo
on:
workflow_dispatch:
env:
TARGET_REPO: "ynput/ayon-addon-action-testing"
DEFAULT_BRANCH: "develop"
MAIN_BRANCH: main
TEMPLATE_REPO: "ynput/ayon-addon-template"
GH_TOKEN: ${{ secrets.REPO_CTRL_TOKEN }}
REQUIRED_SECRECTS: CI_EMAIL,CI_USER,REPO_CTRL_TOKEN,YNPUT_BOT_TOKEN
jobs:
verify_repo_secrets:
runs-on: ubuntu-latest
steps:
- name: 🔎 Verify repo secrets for ${{ github.repository }}
id: verify_var
run: |
missing_vars=$(echo ${{ env.REQUIRED_SECRECTS }} | tr ',' '\n' | while read var; do
gh secret list --repo ${{ github.repository }} --json name --jq '.[].name' | grep -qx "$var" || echo "$var"
done)
if [ -n "$missing_vars" ]; then
echo "::error::The following required variables are missing: $missing_vars for repository ${{ github.repository }}"
exit 1
else
echo "::notice::All required variables are present."
fi
reset-test-repo:
runs-on: ubuntu-latest
needs: verify_repo_secrets
steps:
# TODO Implement early return to check if all required repo variables exist
# TODO Implement early return to check against list of testing repos
- name: Check for existing repo
id: repo-check
run: |
if ! gh repo view "${{ env.TARGET_REPO }}" > /dev/null 2>&1; then
echo "::error::Repository `${{ env.TARGET_REPO }}` doesn't exists - can't reset. Please create the repository first."
echo "repo_present=false" >> $GITHUB_OUTPUT
exit 1
fi
echo "repo_present=true" >> $GITHUB_OUTPUT
echo "::notice::Found Repository ${{ env.TARGET_REPO }}."
exit 0
- name: Delete repository if exists
if: steps.repo-check.outputs.repo_present
run: |
echo "::notice:: Deleting repository `${{ env.TARGET_REPO }}`"
gh repo delete "${{ env.TARGET_REPO }}" --yes
- name: Create new Repo `${{ env.TARGET_REPO }}` from template `${{ env.TEMPLATE_REPO }}`
run: |
gh repo create ${{ env.TARGET_REPO }} --template ${{ env.TEMPLATE_REPO }} --public
echo "::notice::Recreated repository `${{ env.TARGET_REPO }}` from template `${{ env.TEMPLATE_REPO }}`"
- name: Show branches
run: |
gh api repos/${{ env.TARGET_REPO }}/branches --jq '.[].name'
prepare-repo:
runs-on: ubuntu-latest
needs: reset-test-repo
env:
DEFAULT_BRANCH: "develop"
steps:
- name: Add ${{ github.actor }} as repo collaborator
# WARNING critical step - user will loose admin-permission in repo if step is removed or altered incorrect
if: always()
run: |
gh api --method PUT \
-H "Accept: application/vnd.github.v3+json" \
"/repos/${{ env.TARGET_REPO }}/collaborators/${{ github.actor }}" \
-f permission=admin
- name: Set repo secrets
run: |
gh secret set YNPUT_BOT_TOKEN --body "${{ secrets.YNPUT_BOT_TOKEN }}" --repo ${{ env.TARGET_REPO }}
gh secret set CI_USER --body "${{ secrets.CI_USER }}" --repo ${{ env.TARGET_REPO }}
gh secret set CI_EMAIL --body "${{ secrets.CI_EMAIL }}" --repo ${{ env.TARGET_REPO }}
echo "$(gh secret list --repo ${{ env.TARGET_REPO }})"
- name: Set repo variables
run: |
gh variable set PATCH_BUMP_LABEL --body "bugfix" --repo ${{ env.TARGET_REPO }}
gh variable set MINOR_BUMP_LABEL --body "feature, enhancement" --repo ${{ env.TARGET_REPO }}
gh variable set MAIN_BRANCH --body "main" --repo ${{ env.TARGET_REPO }}
gh variable set PROJECT_NAME --body "template" --repo ${{ env.TARGET_REPO }}
echo "$(gh variable list --repo ${{ env.TARGET_REPO }})"
- name: Add repo labels
run: |
gh label create "feature" --color "#008672" --description "New functionality which is not present so far" --repo ${{ env.TARGET_REPO }}
gh label create "bugfix" --color "#f96713" --description "Something got fixed" --repo ${{ env.TARGET_REPO }}
echo "$(gh label list --repo ${{ env.TARGET_REPO }})"
- name: Get latest sha from ${{ env.DEFAULT_BRANCH }}
id: latest-sha
run: |
commit_sha=$(gh api /repos/${{ env.TARGET_REPO }}/branches/develop -q '.commit.sha')
echo "sha=$commit_sha" >> $GITHUB_OUTPUT
- name: Add main branch
run: |
gh api \
-X POST \
-H "Accept: application/vnd.github.v3+json" \
/repos/${{ env.TARGET_REPO }}/git/refs \
-f ref="refs/heads/${{ env.MAIN_BRANCH }}" \
-f sha="${{ steps.latest-sha.outputs.sha }}"
add-local-changes:
runs-on: ubuntu-latest
needs: prepare-repo
steps:
- name: Checkout ${{ env.TARGET_REPO }} repo
uses: actions/checkout@v4
with:
token: ${{ env.GH_TOKEN }}
repository: ${{ env.TARGET_REPO }}
ref: ${{ env.DEFAULT_BRANCH }}
- name: Add PR Template
# TODO replace develop with main after initial release
run: |
curl -O https://raw.githubusercontent.com/${{ github.repository }}/develop/.github/pull_request_template.md
mv pull_request_template.md ./.github/pull_request_template.md
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
git add ./.github/pull_request_template.md
git commit -m "Add pr template"
git push origin ${{ env.DEFAULT_BRANCH }}
- name: Add initial-release workflow
# TODO replace develop with main after initial release
run: |
curl -O https://raw.githubusercontent.com/${{ github.repository }}/develop/caller_workflows/addon_repo_initial_release.yml
mv addon_repo_initial_release.yml ./.github/workflows/initial_release.yml
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
git add ./.github/workflows/initial_release.yml
git commit -m "Add initial release trigger workflow"
git push origin ${{ env.DEFAULT_BRANCH }}
- name: Add release workflow
# TODO replace develop with main after initial release
run: |
curl -O https://raw.githubusercontent.com/${{ github.repository }}/develop/caller_workflows/addon_repo_release_trigger.yml
mv addon_repo_release_trigger.yml ./.github/workflows/release_trigger.yml
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
git add ./.github/workflows/release_trigger.yml
git commit -m "Add release trigger workflow"
git push origin ${{ env.DEFAULT_BRANCH }}
- name: 🗒️ Adjust package.py
run: |
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
repo_name=$(basename ${{ env.TARGET_REPO }})
# INFO capitalize all letters after a "-" and the first one
repo_name_cap=$(echo "$repo_name" | sed -E 's/(^|-)(.)/\1\U\2/g')
sed -i "s/^version = \".*\"/version = \"0.1.0\"/" package.py
sed -i "s/^name = \".*\"/name = \"$repo_name\"/" package.py
sed -i "s/^title = \".*\"/title = \"$repo_name_cap\"/" package.py
git add package.py
git commit -m "Add warning information to readme."
git push origin ${{ env.DEFAULT_BRANCH }}
- name: 🗒️ Adjust readme
run: |
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
echo -e "# Not intended for Development\nThis is a testing repository for github actions.<br>Changes in this repository are likely to be reset by automanted testing procedures.<br>Don't use this repository for any development - use [ayon/ci-testing](https://github.com/ynput/ci-testing) instead." > README.md
git add README.md
git commit -m "Add warning information to readme"
git push origin ${{ env.DEFAULT_BRANCH }}
- name: Create first feature branch
run: |
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
git checkout -b test_feature01
date >> date.txt
git add date.txt
git commit -m "Add date file"
git push -u origin test_feature01
pr_body="
# Date file added
## Summary
Got a date file included
## Root Cause Analysis
[Issue Link](https://github.com/ynput/ci-testing/blob/develop/.github/ISSUE_TEMPLATE/bug_report.yml)
## Changelog
* Add date file
* Commit it
* Fix no date file
## Testing Strategy
Tested all the way.
## Checklist
* [x] The fix has been locally tested
* [x] New unit tests have been added to prevent future regressions
* [x] The documentation has been updated if necessary
"
gh pr create --base ${{ env.DEFAULT_BRANCH }} --head test_feature01 --title "Add date file" --body "$pr_body" --label "bugfix" --assignee "${{ github.actor }}"
- name: Create second feature branch
run: |
git config --global user.name "${{ secrets.CI_USER }}"
git config --global user.email "${{ secrets.CI_EMAIL }}"
git checkout -b test_feature02
free -h >> memory_usage.txt
git add memory_usage.txt
git commit -m "Add memory usage file"
git push -u origin test_feature02
pr_body="
# Memory usage check added
## Summary
Got a check for memory usage implemented
## Root Cause Analysis
[Issue Link](https://github.com/ynput/ci-testing/blob/develop/.github/ISSUE_TEMPLATE/bug_report.yml)
## Changelog
* Add text file
* Commit it the memory check
* Fix no memory usage file
## Testing Strategy
Tested all the way.
## Checklist
* [x] The fix has been locally tested
* [x] New unit tests have been added to prevent future regressions
* [x] The documentation has been updated if necessary
"
gh pr create --base ${{ env.DEFAULT_BRANCH }} --head test_feature02 --title "Add mem file" --body "$pr_body" --label "enhancement" --assignee "${{ github.actor }}"
preapre-release:
runs-on: ubuntu-latest
needs: add-local-changes
steps:
- name: Create GitHub Release
run: |
gh workflow run initial_release.yml --repo ${{ env.TARGET_REPO }}
- name: Poll for Draft Release
# TODO check if draft release creation emmits a signal or something to avoid this kind of pulling
id: poll-release
run: |
for i in {1..20}; do
DRAFT_RELEASE=$(gh release list --repo ${{ env.TARGET_REPO }} --limit 1 --json isDraft --jq '.[0].isDraft')
if [[ "$DRAFT_RELEASE" == "true" ]]; then
echo "Draft release found."
release_tag=$(gh release list --repo ${{ env.TARGET_REPO }} --limit 1 --json tagName --jq '.[0].tagName')
echo "release_tag=$release_tag" >> $GITHUB_OUTPUT
break
else
echo "Draft release not found yet, retrying in 15 seconds..."
sleep 15
fi
done
- name: Publish Release
if: steps.poll-release.outputs.release_tag
run: |
echo "release tag: ${{ steps.poll-release.outputs.release_tag }}"
gh release edit ${{ steps.poll-release.outputs.release_tag }} --draft=false --repo ${{ env.TARGET_REPO }}