diff --git a/.github/workflows/changelog-build.yml b/.github/workflows/changelog-build.yml new file mode 100644 index 00000000..a822cf6f --- /dev/null +++ b/.github/workflows/changelog-build.yml @@ -0,0 +1,118 @@ +name: 'Changelog Build (Release)' + +on: + workflow_dispatch: + inputs: + last-release-tag: + description: Last Git tag to start from (exclusive) (e.g. `v2.0.0`) + type: string + required: true + release-branch: + description: Release branch to build changelog on (e.g. `r2.1.0`) + type: string + required: true + changelog-main-content: + description: Custom changelog content to include before detailed changelogs + type: string + required: false + default: '' + +jobs: + changelog: + runs-on: ubuntu-latest + steps: + - name: Checkout branch + uses: actions/checkout@v4 + with: + ref: main + fetch-depth: 0 + + - name: Build Changelog + id: github_tag + uses: mikepenz/release-changelog-builder-action@v3.3.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + owner: ${{ github.repository_owner }} + repo: ${{ github.event.repository.name }} + ignorePreReleases: "false" + failOnError: "false" + fromTag: ${{ inputs.last-release-tag }} + toTag: ${{ inputs.release-branch }} + + - name: Update changelog file + env: + RELEASE_BRANCH: ${{ inputs.release-branch }} + CHANGELOG: ${{ steps.github_tag.outputs.changelog }} + MAIN_CONTENT: ${{ inputs.changelog-main-content }} + shell: bash -x -e -u -o pipefail {0} + run: | + RELEASE_VERSION=${RELEASE_BRANCH#r} + CHANGELOG=$(echo "$CHANGELOG" | sed '/^[[:blank:]]*#/s/#/###/') + + # Build release notes starting with version header + RELEASE_NOTES="## NVIDIA DFM $RELEASE_VERSION" + + # Add custom content if provided + if [ -n "$MAIN_CONTENT" ]; then + RELEASE_NOTES="$RELEASE_NOTES + + $MAIN_CONTENT" + fi + + # Add detailed changelogs section + RELEASE_NOTES="$RELEASE_NOTES + + ### Detailed Changelogs: + + $CHANGELOG" + + printf "%s\n" "$RELEASE_NOTES" | sed '//r /dev/stdin' CHANGELOG.md > CHANGELOG.tmp.md + + mv CHANGELOG.tmp.md CHANGELOG.md + + - name: Inspect new changelog file + run: cat CHANGELOG.md + + - name: Create or update label + uses: actions/github-script@v6 + with: + script: | + const labelName = '${{ inputs.release-branch }}'; + const labelColor = '0366d6'; // Blue color + const labelDescription = `Release ${labelName}`; + + try { + // Try to get the label + await github.rest.issues.getLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: labelName + }); + console.log(`Label '${labelName}' already exists`); + } catch (error) { + if (error.status === 404) { + // Label doesn't exist, create it + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: labelName, + color: labelColor, + description: labelDescription + }); + console.log(`Created label '${labelName}'`); + } else { + throw error; + } + } + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v7 + with: + commit-message: "beep boop: Update changelog" + title: "Update changelog for `${{ inputs.release-branch }}`" + signoff: true + sign-commits: true + base: main + branch: bot/chore/update-changelog-into-${{ inputs.release-branch }} + labels: ${{ inputs.release-branch }}