-
Notifications
You must be signed in to change notification settings - Fork 27
381 lines (357 loc) · 16.5 KB
/
create-release-pr.yaml
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
name: Create Release PR
on:
workflow_dispatch:
inputs:
re_release:
description: 'Re-Release same version with fixes'
required: false
default: false
type: boolean
schedule:
- cron: "0 0 * * *"
jobs:
checks:
name: "Create Release PR"
permissions:
contents: write
pull-requests: write
runs-on: ubuntu-latest
outputs:
current_available_version: ${{ steps.current_available_version.outputs.version }}
current_global_version: ${{ steps.current_global_version.outputs.version }}
upgrade_available: ${{ steps.current_global_version.outputs.available }}
lint_plugins: ${{ steps.lint_plugins.outputs.lint_plugins }}
unit_test_plugins: ${{ steps.unit_test_plugins.outputs.unit_test_plugins }}
integration_test_plugins: ${{ steps.integration_test_plugins.outputs.integration_test_plugins }}
integration_test_exit_code: ${{ steps.integration_test_plugins.outputs.integration_test_exit_code }}
all_potential_upgrades: ${{ steps.all_potential_upgrades.outputs.all_potential_upgrades }}
pr_body: ${{ steps.prepare_pr.outputs.pr_body }}
tag_version: ${{ steps.prepare_pr.outputs.tag_version }}
defaults:
run:
working-directory: .
steps:
#----------------------------------------------
# Check out repo
#----------------------------------------------
- uses: actions/checkout@v4
#----------------------------------------------
# Setup python
#----------------------------------------------
- uses: actions/setup-python@v5
with:
python-version: '3.9'
#----------------------------------------------
# Install poetry
#----------------------------------------------
- name: Install poetry
run: pipx install poetry
id: setup-poetry
#----------------------------------------------
# Get the latest version of aries-cloudagent from pypi
#----------------------------------------------
- name: Get latest aries-cloudagent version
id: current_available_version
run: |
remote_version=$(pip index versions aries-cloudagent)
version=$(grep -oP '(?<=Available versions: ).*?(?=,)' <<< "$remote_version")
echo current_available_version=$version >> $GITHUB_OUTPUT
echo "Remote version = $version"
#----------------------------------------------
# Check the latest version from plugins_global lock file
#----------------------------------------------
- name: Get global aries-cloudagent version from plugins repo
id: current_global_version
run: |
cd plugin_globals
lock_version=$(grep -A1 'name = "aries-cloudagent"' poetry.lock | grep -v 'name = "aries-cloudagent"')
version=$(grep -oP '(?<=").*?(?=")' <<< "$lock_version")
echo current_global_version=$version >> $GITHUB_OUTPUT
echo "Global version = $version"
#----------------------------------------------
# Re-Release Check
#----------------------------------------------
- name: Re-Release Check
if: github.event.inputs.re_release == 'true'
run: |
echo "Re-Release manually requested. Skipping upgrade available check."
#----------------------------------------------
# Check if aries-cloudagent upgrade available
# If the global version is greater than or equal to the remote version, exit
#----------------------------------------------
- name: Check if aries-cloudagent upgrade available
id: upgrade_available
if: github.event.inputs.re_release != 'true'
run: |
current_available_version="${{steps.current_available_version.outputs.current_available_version}}"
echo "Remote version = $current_available_version"
current_global_version="${{steps.current_global_version.outputs.current_global_version}}"
echo "Global version = $current_global_version"
# Compare versions
sem_version () {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}
if [ $(sem_version $current_global_version) -ge $(sem_version $current_available_version) ]; then
echo "Version of aries-cloudagent is up to date"
exit 0
fi
echo available=true >> $GITHUB_OUTPUT
echo "Detected aries-cloudagent upgrade available..."
#----------------------------------------------
# Update global aries-cloudagent version in lock file
#----------------------------------------------
- name: Update global acapy version
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
run: |
python repo_manager.py 3
echo "Update global acapy version"
#----------------------------------------------
# Update all plugins with aries-cloudagent and global and local dependencies
#----------------------------------------------
- name: Run global updates
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
run: |
python repo_manager.py 2
echo "Upgrade all plugins"
#----------------------------------------------
# Get all potential upgrades
#----------------------------------------------
- name: Get all potential upgrades
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
id: all_potential_upgrades
run: |
declare -a potential_upgrades=()
echo "Checking for potential upgrades"
upgraded_plugins=$(python repo_manager.py 5)
echo "Upgraded plugins: $upgraded_plugins"
for dir in ./*/; do
current_folder=$(basename "$dir")
if [[ $current_folder == "plugin_globals" ]]; then
continue
fi
found=false
for plugin in ${upgraded_plugins}; do
if [[ $current_folder == *"$plugin"* ]]; then
found=true
break
fi
done
if [[ $found != true ]]; then
potential_upgrades+=("$current_folder")
fi
done
echo "Potential upgrades: ${potential_upgrades[*]}"
echo all_potential_upgrades=${potential_upgrades[*]} >> $GITHUB_OUTPUT
#----------------------------------------------
# Collect plugins that fail linting
#----------------------------------------------
- name: Lint plugins
id: lint_plugins
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
continue-on-error: true
run: |
declare -a failed_plugins=()
for dir in ./*/; do
current_folder=$(basename "$dir")
if [[ $current_folder == "plugin_globals" ]]; then
continue
fi
cd $current_folder
poetry install --no-interaction --no-root --extras "aca-py"
if poetry run ruff check .; then
echo "plugin $current_folder passed lint check"
else
echo "plugin $current_folder failed lint check"
failed_plugins+=("$current_folder")
fi
cd ..
done
echo lint_plugins=${failed_plugins[*]} >> $GITHUB_OUTPUT
#----------------------------------------------
# Collect plugins that fail unit tests
#----------------------------------------------
- name: Unit Test Plugins
id: unit_test_plugins
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
continue-on-error: true
run: |
declare -a failed_plugins=()
for dir in ./*/; do
current_folder=$(basename "$dir")
if [[ $current_folder == "plugin_globals" ]]; then
continue
fi
cd $current_folder
poetry install --no-interaction --no-root --extras "aca-py"
if poetry run pytest; then
echo "plugin $current_folder passed unit test check"
else
echo "plugin $current_folder failed unit test check"
failed_plugins+=("$current_folder")
fi
cd ..
done
echo unit_test_plugins=${failed_plugins[*]} >> $GITHUB_OUTPUT
# ----------------------------------------------
# Install docker compose
# ----------------------------------------------
- name: Initialize Docker Compose
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
uses: isbang/compose-action@v1.5.1
# ----------------------------------------------
# Collect plugins that fail integration tests
# ----------------------------------------------
- name: Integration Test Plugins
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
id: integration_test_plugins
continue-on-error: true
run: |
trap 'echo "integration_test_exit_code=$?" >> "$GITHUB_OUTPUT"' EXIT
declare -a failed_plugins=()
for dir in ./*/; do
current_folder=$(basename "$dir")
if [[ $current_folder == "plugin_globals" ]]; then
continue
fi
cd $current_folder/integration
docker compose down --remove-orphans
docker compose build
if docker compose run tests; then
echo "plugin $current_folder passed integration test check"
else
echo "plugin $current_folder failed integration test check"
failed_plugins+=("$current_folder")
fi
cd ../..
done
echo integration_test_plugins=${failed_plugins[*]} >> $GITHUB_OUTPUT
#----------------------------------------------
# Integration Test Failure Check
#----------------------------------------------
- name: Integration Test Failure Check
if: steps.integration_test_plugins.outputs.integration_test_exit_code == '17'
run: |
echo "Integration tests failed with exit code 17. Skipping commit and release"
echo integration_test_exit_code=17 >> $GITHUB_OUTPUT
# ----------------------------------------------
# Prepare Pull Request
# ----------------------------------------------
- name: Prepare Pull Request
id: prepare_pr
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
run: |
echo "Merging failed plugins"
failed_plugins=()
# Merge all failed plugins
potential_upgrades=(${{ steps.all_potential_upgrades.outputs.all_potential_upgrades }})
echo "All potential upgrades: ${{ steps.all_potential_upgrades.outputs.all_potential_upgrades }}"
lint_plugins=(${{steps.lint_plugins.outputs.lint_plugins}})
unit_test_plugins=(${{steps.unit_test_plugins.outputs.unit_test_plugins}})
integration_test_plugins=(${{steps.integration_test_plugins.outputs.integration_test_plugins}})
for plugin in "${lint_plugins[@]}"; do
if [[ ! " ${failed_plugins[@]} " =~ " $plugin " ]]; then
failed_plugins+=("$plugin")
fi
done
for plugin in "${unit_test_plugins[@]}"; do
if [[ ! " ${failed_plugins[@]} " =~ " $plugin " ]]; then
failed_plugins+=("$plugin")
fi
done
for plugin in "${integration_test_plugins[@]}"; do
if [[ ! " ${failed_plugins[@]} " =~ " $plugin " ]]; then
failed_plugins+=("$plugin")
fi
done
echo "Failed plugins: ${failed_plugins[*]}"
# Get release for the branch name and docs
release_version="${{steps.current_available_version.outputs.current_available_version}}"
echo "Remote version = $release_version"
# Configure the git bot
git config --global user.name 'Release Bot'
git config --global user.email 'release-bot@users.noreply.github.com'
# Add all the changed files and then remove the failed plugins
git add .
for plugin in "${failed_plugins[@]}"; do
git restore --staged $plugin
git checkout -- $plugin
done
# Get the release notes and update the plugin decription with acapy version
body=$(python repo_manager.py 4)
# Determine the release version via tags
get_tags_output=$(git tag -n0 "*$release_version*")
echo "Tag output: ${get_tags_output}"
tags_num=0
for item in ${get_tags_output}; do
tags_num=$((tags_num+1))
done
tag_version=""
if [ $tags_num -eq 0 ]
then
tag_version=$release_version
else
tag_version="$release_version.$tags_num"
fi
# Update the RELEASES.md file with the release notes
echo "$body" | cat - RELEASES.md > temp && mv temp RELEASES.md
# Check if there are any upgrades
upgraded_plugins=($(python repo_manager.py 5))
has_upgrades=false
for plugin in ${potential_upgrades[@]}; do
for upgrade in ${upgraded_plugins[@]}; do
if [[ $plugin == *"$upgrade"* ]]; then
has_upgrades=true
break
fi
done
done
if [ "$has_upgrades" = true ]
then
echo "Upgrades detected. Committing the changes"
else
echo "No upgrades detected. Skipping commit and release"
exit 1
fi
# Update the release notes with the upgraded plugins.
# For replacing with the sed command we need to double escape the newline and tab characters.
details=$(printf '#### Plugins upgraded this release: \n\t - ')
double_escape_details=$(printf '#### Plugins upgraded this release: \\n\\t - ')
# For replacing the first occurence of ' - ' with the details
count=${#upgraded_plugins[*]}
for i in $(seq 0 "$(("$count" - 2))" );
do
details=$(printf '%s %s \n\t - ' "$details" "${upgraded_plugins[$i]}")
double_escape_details=$(printf '%s %s \\n\\t - ' "$double_escape_details" "${upgraded_plugins[$i]}")
done
details=$(printf '%s %s \n' "$details" "${upgraded_plugins[$count - 1]}")
double_escape_details=$(printf '%s %s \n' "$double_escape_details" "${upgraded_plugins[$count - 1]}")
# Replace the first occurence of ' - ' with the details
sed -i "0,/\s\-\s/s// - $(printf '%s ' ${double_escape_details})/" RELEASES.md
# Replace the release version with the release tag
sed -i "0,/v$release_version/{s/v$release_version/v$tag_version/}" RELEASES.md
body=${body/v$release_version/v$tag_version}
# Prepare the PR body
EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64)
echo "pr_body<<$EOF" >> $GITHUB_OUTPUT
echo "$body $details" >> $GITHUB_OUTPUT
echo "$EOF" >> $GITHUB_OUTPUT
# Set the tag version output
echo tag_version=$tag_version >> $GITHUB_OUTPUT
#----------------------------------------------
# Create Release PR
#----------------------------------------------
- name: Create PR
if: ${{ steps.upgrade_available.outputs.available == 'true' && github.event.inputs.re_release != 'true'}}
uses: peter-evans/create-pull-request@v6
with:
author: Release Bot <release-bot@users.noreply.github.com>
committer: Release Bot <release-bot@users.noreply.github.com>
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Release v${{ steps.prepare_pr.outputs.tag_version }} Upgrades"
title: "Release for aries-cloudagent v${{ steps.prepare_pr.outputs.tag_version }}"
body: "${{ steps.prepare_pr.outputs.pr_body }}"
branch: "release-v${{ steps.prepare_pr.outputs.tag_version }}"
base: "main"
draft: false
signoff: true
delete-branch: true