-
Notifications
You must be signed in to change notification settings - Fork 0
296 lines (253 loc) · 9.8 KB
/
release.yml
File metadata and controls
296 lines (253 loc) · 9.8 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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
name: Release
run-name: Release ${{ inputs.version }} by ${{ github.actor }}
on:
workflow_dispatch:
inputs:
version:
description: "The release version in <MAJOR>.<MINOR>.<PATCH> format"
required: true
permissions:
contents: read
env:
DART_SUPPRESS_ANALYTICS: 'true'
jobs:
release:
name: Release
runs-on: ubuntu-latest
timeout-minutes: 120
permissions:
contents: write
steps:
- name: Check release version
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Release version must use <MAJOR>.<MINOR>.<PATCH> format." >&2
exit 1
fi
if [[ "${GITHUB_REF_TYPE}" != "branch" ]]; then
echo "Run the release workflow from a branch, not from ${GITHUB_REF_TYPE} ${GITHUB_REF_NAME}." >&2
exit 1
fi
- name: Checkout repository
uses: actions/checkout@v6.0.2
with:
fetch-depth: 0
token: ${{ secrets.QAMETA_CI }}
- name: Check release tags
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
packages=(
allure_dart_commons
allure_dart_test
allure_flutter_test
)
release_tag="v${version}"
if git rev-parse --verify --quiet "refs/tags/${release_tag}"; then
echo "Tag ${release_tag} already exists locally." >&2
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/${release_tag}" >/dev/null 2>&1; then
echo "Tag ${release_tag} already exists on origin." >&2
exit 1
fi
for package in "${packages[@]}"; do
tag="${package}-v${version}"
if git rev-parse --verify --quiet "refs/tags/${tag}"; then
echo "Tag ${tag} already exists locally." >&2
exit 1
fi
if git ls-remote --exit-code --tags origin "refs/tags/${tag}" >/dev/null 2>&1; then
echo "Tag ${tag} already exists on origin." >&2
exit 1
fi
done
- name: Check pub.dev versions
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
packages=(
allure_dart_commons
allure_dart_test
allure_flutter_test
)
for package in "${packages[@]}"; do
response="$(curl -fsSL "https://pub.dev/api/packages/${package}" 2>/dev/null || true)"
if grep -q "\"version\":\"${version}\"" <<<"$response"; then
echo "${package} ${version} is already published on pub.dev." >&2
exit 1
fi
done
- name: Configure CI Git user
run: |
git config --global user.name qameta-ci
git config --global user.email qameta-ci@qameta.io
- name: Set release version
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
perl -0pi -e "s/^version: .*/version: ${version}/m" \
packages/allure_dart_commons/pubspec.yaml \
packages/allure_dart_test/pubspec.yaml \
packages/allure_flutter_test/pubspec.yaml
perl -0pi -e "s/(allure_dart_commons:\s*)\^[^\s]+/\${1}^${version}/g" \
packages/allure_dart_test/pubspec.yaml \
packages/allure_flutter_test/pubspec.yaml
perl -0pi -e "s/(allure_dart_test:\s*)\^[^\s]+/\${1}^${version}/g" \
packages/allure_dart_commons/pubspec.yaml \
packages/allure_flutter_test/pubspec.yaml
for changelog in packages/*/CHANGELOG.md; do
if grep -Fq "## ${version}" "${changelog}"; then
continue
fi
existing="$(mktemp)"
awk '
NR == 1 && $0 == "# Changelog" {
skipped_heading = 1
next
}
skipped_heading && !emitted && $0 == "" {
next
}
{
emitted = 1
print
}
' "${changelog}" > "${existing}"
{
printf '# Changelog\n\n'
printf '## %s\n\n' "${version}"
printf 'This package is released from the `allure-dart` monorepo.\n\n'
printf 'Release notes are maintained centrally in the repository releases:\n'
printf 'https://github.com/allure-framework/allure-dart/releases\n'
if [ -s "${existing}" ]; then
printf '\n'
cat "${existing}"
fi
} > "${changelog}"
rm -f "${existing}"
done
for pubspec in \
packages/allure_dart_commons/pubspec.yaml \
packages/allure_dart_test/pubspec.yaml \
packages/allure_flutter_test/pubspec.yaml; do
grep -Fxq "version: ${version}" "${pubspec}"
done
for changelog in packages/*/CHANGELOG.md; do
grep -Fq "## ${version}" "${changelog}"
done
grep -Fq "allure_dart_commons: ^${version}" packages/allure_dart_test/pubspec.yaml
grep -Fq "allure_dart_commons: ^${version}" packages/allure_flutter_test/pubspec.yaml
grep -Fq "allure_dart_test: ^${version}" packages/allure_dart_commons/pubspec.yaml
grep -Fq "allure_dart_test: ^${version}" packages/allure_flutter_test/pubspec.yaml
git diff -- packages/*/pubspec.yaml packages/*/CHANGELOG.md
- name: Commit release version
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
if git diff --quiet -- packages/*/pubspec.yaml packages/*/CHANGELOG.md; then
echo "Package versions already match ${version}; using the current commit."
else
git add packages/*/pubspec.yaml packages/*/CHANGELOG.md
git commit -m "release ${version}"
fi
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
channel: stable
- name: Push release commit
shell: bash
run: |
set -euo pipefail
git push origin "HEAD:${{ github.ref_name }}"
- name: Push commons package tag
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
git tag "allure_dart_commons-v${version}"
git push origin "allure_dart_commons-v${version}"
- name: Wait for commons package to resolve
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
tmp_dir="$(mktemp -d)"
output="${tmp_dir}/pub-get.log"
trap 'rm -rf "${tmp_dir}"' EXIT
scripts/write-allure-dart-resolution-pubspec.sh "${version}" commons "${tmp_dir}/pubspec.yaml"
for attempt in {1..60}; do
echo "::group::Attempt ${attempt}/60: resolve allure_dart_commons ${version}"
if (cd "${tmp_dir}" && dart pub get > "${output}" 2>&1); then
echo "allure_dart_commons ${version} resolves with dart pub get."
echo "::endgroup::"
exit 0
fi
echo "Waiting for allure_dart_commons ${version} to resolve with dart pub get (${attempt}/60)."
head -40 "${output}" || true
echo "::endgroup::"
sleep 30
done
echo "allure_dart_commons ${version} did not resolve with dart pub get in time." >&2
exit 1
- name: Push package:test adapter tag
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
git tag "allure_dart_test-v${version}"
git push origin "allure_dart_test-v${version}"
- name: Wait for Dart packages to resolve
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
tmp_dir="$(mktemp -d)"
output="${tmp_dir}/pub-get.log"
trap 'rm -rf "${tmp_dir}"' EXIT
scripts/write-allure-dart-resolution-pubspec.sh "${version}" dart-test "${tmp_dir}/pubspec.yaml"
for attempt in {1..60}; do
echo "::group::Attempt ${attempt}/60: resolve allure_dart_commons and allure_dart_test ${version}"
if (cd "${tmp_dir}" && dart pub get > "${output}" 2>&1); then
echo "allure_dart_commons and allure_dart_test ${version} resolve with dart pub get."
echo "::endgroup::"
exit 0
fi
echo "Waiting for allure_dart_commons and allure_dart_test ${version} to resolve with dart pub get (${attempt}/60)."
head -40 "${output}" || true
echo "::endgroup::"
sleep 30
done
echo "allure_dart_commons and allure_dart_test ${version} did not resolve with dart pub get in time." >&2
exit 1
- name: Push Flutter adapter tag
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
git tag "allure_flutter_test-v${version}"
git push origin "allure_flutter_test-v${version}"
- name: Push release tag
shell: bash
run: |
set -euo pipefail
version="${{ inputs.version }}"
git tag "v${version}"
git push origin "v${version}"
- name: Publish GitHub release
uses: octokit/request-action@v2.x
with:
route: POST /repos/${{ github.repository }}/releases
tag_name: v${{ inputs.version }}
name: ${{ inputs.version }}
generate_release_notes: true
target_commitish: ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.QAMETA_CI }}