-
Notifications
You must be signed in to change notification settings - Fork 29
174 lines (153 loc) · 5.81 KB
/
publish-beta.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Publish radashi@beta
on:
workflow_dispatch:
schedule:
- cron: '0 5 * * *'
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- run: pnpm install
- run: pnpm test
- if: ${{ matrix.node-version == '22.x' }}
name: Upload coverage reports to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
validate:
name: Validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version: '22.x'
cache: pnpm
- run: pnpm install
- name: Lint
run: pnpm lint
- name: Check Build
run: pnpm build
publish-beta:
name: Publish Beta
needs: [test, validate]
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
node-version: '22.x'
cache: pnpm
- run: pnpm install
- run: pnpm build
- name: Retrieve Stable Version
id: get-stable-version
run: |
echo "::set-output name=stable-version::v$(npm view radashi version)"
- name: Install git-cliff
run: pnpm install -g [email protected]
- name: Calculate Version
id: set-version
run: |
NEXT_VERSION=$(git-cliff --bumped-version | sed 's/v//')
BUILD_DIGEST=$(find dist package.json -type f -exec shasum -a 256 {} + | shasum -a 256 | cut -c 1-7)
NEXT_BETA_VERSION="$NEXT_VERSION-beta.$BUILD_DIGEST"
echo "Determined next beta version: $NEXT_BETA_VERSION"
echo "::set-output name=version::$NEXT_BETA_VERSION"
- name: Check Version
id: check-version
run: |
if npm -s view radashi@${{ steps.set-version.outputs.version }}; then
echo "🚫 Version ${{ steps.set-version.outputs.version }} already exists"
exit 1
else
echo "🟢 Version ${{ steps.set-version.outputs.version }} is available"
fi
- name: Retrieve Previous Tag
id: get-previous-tag
run: |
TAG=$(git describe --tags --abbrev=0)
echo "::set-output name=tag::$TAG"
echo "::set-output name=tag-commit::$(git rev-parse $TAG)"
- name: Install SSH Client
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
- name: Generate Changelog
env:
GITHUB_TOKEN: ${{ secrets.GIT_CLIFF_PAT }}
run: |
# The entire changelog is regenerated from the point in history at which Radashi was born.
git-cliff 2be4acf455ebec86e846854dbab57bd0bfbbceb7..HEAD -o CHANGELOG.md
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git add CHANGELOG.md
git commit -m "chore(release): ${{ steps.set-version.outputs.version }}" -m "[skip ci]"
git push
- name: Publish to NPM
run: |
npm version ${{ steps.set-version.outputs.version }} --no-git-tag-version
npm publish --tag beta --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Create Git Tags
run: |
TAG=v${{ steps.set-version.outputs.version }}
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git tag $TAG
git push origin $TAG
git tag beta -f
git push origin beta -f
- name: Get PR Numbers
id: get-pr-numbers
run: |
PR_NUMBERS=$(git log --oneline ${{ steps.get-previous-tag.outputs.tag-commit }}..HEAD | grep -o '(#[0-9]\+)$' | tr '\n' ' ')
echo "::set-output name=pr-numbers::${PR_NUMBERS}"
- name: Comment on Pull Requests
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const headCommitSHA = context.sha
const baseCommitSHA = '${{ steps.get-previous-tag.outputs.tag-commit }}'
console.log('Commit range identified: %s ... %s', baseCommitSHA, headCommitSHA)
const prNumbers = '${{ steps.get-pr-numbers.outputs.pr-numbers }}'.split(/\s+/).map(s => s.replace(/\D/g, ''))
console.log('PR numbers:', prNumbers)
for (const prNumber of prNumbers) {
const version = '${{ steps.set-version.outputs.version }}'
const body = `
A new beta version \`${version}\` has been published to NPM. :rocket:
To install:
\`\`\`sh
pnpm add radashi@${version}
\`\`\`
The \`radashi@beta\` tag also includes this PR.
<a href="https://github.com/radashi-org/radashi/compare/${{ steps.get-stable-version.outputs.stable-version }}...${headCommitSHA}">
<img src="https://github.com/radashi-org/radashi/raw/main/.github/img/changes-button.png" alt="See the changes" width="250px" />
</a>`
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: body
})
}