-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (179 loc) · 6.87 KB
/
Copy pathrelease.yml
File metadata and controls
213 lines (179 loc) · 6.87 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
name: Release
on:
workflow_dispatch:
inputs:
target_branch:
description: Release branch
required: true
type: choice
options:
- develop
- main
version:
description: Release version (X.Y.Z)
required: true
type: string
permissions:
actions: write
contents: write
concurrency:
group: release-${{ inputs.target_branch }}
cancel-in-progress: false
env:
CARGO_TERM_COLOR: always
jobs:
plan:
runs-on: ubuntu-latest
outputs:
previous_version: ${{ steps.plan.outputs.previous_version }}
version: ${{ steps.plan.outputs.version }}
target_branch: ${{ steps.plan.outputs.target_branch }}
steps:
- name: Checkout selected branch
uses: actions/checkout@v4
with:
ref: ${{ inputs.target_branch }}
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Plan release
id: plan
env:
TARGET_BRANCH: ${{ inputs.target_branch }}
RELEASE_VERSION: ${{ inputs.version }}
run: devops/ga-release-plan.sh
prepare_release:
needs: plan
runs-on: ubuntu-latest
outputs:
release_sha: ${{ steps.release_commit.outputs.release_sha }}
steps:
- name: Checkout target branch
uses: actions/checkout@v4
with:
ref: ${{ needs.plan.outputs.target_branch }}
fetch-depth: 0
- name: Fetch tags
run: git fetch --force --tags
- name: Verify tag does not already exist
shell: bash
run: |
if git rev-parse "refs/tags/${{ needs.plan.outputs.version }}" >/dev/null 2>&1; then
echo "Tag ${{ needs.plan.outputs.version }} already exists."
exit 1
fi
- name: Configure git author
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
- name: Create release commit
id: release_commit
shell: bash
run: |
set -euo pipefail
version="${{ needs.plan.outputs.version }}"
perl -pi -e 's/^version = "[0-9]+\.[0-9]+\.[0-9]+"/version = "'"$version"'"/' Cargo.toml
perl -0pi -e 's/name = "commitbot"\nversion = "[0-9]+\.[0-9]+\.[0-9]+"/name = "commitbot"\nversion = "'"$version"'"/m' Cargo.lock
if git diff --quiet -- Cargo.toml Cargo.lock; then
echo "Release version ${version} is already present in Cargo metadata." >&2
exit 1
fi
git add Cargo.toml Cargo.lock
git commit -m "Release ${version}"
git tag "${version}"
echo "release_sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Push release commit and tag
shell: bash
run: |
set -euo pipefail
git push origin "HEAD:${{ needs.plan.outputs.target_branch }}"
git push origin "refs/tags/${{ needs.plan.outputs.version }}"
create_release:
needs: [plan, prepare_release]
runs-on: ubuntu-latest
steps:
- name: Check out release commit
uses: actions/checkout@v4
with:
ref: ${{ needs.prepare_release.outputs.release_sha }}
- name: Generate release notes
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
NOTES_ARGS=()
if [[ -n "${{ needs.plan.outputs.previous_version }}" ]]; then
NOTES_ARGS+=(-f previous_tag_name="${{ needs.plan.outputs.previous_version }}")
fi
gh api \
-H "Accept: application/vnd.github+json" \
"/repos/${{ github.repository }}/releases/generate-notes" \
-f tag_name="${{ needs.plan.outputs.version }}" \
-f target_commitish="${{ needs.prepare_release.outputs.release_sha }}" \
"${NOTES_ARGS[@]}" \
--jq .body > generated-release-notes.md
bash devops/render-release-notes.sh \
"${{ needs.plan.outputs.version }}" \
"${{ github.repository }}" \
generated-release-notes.md > release-notes.md
- name: Create GitHub release
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
gh release create "${{ needs.plan.outputs.version }}" \
--draft \
--verify-tag \
--target "${{ needs.prepare_release.outputs.release_sha }}" \
--title "${{ needs.plan.outputs.version }}" \
--notes-file release-notes.md
- name: Dispatch release-assets workflow
id: dispatch_assets
env:
GH_TOKEN: ${{ github.token }}
shell: bash
run: |
set -euo pipefail
dispatch_started_at="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
source_run_url="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
gh workflow run release-assets.yml \
--ref "${{ needs.plan.outputs.target_branch }}" \
-f tag="${{ needs.plan.outputs.version }}" \
-f source_run_id="${{ github.run_id }}" \
-f source_run_url="${source_run_url}"
assets_run_url=""
for _ in {1..12}; do
sleep 5
assets_run_url="$(
gh api "/repos/${{ github.repository }}/actions/workflows/release-assets.yml/runs?event=workflow_dispatch&branch=${{ needs.plan.outputs.target_branch }}&per_page=20" \
--jq '.workflow_runs
| map(select(.head_sha == "${{ needs.prepare_release.outputs.release_sha }}" and .status != null))
| sort_by(.created_at)
| reverse
| .[0].html_url // ""'
)"
if [[ -n "${assets_run_url}" ]]; then
break
fi
done
echo "dispatch_started_at=${dispatch_started_at}" >> "$GITHUB_OUTPUT"
echo "assets_run_url=${assets_run_url}" >> "$GITHUB_OUTPUT"
- name: Add release summary
shell: bash
run: |
release_url="https://github.com/${{ github.repository }}/releases/tag/${{ needs.plan.outputs.version }}"
assets_url="${{ steps.dispatch_assets.outputs.assets_run_url }}"
{
echo "## Release"
echo
echo "- Version: \`${{ needs.plan.outputs.version }}\`"
echo "- Release: [${{ needs.plan.outputs.version }}](${release_url})"
if [[ -n "${assets_url}" ]]; then
echo "- Release assets workflow: [Open run](${assets_url})"
else
echo "- Release assets workflow: dispatched, but the run URL was not discovered yet."
echo "- Release assets workflow page: [Open workflow](https://github.com/${{ github.repository }}/actions/workflows/release-assets.yml)"
fi
} >> "$GITHUB_STEP_SUMMARY"