-
Notifications
You must be signed in to change notification settings - Fork 24
206 lines (191 loc) · 9.45 KB
/
ReleaseDrafter.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
# This workflow automatically drafts new project releases so it is obvious
# what a current release will look like at any time.
#
# It takes advantage of the labels used in Project Mu to automatically categorize
# the types of changes in a given release. In addition, the semantic version of
# the code is constantly maintained based on Project Mu label conventions to ensure
# semantic versioning is followed and a release version is always ready.
#
# The workflow is set up to support three types of repos as used in Project Mu. The
# config file name varies depending on the branch being built.
#
# 1. A "latest release branch"
# - Example: `release/202405`
# - Config file: `release-draft-config-n.yml` and `release-draft-config-n-dev.yml`
# 2. A "previous release branch"
# - Example: `release/202311`
# - Config file: `release-draft-config-n-1.yml` and `release-draft-config-n-1-dev.yml`
# 3. A "main branch"
# - Example: `main`
# - Config file: `release-draft-config.yml`
#
# Note:
# - The versions for the above types of repos are automatically read from .sync/Version.njk.
# - The correct config files are automatically synced to the corresponding branches by the
# Mu DevOps file sync operation. No manual maintenance is needed.
#
# Project Mu repos are encouraged to use this reusable workflow if this release
# workflow makes sense in their repo.
#
# The release draft configuration is defined in:
# - .github/release-draft-config.yml
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
# For more information, see:
# https://github.com/release-drafter/release-drafter
name: Mu DevOps Release Draft Workflow
on:
workflow_call:
jobs:
update_release_draft:
name: Update Release Draft
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Download Version Information
id: download_ver_info
shell: bash
run: |
mkdir $HOME/temp
versionFileUrl="https://raw.githubusercontent.com/microsoft/mu_devops/main/.sync/Version.njk"
localFilePath=$HOME/temp/Version.njk
curl $versionFileUrl --output "${localFilePath}"
echo "file_path=${localFilePath}" >> $GITHUB_ENV
- name: Extract Version Information
id: extract_ver_info
shell: bash
env:
FILE_PATH: ${{ env.file_path }}
run: |
fileContent=$(cat "${FILE_PATH}")
latestMuReleaseBranch=$(echo "$fileContent" | grep -oP '(?<=latest_mu_release_branch = ").*(?=")')
latestMuDevBranch=$(echo "$latestMuReleaseBranch" | sed 's/release/dev/')
previousMuReleaseBranch=$(echo "$fileContent" | grep -oP '(?<=previous_mu_release_branch = ").*(?=")')
previousMuDevBranch=$(echo "$previousMuReleaseBranch" | sed 's/release/dev/')
echo "latest_mu_release_branch=${latestMuReleaseBranch}" >> $GITHUB_ENV
echo "latest_mu_dev_branch=${latestMuDevBranch}" >> $GITHUB_ENV
echo "latest_mu_dev_branch_full=refs/heads/${latestMuDevBranch}" >> $GITHUB_ENV
echo "latest_mu_release_branch_full=refs/heads/${latestMuReleaseBranch}" >> $GITHUB_ENV
echo "previous_mu_release_branch=${previousMuReleaseBranch}" >> $GITHUB_ENV
echo "previous_mu_dev_branch=${previousMuDevBranch}" >> $GITHUB_ENV
echo "previous_mu_dev_branch_full=refs/heads/${previousMuDevBranch}" >> $GITHUB_ENV
echo "previous_mu_release_branch_full=refs/heads/${previousMuReleaseBranch}" >> $GITHUB_ENV
- name: Build a ${{ env.latest_mu_release_branch }} Draft
if: ${{ startsWith(github.ref, env.latest_mu_dev_branch_full) }}
id: update_draft_n
uses: release-drafter/[email protected]
with:
# Note: Path is relative to .github/
config-name: release-draft-config-n.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Draft Release for Current (${{ env.latest_mu_release_branch }}) Release Branch
if: steps.update_draft_n.outcome == 'success'
run: |
# Prepare the release body
release_body_path="${{ runner.temp }}/release_body.txt"
release_body=$(cat <<'EOF'
${{ steps.update_draft_n.outputs.body }}
EOF
)
release_body="${release_body//\`/\\\`}"
echo "${release_body}" > $release_body_path
sed -i 's/\\`/`/g' $release_body_path
sed -i '/\**Full Changelog\**:/d' $release_body_path
# Get the new tag and title
new_tag=$(echo "${{ steps.update_draft_n.outputs.tag_name }}" | sed 's/dev-//')
new_title=$(echo "${{ steps.update_draft_n.outputs.tag_name }}" | sed 's/dev/release/')
# Determine the corresponding tag names
existing_tag_prefix=""
tag_regex="v([0-9]{6}).*\."
if [[ $new_tag =~ $tag_regex ]]; then
existing_tag_prefix="${BASH_REMATCH[1]}"
fi
# Delete the template dev draft created
gh release delete "${{ steps.update_draft_n.outputs.tag_name }}" --repo ${{ github.repository }} --yes
# Delete any existing draft releases for this release branch
for tag in $(gh release list --repo ${{ github.repository }} --json tagName,isPrerelease,isDraft --jq ".[] | select(.isDraft == true and .isPrerelease == false and (.tagName | startswith(\"v$existing_tag_prefix\"))) | .tagName"); do
gh release delete "$tag" --repo ${{ github.repository }} --yes
done
gh release create "$new_tag" \
--repo "${{ github.repository }}" \
--target "${{ env.latest_mu_release_branch_full }}" \
--title "$new_title" \
--notes-file "$release_body_path" \
--draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build a ${{ env.previous_mu_release_branch }} Draft
if: ${{ startsWith(github.ref, env.previous_mu_dev_branch_full) }}
id: update_draft_n_1
uses: release-drafter/[email protected]
with:
# Note: Path is relative to .github/
config-name: release-draft-config-n-1.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Draft Release for N-1 (${{ env.previous_mu_release_branch }}) Release Branch
if: steps.update_draft_n_1.outcome == 'success'
run: |
# Prepare the release body
release_body_path="${{ runner.temp }}/release_body.txt"
release_body=$(cat <<'EOF'
${{ steps.update_draft_n_1.outputs.body }}
EOF
)
release_body="${release_body//\`/\\\`}"
echo "${release_body}" > $release_body_path
sed -i 's/\\`/`/g' $release_body_path
sed -i '/\**Full Changelog\**:/d' $release_body_path
# Get the new tag and title
new_tag=$(echo "${{ steps.update_draft_n_1.outputs.tag_name }}" | sed 's/dev-//')
new_title=$(echo "${{ steps.update_draft_n_1.outputs.tag_name }}" | sed 's/dev/release/')
# Determine the corresponding tag names
existing_tag_prefix=""
tag_regex="v([0-9]{6}).*\."
if [[ $new_tag =~ $tag_regex ]]; then
existing_tag_prefix="${BASH_REMATCH[1]}"
fi
# Delete the template dev draft created
gh release delete "${{ steps.update_draft_n_1.outputs.tag_name }}" --repo ${{ github.repository }} --yes
# Delete any existing draft releases for this release branch
for tag in $(gh release list --repo ${{ github.repository }} --json tagName,isPrerelease,isDraft --jq ".[] | select(.isDraft == true and .isPrerelease == false and (.tagName | startswith(\"v$existing_tag_prefix\"))) | .tagName"); do
gh release delete "$tag" --repo ${{ github.repository }} --yes
done
gh release create "$new_tag" \
--repo "${{ github.repository }}" \
--target "${{ env.previous_mu_release_branch_full }}" \
--title "$new_title" \
--notes-file "$release_body_path" \
--draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create the ${{ env.latest_mu_dev_branch }} Draft
if: ${{ startsWith(github.ref, env.latest_mu_dev_branch_full) }}
uses: release-drafter/[email protected]
with:
# Note: Path is relative to .github/
config-name: release-draft-config-n-dev.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create the ${{ env.previous_mu_dev_branch }} Draft
if: ${{ startsWith(github.ref, env.previous_mu_dev_branch_full) }}
uses: release-drafter/[email protected]
with:
# Note: Path is relative to .github/
config-name: release-draft-config-n-1-dev.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build the New Release Draft
if: ${{ !startsWith(github.ref, 'refs/heads/release') && !startsWith(github.ref, 'refs/heads/dev') }}
id: update_draft_non_release
uses: release-drafter/[email protected]
with:
# Note: Path is relative to .github/
config-name: release-draft-config.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}