|
| 1 | +name: 'Changelog Build (Release)' |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + last-release-tag: |
| 7 | + description: Last Git tag to start from (exclusive) (e.g. `v2.0.0`) |
| 8 | + type: string |
| 9 | + required: true |
| 10 | + release-branch: |
| 11 | + description: Release branch to build changelog on (e.g. `r2.1.0`) |
| 12 | + type: string |
| 13 | + required: true |
| 14 | + changelog-main-content: |
| 15 | + description: Custom changelog content to include before detailed changelogs |
| 16 | + type: string |
| 17 | + required: false |
| 18 | + default: '' |
| 19 | + |
| 20 | +jobs: |
| 21 | + changelog: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Checkout branch |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + ref: main |
| 28 | + fetch-depth: 0 |
| 29 | + |
| 30 | + - name: Build Changelog |
| 31 | + id: github_tag |
| 32 | + uses: mikepenz/release-changelog-builder-action@v3.3.1 |
| 33 | + env: |
| 34 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 35 | + with: |
| 36 | + owner: ${{ github.repository_owner }} |
| 37 | + repo: ${{ github.event.repository.name }} |
| 38 | + ignorePreReleases: "false" |
| 39 | + failOnError: "false" |
| 40 | + fromTag: ${{ inputs.last-release-tag }} |
| 41 | + toTag: ${{ inputs.release-branch }} |
| 42 | + |
| 43 | + - name: Update changelog file |
| 44 | + env: |
| 45 | + RELEASE_BRANCH: ${{ inputs.release-branch }} |
| 46 | + CHANGELOG: ${{ steps.github_tag.outputs.changelog }} |
| 47 | + MAIN_CONTENT: ${{ inputs.changelog-main-content }} |
| 48 | + shell: bash -x -e -u -o pipefail {0} |
| 49 | + run: | |
| 50 | + RELEASE_VERSION=${RELEASE_BRANCH#r} |
| 51 | + CHANGELOG=$(echo "$CHANGELOG" | sed '/^[[:blank:]]*#/s/#/###/') |
| 52 | +
|
| 53 | + # Build release notes starting with version header |
| 54 | + RELEASE_NOTES="## NVIDIA DFM $RELEASE_VERSION" |
| 55 | +
|
| 56 | + # Add custom content if provided |
| 57 | + if [ -n "$MAIN_CONTENT" ]; then |
| 58 | + RELEASE_NOTES="$RELEASE_NOTES |
| 59 | +
|
| 60 | + $MAIN_CONTENT" |
| 61 | + fi |
| 62 | +
|
| 63 | + # Add detailed changelogs section |
| 64 | + RELEASE_NOTES="$RELEASE_NOTES |
| 65 | +
|
| 66 | + ### Detailed Changelogs: |
| 67 | +
|
| 68 | + $CHANGELOG" |
| 69 | +
|
| 70 | + printf "%s\n" "$RELEASE_NOTES" | sed '/<!-- Next changelog -->/r /dev/stdin' CHANGELOG.md > CHANGELOG.tmp.md |
| 71 | +
|
| 72 | + mv CHANGELOG.tmp.md CHANGELOG.md |
| 73 | +
|
| 74 | + - name: Inspect new changelog file |
| 75 | + run: cat CHANGELOG.md |
| 76 | + |
| 77 | + - name: Create or update label |
| 78 | + uses: actions/github-script@v6 |
| 79 | + with: |
| 80 | + script: | |
| 81 | + const labelName = '${{ inputs.release-branch }}'; |
| 82 | + const labelColor = '0366d6'; // Blue color |
| 83 | + const labelDescription = `Release ${labelName}`; |
| 84 | +
|
| 85 | + try { |
| 86 | + // Try to get the label |
| 87 | + await github.rest.issues.getLabel({ |
| 88 | + owner: context.repo.owner, |
| 89 | + repo: context.repo.repo, |
| 90 | + name: labelName |
| 91 | + }); |
| 92 | + console.log(`Label '${labelName}' already exists`); |
| 93 | + } catch (error) { |
| 94 | + if (error.status === 404) { |
| 95 | + // Label doesn't exist, create it |
| 96 | + await github.rest.issues.createLabel({ |
| 97 | + owner: context.repo.owner, |
| 98 | + repo: context.repo.repo, |
| 99 | + name: labelName, |
| 100 | + color: labelColor, |
| 101 | + description: labelDescription |
| 102 | + }); |
| 103 | + console.log(`Created label '${labelName}'`); |
| 104 | + } else { |
| 105 | + throw error; |
| 106 | + } |
| 107 | + } |
| 108 | +
|
| 109 | + - name: Create Pull Request |
| 110 | + uses: peter-evans/create-pull-request@v7 |
| 111 | + with: |
| 112 | + commit-message: "beep boop: Update changelog" |
| 113 | + title: "Update changelog for `${{ inputs.release-branch }}`" |
| 114 | + signoff: true |
| 115 | + sign-commits: true |
| 116 | + base: main |
| 117 | + branch: bot/chore/update-changelog-into-${{ inputs.release-branch }} |
| 118 | + labels: ${{ inputs.release-branch }} |
0 commit comments