-
Notifications
You must be signed in to change notification settings - Fork 134
74 lines (67 loc) · 2.56 KB
/
label-alpha-release.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
name: Autorelease alpha version
on:
pull_request:
types:
- labeled
jobs:
check-permissions:
name: "Check user has permission to release"
runs-on: ubuntu-latest
outputs:
# can have multiple outputs
# check-result: ${{ steps.check-permissions.outputs.check-result }}
# user-permission: ${{ steps.check-permissions.outputs.user-permission }}
require-result: ${{ steps.check-permissions.outputs.require-result }}
steps:
- uses: actions-cool/check-user-permission@v2
id: check-permissions
with:
require: 'write'
warn-when-failed:
name: Warn when the user does not have the required permissions
runs-on: ubuntu-latest
needs: check-permissions
if: needs.check-permissions.outputs.require-result == 'false'
steps:
- run: echo "The user does not have the write permissions to trigger this action (pun intended)."
- run: echo "require-result = ${{ needs.check-permissions.outputs.require-result }}"
label-alpha-release:
name: Release alpha version based on PR label
runs-on: ubuntu-latest
needs: check-permissions
if: needs.check-permissions.outputs.require-result == 'true' &&
contains(github.event.pull_request.labels.*.name, 'release alpha')
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.base.ref }}
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
fetch-depth: 0
- uses: pnpm/action-setup@v4
with:
version: 8.x.x
- uses: actions/setup-node@v4
with:
node-version: '18'
registry-url: https://registry.npmjs.org
cache: 'pnpm'
- run: pnpm install
- name: Determine new version
id: versions
if: steps.bump-type.outputs.bump-type != 'null'
run: |
OLD_VERSION=$(jq ".version" package.json -r)
NEW_VERSION=$(pnpx semver $OLD_VERSION -i prerelease --preid alpha)
echo "old-version=$OLD_VERSION" >> "$GITHUB_OUTPUT"
echo "new-version=$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Update version in package.json
if: steps.bump-type.outputs.bump-type != 'null'
run: |
mv package.json package.old.json
jq --indent 4 '.version = "${{ steps.versions.outputs.new-version }}"' package.old.json > package.json
rm package.old.json
- name: Publish the alpha in the npm registry
run: npm publish --access public --tag alpha
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}