|
11 | 11 | #
|
12 | 12 | # 1. A "latest release branch"
|
13 | 13 | # - 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` |
15 | 15 | # 2. A "previous release branch"
|
16 | 16 | # - 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` |
18 | 18 | # 3. A "main branch"
|
19 | 19 | # - Example: `main`
|
20 | 20 | # - Config file: `release-draft-config.yml`
|
@@ -68,33 +68,137 @@ jobs:
|
68 | 68 | run: |
|
69 | 69 | fileContent=$(cat "${FILE_PATH}")
|
70 | 70 | latestMuReleaseBranch=$(echo "$fileContent" | grep -oP '(?<=latest_mu_release_branch = ").*(?=")')
|
| 71 | + latestMuDevBranch=$(echo "$latestMuReleaseBranch" | sed 's/release/dev/') |
71 | 72 | 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) }} |
78 | 84 | id: update_draft_n
|
79 |
| - uses: release-drafter/release-drafter@v6.0.0 |
| 85 | + uses: release-drafter/release-drafter@v6.1.0 |
80 | 86 | with:
|
81 | 87 | # Note: Path is relative to .github/
|
82 | 88 | config-name: release-draft-config-n.yml
|
83 | 89 | env:
|
84 | 90 | 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) }} |
87 | 134 | id: update_draft_n_1
|
88 |
| - uses: release-drafter/release-drafter@v6.0.0 |
| 135 | + uses: release-drafter/release-drafter@v6.1.0 |
89 | 136 | with:
|
90 | 137 | # Note: Path is relative to .github/
|
91 | 138 | config-name: release-draft-config-n-1.yml
|
92 | 139 | env:
|
93 | 140 | 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/[email protected] |
| 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/[email protected] |
| 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 }} |
94 | 198 | - 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') }} |
96 | 200 | id: update_draft_non_release
|
97 |
| - uses: release-drafter/release-drafter@v6.0.0 |
| 201 | + uses: release-drafter/release-drafter@v6.1.0 |
98 | 202 | with:
|
99 | 203 | # Note: Path is relative to .github/
|
100 | 204 | config-name: release-draft-config.yml
|
|
0 commit comments