-
Notifications
You must be signed in to change notification settings - Fork 80
70 lines (55 loc) · 1.97 KB
/
npm-publish-canary.yaml
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
name: Publish canary to NPM
on:
pull_request:
types:
- opened
- synchronize
paths:
- packages/**
push:
branches: [main]
paths:
- packages/**
jobs:
publish-packages:
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.owner.login == 'livecycle' || github.event.repository.owner.login == 'livecycle'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: yarn
- run: yarn
- name: Set NPM token
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
- name: Set git identity
run: |
# version git commit is not pushed, so this just needs to be configured
git config user.email "$(git log -1 --format='%ae')"
git config user.name "$(git log -1 --format='%an')"
- name: npm publish
run: |
set -eou pipefail
set -x
REF="${{ github.head_ref }}"
if [[ -z "$REF" ]]; then
REF="${{ github.ref_name }}"
fi
# this will be the NPM dist-tag
GIT_ID=$(echo "${REF}" | sed 's/[^a-zA-Z0-9_-]/-/g')
# run 'lerna version' to get get next prerelease
yarn -s lerna version prerelease --no-git-tag-version --preid $GIT_ID --ignore-scripts --exact --yes
# modify the prerelease to include the git commit hash
VERSION=$(jq -r .version lerna.json | sed -E "s/[^.]+$/$(git rev-parse --short HEAD)/")
# run 'lerna version' again to actually set the version with the commit hash
yarn -s lerna version $VERSION --no-git-tag-version --preid $GIT_ID --ignore-scripts --exact --yes
# commit that goes nowhere
git commit -m "canary version $VERSION" lerna.json packages/*/package.json
# publish
yarn -s lerna publish from-package --pre-dist-tag $GIT_ID --yes
# undo the commit
git reset --hard HEAD^1