# Requires repo secret: PERSONAL_ACCESS_TOKEN with permissions: # Contents: read and write # Pull Requests: read name: GitHub Release Drafter on: push: branches: - 'main' workflow_dispatch: inputs: ref: description: 'Git ref (refs/heads/, refs/tags/, etc.) or SHA' required: true type: string concurrency: group: ${{ github.workflow }}-${{ inputs.ref || github.ref }} cancel-in-progress: true env: ref: ${{ inputs.ref || github.sha || github.ref }} jobs: release: permissions: # actions/checkout@v4 contents: read # thollander/actions-comment-pull-request pull-requests: write runs-on: ubuntu-latest steps: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 with: ref: ${{ env.ref }} submodules: 'recursive' # auto-changelog needs a full fetch for tag info fetch-depth: 0 # Check to see if the package.json version has changed - id: check uses: EndBug/version-check@5102328418c0130d66ca712d755c303e93368ce2 # v2.1.7 with: # NOTE: `diff-search:true` is preferred so that only the exact commit that bumps the # version triggers this workflow, but `workflow_dispatch` doesn't carry commit or # commit ref info that's needed for it. diff-search: ${{ github.event_name != 'workflow_dispatch' && true || false }} static-checking: ${{ github.event_name == 'workflow_dispatch' && 'localIsNew' || '' }} file-url: ${{ github.event_name == 'workflow_dispatch' && 'https://unpkg.com/igir/package.json' || '' }} - if: steps.check.outputs.changed == 'true' uses: volta-cli/action@5c175f92dea6f48441c436471e6479dbc192e194 # v4.2.1 - if: steps.check.outputs.changed == 'true' uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4 with: path: | ~/.npm ~\AppData\Roaming\npm-cache key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-npm- ${{ runner.os }}- - if: steps.check.outputs.changed == 'true' run: npm ci # Generate the release's markdown template - if: steps.check.outputs.changed == 'true' id: auto-changelog run: | EOF=$(dd if=/dev/urandom bs=15 count=1 status=none | base64) { echo "MARKDOWN<<$EOF" ./scripts/auto-changelog.sh echo "" echo "" echo "$EOF" } >> "${GITHUB_OUTPUT}" # Create/update the draft release - if: steps.check.outputs.changed == 'true' id: release-drafter uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6.1.0 with: name: v${{ steps.check.outputs.version }} tag: v${{ steps.check.outputs.version }} version: ${{ steps.check.outputs.version }} commitish: ${{ env.ref }} # NOTE(cemmer): `template` can't be supplied here, only `header` and `footer`, so have to pick one of those # and make sure the .github/gh-release-drafter.yml's `template` is empty-ish. header: ${{ steps.auto-changelog.outputs.MARKDOWN }} env: # NOTE(cemmer): PAT here causes the release to be made under your account. # ${{ secrets.GITHUB_TOKEN }} would cause it to be created from `github-actions`, even when published. GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} - if: ${{ steps.release-drafter.outputs.id }} run: | { echo "# v${{ steps.check.outputs.version }} @ ${{ env.ref }}" echo "" echo "${{ steps.release-drafter.outputs.html_url }}" } >> "${GITHUB_STEP_SUMMARY}" # Comment back on the PR that caused this push - if: ${{ steps.release-drafter.outputs.id }} id: pr-finder run: | GIT_SHA=$(git rev-parse HEAD) echo "${GIT_SHA}" PR_NUMBER=$(curl -L \ --fail-with-body \ --silent \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ "https://api.github.com/repos/${GITHUB_REPOSITORY}/commits/${GIT_SHA}/pulls" \ | jq --raw-output '.[0].number') echo "PR_NUMBER=${PR_NUMBER}" >> "${GITHUB_OUTPUT}" - if: ${{ steps.release-drafter.outputs.id }} uses: thollander/actions-comment-pull-request@24bffb9b452ba05a4f3f77933840a6a841d1b32b # v3.0.1 with: message: | ## :octocat: GitHub release This pull request resulted in the release: [v${{ steps.check.outputs.version }} @ ${{ env.ref }}](${{ steps.release-drafter.outputs.html_url }}) _Comment generated by the [${{ github.workflow }}](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/attempts/${{ github.run_attempt }}) workflow._ comment-tag: gh-release pr-number: ${{ steps.pr-finder.outputs.PR_NUMBER }}