-
Notifications
You must be signed in to change notification settings - Fork 321
75 lines (66 loc) · 2.75 KB
/
prerelease.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
name: Prerelease
on:
push:
branches-ignore:
- "master"
jobs:
build:
name: Build
if: "contains(github.event.head_commit.message, '[prerelease]')"
uses: ./.github/workflows/build-and-upload.yml
secrets:
npm_token: ${{ secrets.npm_token }}
prerelease:
name: Prerelease
needs: build
if: ${{ needs.build.outputs.has_changes == 'true' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set variables
run: |
echo "COMMIT_SHA=${GITHUB_SHA}" >> $GITHUB_ENV
- name: Run Setup
uses: ./.github/actions/setup
with:
npm_token: ${{ secrets.npm_token }}
- uses: ./.github/actions/git-creds
- uses: ./.github/actions/download-builds
- name: Generate new versions
id: generate-versions
run: |
commit_sha=$COMMIT_SHA
preid="alpha-${commit_sha:0:5}"
full_output=$(yarn lerna version --exact --conventional-commits --conventional-prerelease --json --no-changelog --no-push --preid "$preid" -y)
# extract only the JSON portion from the full output, excluding yarn logs
json_output=$(echo "$full_output" | awk '/^\[/{p=1} p; /\]/{p=0}' )
echo 'new_versions<<EOF' >> $GITHUB_OUTPUT
echo "$json_output" >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- run: yarn config set registry https://registry.npmjs.org/
- name: Setup .npmrc for publish
run: npm set "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN"
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_token }}
- name: Publish new versions
run: yarn lerna publish from-package --dist-tag prerelease -y
- name: Get current PR id
uses: 8BitJonny/[email protected]
id: PR
- name: Prepare PR comment
id: prepare-comment
env:
json_data: ${{ steps.generate-versions.outputs.new_versions }}
run: |
echo 'comment_body<<EOF' >> $GITHUB_OUTPUT
echo "A new prerelease version of this PR has been published! 🎉" >> $GITHUB_OUTPUT
echo "To install this prerelease version, run the following command in your terminal with any one of the packages changed in this PR:" >> $GITHUB_OUTPUT
echo "$json_data" | jq -r '.[] | "\nTo update `\(.name)`:\n```\nyarn add \(.name)@\(.newVersion)\n```\nOr with npm:\n```\nnpm i \(.name)@\(.newVersion)\n```\n"' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Create comment with prerelease version details
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ steps.PR.outputs.number }}
body: ${{ steps.prepare-comment.outputs.comment_body }}