Skip to content

Commit 1915931

Browse files
authored
Update Release Drafter for Dev Branches (#387)
Changes the way release drafter handles drafting releases on repos with release branches (which have dev branches now). Ultimately, a release is drafted for the dev branch and the release branch. The releases are differentiated by both their release title and tag. - Release Branch - Title: `release-v<version>` - Tag: `v<version>` - Dev Branch - Title: `dev-v<version>` - Tag: `dev-v<version>` Note that the tag for the release branch follows the same convention as existing release tags. The "release branch" release includes all pull requests made to the dev branch with the `type:backport` label since the last "dev branch" release. For this reason, the "dev branch" and "release branch" should be released at the same time. Then, this effectively results in the "release branch" having all relevant changes since the last release. The "dev branch" release will be based at the same point in history as the "release branch" release but include all changes not just those with the `type:backport` label. The "release branch" release for the current release branch should be marked as "latest". For example, if "release/202311" and "release/202405" exist, the "release/202405" "release branch" release would be marked as latest. The `release-drafter/release-drafter` action is still used. Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
1 parent e6710ae commit 1915931

4 files changed

Lines changed: 157 additions & 15 deletions

File tree

.github/workflows/ReleaseDrafter.yml

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
#
1212
# 1. A "latest release branch"
1313
# - Example: `release/202405`
14-
# - Config file: `release-draft-config-n.yml`
14+
# - Config file: `release-draft-config-n.yml` and `release-draft-config-n-dev.yml`
1515
# 2. A "previous release branch"
1616
# - Example: `release/202311`
17-
# - Config file: `release-draft-config-n-1.yml`
17+
# - Config file: `release-draft-config-n-1.yml` and `release-draft-config-n-1-dev.yml`
1818
# 3. A "main branch"
1919
# - Example: `main`
2020
# - Config file: `release-draft-config.yml`
@@ -68,31 +68,135 @@ jobs:
6868
run: |
6969
fileContent=$(cat "${FILE_PATH}")
7070
latestMuReleaseBranch=$(echo "$fileContent" | grep -oP '(?<=latest_mu_release_branch = ").*(?=")')
71+
latestMuDevBranch=$(echo "$latestMuReleaseBranch" | sed 's/release/dev/')
7172
previousMuReleaseBranch=$(echo "$fileContent" | grep -oP '(?<=previous_mu_release_branch = ").*(?=")')
72-
echo "latest_mu_branch=${latestMuReleaseBranch}" >> $GITHUB_ENV
73-
echo "latest_mu_branch_full=refs/heads/${latestMuReleaseBranch}" >> $GITHUB_ENV
74-
echo "previous_mu_branch=${previousMuReleaseBranch}" >> $GITHUB_ENV
75-
echo "previous_mu_branch_full=refs/heads/${previousMuReleaseBranch}" >> $GITHUB_ENV
76-
- name: Build a ${{ env.latest_mu_branch }} Draft
77-
if: ${{ startsWith(github.ref, env.latest_mu_branch_full) }}
73+
previousMuDevBranch=$(echo "$previousMuReleaseBranch" | sed 's/release/dev/')
74+
echo "latest_mu_release_branch=${latestMuReleaseBranch}" >> $GITHUB_ENV
75+
echo "latest_mu_dev_branch=${latestMuDevBranch}" >> $GITHUB_ENV
76+
echo "latest_mu_dev_branch_full=refs/heads/${latestMuDevBranch}" >> $GITHUB_ENV
77+
echo "latest_mu_release_branch_full=refs/heads/${latestMuReleaseBranch}" >> $GITHUB_ENV
78+
echo "previous_mu_release_branch=${previousMuReleaseBranch}" >> $GITHUB_ENV
79+
echo "previous_mu_dev_branch=${previousMuDevBranch}" >> $GITHUB_ENV
80+
echo "previous_mu_dev_branch_full=refs/heads/${previousMuDevBranch}" >> $GITHUB_ENV
81+
echo "previous_mu_release_branch_full=refs/heads/${previousMuReleaseBranch}" >> $GITHUB_ENV
82+
- name: Build a ${{ env.latest_mu_release_branch }} Draft
83+
if: ${{ startsWith(github.ref, env.latest_mu_dev_branch_full) }}
7884
id: update_draft_n
7985
uses: release-drafter/release-drafter@v6.0.0
8086
with:
8187
# Note: Path is relative to .github/
8288
config-name: release-draft-config-n.yml
8389
env:
8490
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85-
- name: Build a ${{ env.previous_mu_branch }} Draft
86-
if: ${{ startsWith(github.ref, env.previous_mu_branch_full) }}
91+
- name: Draft Release for Current (${{ env.latest_mu_release_branch }}) Release Branch
92+
if: steps.update_draft_n.outcome == 'success'
93+
run: |
94+
# Prepare the release body
95+
release_body_path="${{ runner.temp }}/release_body.txt"
96+
release_body=$(cat <<'EOF'
97+
${{ steps.update_draft_n.outputs.body }}
98+
EOF
99+
)
100+
release_body="${release_body//\`/\\\`}"
101+
echo "${release_body}" > $release_body_path
102+
sed -i 's/\\`/`/g' $release_body_path
103+
sed -i '/\**Full Changelog\**:/d' $release_body_path
104+
105+
# Get the new tag and title
106+
new_tag=$(echo "${{ steps.update_draft_n.outputs.tag_name }}" | sed 's/dev-//')
107+
new_title=$(echo "${{ steps.update_draft_n.outputs.tag_name }}" | sed 's/dev/release/')
108+
109+
# Determine the corresponding tag names
110+
existing_tag_prefix=""
111+
tag_regex="v([0-9]{6}).*\."
112+
if [[ $new_tag =~ $tag_regex ]]; then
113+
existing_tag_prefix="${BASH_REMATCH[1]}"
114+
fi
115+
116+
# Delete the template dev draft created
117+
gh release delete "${{ steps.update_draft_n.outputs.tag_name }}" --repo ${{ github.repository }} --yes
118+
119+
# Delete any existing draft releases for this release branch
120+
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
121+
gh release delete "$tag" --repo ${{ github.repository }} --yes
122+
done
123+
124+
gh release create "$new_tag" \
125+
--repo "${{ github.repository }}" \
126+
--target "${{ env.latest_mu_release_branch_full }}" \
127+
--title "$new_title" \
128+
--notes-file "$release_body_path" \
129+
--draft
130+
env:
131+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
- name: Build a ${{ env.previous_mu_release_branch }} Draft
133+
if: ${{ startsWith(github.ref, env.previous_mu_dev_branch_full) }}
87134
id: update_draft_n_1
88135
uses: release-drafter/release-drafter@v6.0.0
89136
with:
90137
# Note: Path is relative to .github/
91138
config-name: release-draft-config-n-1.yml
92139
env:
93140
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
141+
- name: Draft Release for N-1 (${{ env.previous_mu_release_branch }}) Release Branch
142+
if: steps.update_draft_n_1.outcome == 'success'
143+
run: |
144+
# Prepare the release body
145+
release_body_path="${{ runner.temp }}/release_body.txt"
146+
release_body=$(cat <<'EOF'
147+
${{ steps.update_draft_n_1.outputs.body }}
148+
EOF
149+
)
150+
release_body="${release_body//\`/\\\`}"
151+
echo "${release_body}" > $release_body_path
152+
sed -i 's/\\`/`/g' $release_body_path
153+
sed -i '/\**Full Changelog\**:/d' $release_body_path
154+
155+
# Get the new tag and title
156+
new_tag=$(echo "${{ steps.update_draft_n_1.outputs.tag_name }}" | sed 's/dev-//')
157+
new_title=$(echo "${{ steps.update_draft_n_1.outputs.tag_name }}" | sed 's/dev/release/')
158+
159+
# Determine the corresponding tag names
160+
existing_tag_prefix=""
161+
tag_regex="v([0-9]{6}).*\."
162+
if [[ $new_tag =~ $tag_regex ]]; then
163+
existing_tag_prefix="${BASH_REMATCH[1]}"
164+
fi
165+
166+
# Delete the template dev draft created
167+
gh release delete "${{ steps.update_draft_n_1.outputs.tag_name }}" --repo ${{ github.repository }} --yes
168+
169+
# Delete any existing draft releases for this release branch
170+
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
171+
gh release delete "$tag" --repo ${{ github.repository }} --yes
172+
done
173+
174+
gh release create "$new_tag" \
175+
--repo "${{ github.repository }}" \
176+
--target "${{ env.previous_mu_release_branch_full }}" \
177+
--title "$new_title" \
178+
--notes-file "$release_body_path" \
179+
--draft
180+
env:
181+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
182+
- name: Create the ${{ env.latest_mu_dev_branch }} Draft
183+
if: ${{ startsWith(github.ref, env.latest_mu_dev_branch_full) }}
184+
uses: release-drafter/release-drafter@v6.0.0
185+
with:
186+
# Note: Path is relative to .github/
187+
config-name: release-draft-config-n-dev.yml
188+
env:
189+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
190+
- name: Create the ${{ env.previous_mu_dev_branch }} Draft
191+
if: ${{ startsWith(github.ref, env.previous_mu_dev_branch_full) }}
192+
uses: release-drafter/release-drafter@v6.0.0
193+
with:
194+
# Note: Path is relative to .github/
195+
config-name: release-draft-config-n-1-dev.yml
196+
env:
197+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94198
- name: Build the New Release Draft
95-
if: ${{ !startsWith(github.ref, 'refs/heads/release') }}
199+
if: ${{ !startsWith(github.ref, 'refs/heads/release') && !startsWith(github.ref, 'refs/heads/dev') }}
96200
id: update_draft_non_release
97201
uses: release-drafter/release-drafter@v6.0.0
98202
with:

.sync/Files.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,30 @@ group:
614614
- files:
615615
- source: .sync/workflows/leaf/release-draft.yml
616616
dest: .github/workflows/release-draft.yml
617-
template: true
617+
template:
618+
depend_on_backport: true
618619
- source: .sync/workflows/config/release-draft/release-draft-config.yml
619620
dest: .github/release-draft-config-n.yml
620621
template:
622+
filter_to_backport: true
623+
latest: true
624+
release_branch: true
625+
- source: .sync/workflows/config/release-draft/release-draft-config.yml
626+
dest: .github/release-draft-config-n-dev.yml
627+
template:
628+
filter_to_backport: false
621629
latest: true
622630
release_branch: true
623631
- source: .sync/workflows/config/release-draft/release-draft-config.yml
624632
dest: .github/release-draft-config-n-1.yml
625633
template:
634+
filter_to_backport: true
635+
latest: false
636+
release_branch: true
637+
- source: .sync/workflows/config/release-draft/release-draft-config.yml
638+
dest: .github/release-draft-config-n-1-dev.yml
639+
template:
640+
filter_to_backport: false
626641
latest: false
627642
release_branch: true
628643
repos: |

.sync/workflows/config/release-draft/release-draft-config.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,37 @@
1919

2020
{% import '../../../Version.njk' as sync_version -%}
2121

22+
{%- if release_branch %}
23+
name-template: 'dev-v$RESOLVED_VERSION'
24+
tag-template: 'dev-v$RESOLVED_VERSION'
25+
{% else %}
2226
name-template: 'v$RESOLVED_VERSION'
2327
tag-template: 'v$RESOLVED_VERSION'
28+
{% endif %}
2429

2530
{# `release_branch` applies a commitish. `latest` then determines the branch to use. -#}
2631
{# If a commitish is not specified, then the `github.ref` value is implicitly used. -#}
2732
{%- if release_branch %}
28-
{% set release_branch = "refs/heads/" + (sync_version.latest_mu_release_branch if latest else sync_version.previous_mu_release_branch) %}
29-
commitish: {{ release_branch }}
33+
{%- set latest_mu_dev_branch = "refs/heads/" + (sync_version.latest_mu_release_branch | replace("release", "dev")) %}
34+
{%- set previous_mu_dev_branch = "refs/heads/" + (sync_version.previous_mu_release_branch | replace("release", "dev")) %}
35+
{%- set actual_branch = latest_mu_dev_branch if latest else previous_mu_dev_branch %}
36+
commitish: {{ actual_branch }}
3037
filter-by-commitish: true
38+
{% if filter_to_backport %}
39+
include-labels: ["type:backport"]
40+
{% endif %}
3141
{% endif %}
3242

3343
template: |
3444
# What's Changed
3545
3646
$CHANGES
3747
48+
{% if release_branch %}
49+
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...dev-v$RESOLVED_VERSION
50+
{% else %}
3851
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION
52+
{% endif %}
3953

4054
categories:
4155
- title: '⚠️ Breaking Changes'

.sync/workflows/leaf/release-draft.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@
2323
name: Update Release Draft
2424

2525
on:
26+
{% if depend_on_backport %}
27+
workflow_run:
28+
workflows: ["Backport Commits to Release Branch"]
29+
branches: [{{ trigger_branch_name if trigger_branch_name else sync_version.latest_mu_release_branch | replace ("release", "dev") }}]
30+
types:
31+
- completed
32+
{% else %}
2633
push:
2734
branches:
28-
- {{ trigger_branch_name if trigger_branch_name else sync_version.latest_mu_release_branch }}
35+
- {{ trigger_branch_name if trigger_branch_name else sync_version.latest_mu_release_branch | replace ("release", "dev") }}
36+
{% endif %}
2937

3038
jobs:
3139
draft:
40+
name: Draft Releases
3241

3342
permissions:
3443
contents: write

0 commit comments

Comments
 (0)