Skip to content

v2.11.0 (#1240)

v2.11.0 (#1240) #513

# 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 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@v2
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.ref }}
# 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@v2
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@v4
- 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@v6
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@v2
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 }}