-
-
Notifications
You must be signed in to change notification settings - Fork 20
115 lines (104 loc) · 4.37 KB
/
gh-release-drafter.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# 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:
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:
token: ${{ secrets.GITHUB_TOKEN }}
# 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: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- 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@v5
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 }}