Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Release Drafter for Dev Branches #387

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 113 additions & 11 deletions .github/workflows/ReleaseDrafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#
# 1. A "latest release branch"
# - Example: `release/202405`
# - Config file: `release-draft-config-n.yml`
# - 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`
# - 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`
Expand Down Expand Up @@ -68,31 +68,133 @@ jobs:
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 = ").*(?=")')
echo "latest_mu_branch=${latestMuReleaseBranch}" >> $GITHUB_ENV
echo "latest_mu_branch_full=refs/heads/${latestMuReleaseBranch}" >> $GITHUB_ENV
echo "previous_mu_branch=${previousMuReleaseBranch}" >> $GITHUB_ENV
echo "previous_mu_branch_full=refs/heads/${previousMuReleaseBranch}" >> $GITHUB_ENV
- name: Build a ${{ env.latest_mu_branch }} Draft
if: ${{ startsWith(github.ref, env.latest_mu_branch_full) }}
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=${latestMuDevBranch}" >> $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: Build a ${{ env.previous_mu_branch }} Draft
if: ${{ startsWith(github.ref, env.previous_mu_branch_full) }}
- 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

# 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

# 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') }}
if: ${{ !startsWith(github.ref, 'refs/heads/release') && !startsWith(github.ref, 'refs/heads/dev') }}
id: update_draft_non_release
uses: release-drafter/[email protected]
with:
Expand Down
14 changes: 14 additions & 0 deletions .sync/Files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,25 @@ group:
- source: .sync/workflows/config/release-draft/release-draft-config.yml
dest: .github/release-draft-config-n.yml
template:
filter_to_backport: true
latest: true
release_branch: true
- source: .sync/workflows/config/release-draft/release-draft-config.yml
dest: .github/release-draft-config-n-dev.yml
template:
filter_to_backport: false
latest: true
release_branch: true
- source: .sync/workflows/config/release-draft/release-draft-config.yml
dest: .github/release-draft-config-n-1.yml
template:
filter_to_backport: true
latest: false
release_branch: true
- source: .sync/workflows/config/release-draft/release-draft-config.yml
dest: .github/release-draft-config-n-1-dev.yml
template:
filter_to_backport: false
latest: false
release_branch: true
repos: |
Expand Down
14 changes: 12 additions & 2 deletions .sync/workflows/config/release-draft/release-draft-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,25 @@

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

{%- if release_branch %}
name-template: 'dev-v$RESOLVED_VERSION'
tag-template: 'dev-v$RESOLVED_VERSION'
{% else %}
name-template: 'v$RESOLVED_VERSION'
tag-template: 'v$RESOLVED_VERSION'
{% endif %}

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

template: |
Expand Down
3 changes: 2 additions & 1 deletion .sync/workflows/leaf/release-draft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ name: Update Release Draft
on:
push:
branches:
- {{ trigger_branch_name if trigger_branch_name else sync_version.latest_mu_release_branch }}
- {{ trigger_branch_name if trigger_branch_name else sync_version.latest_mu_release_branch | replace ("release", "dev") }}

jobs:
draft:
name: Draft Releases

permissions:
contents: write
Expand Down