-
Notifications
You must be signed in to change notification settings - Fork 3
85 lines (72 loc) · 2.97 KB
/
publish.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
name: Publish to npm
on:
push:
branches:
- main
- next
- beta
tags:
- "v*"
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
registry-url: "https://registry.npmjs.org"
- name: Install dependencies and build
run: npm ci && lerna run build --ignore @react-motion-router/example
- name: Get tag name and commit hash
id: git-info
run: |
if [[ "${GITHUB_REF##*/}" == "main" ]]; then
echo "TAG_NAME=latest" >> $GITHUB_ENV
else
echo "TAG_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
fi
COMMIT_HASH=$(git rev-parse --short HEAD)
LAST_COMMIT_HASH=$(git rev-parse --short HEAD~1)
echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV
echo "LAST_COMMIT_HASH=${LAST_COMMIT_HASH}" >> $GITHUB_ENV
- name: Conditional Version Update
id: version
if: startsWith(env.TAG_NAME, 'next') || startsWith(env.TAG_NAME, 'beta')
run: |
TAG_NAME=${{ env.TAG_NAME }}
COMMIT_HASH=${{ env.COMMIT_HASH }}
LAST_COMMIT_HASH=${{ env.LAST_COMMIT_HASH }}
ALL_PACKAGES_JSON=$(npx lerna list --json)
CHANGED_PACKAGES_JSON=$(npx lerna list --json --since ${LAST_COMMIT_HASH})
CHANGED_PACKAGES_COUNT=$(echo $CHANGED_PACKAGES_JSON | jq '. | length')
if [[ $CHANGED_PACKAGES_COUNT -eq 0 ]]; then
echo "No packages changed. Exiting..."
echo "versioned=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo $CHANGED_PACKAGES_JSON | jq -r '.[].location' | while read -r package; do
CURRENT_VERSION=$(jq -r '.version' $package/package.json)
NEW_VERSION="${CURRENT_VERSION}-${TAG_NAME}.sha-${COMMIT_HASH}"
jq ".version = \"${NEW_VERSION}\"" $package/package.json > $package/package.json.tmp && mv $package/package.json.tmp $package/package.json
done
echo $ALL_PACKAGES_JSON | jq -r '.[].location' | while read -r package; do
if ! echo $CHANGED_PACKAGES_JSON | jq -r '.[].location' | grep -q "$package"; then
jq ".private = true" $package/package.json > $package/package.json.tmp && mv $package/package.json.tmp $package/package.json
fi
done
echo "versioned=true" >> "$GITHUB_OUTPUT"
- name: Assume unchanged for all package.json files
run: |
git ls-files -m | grep 'package.json' | xargs -I {} git update-index --assume-unchanged {}
- name: Publish packages
if: ${{ steps.version.outputs.versioned == 'true' }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
TAG_NAME=${{ env.TAG_NAME }}
npx lerna publish from-package --yes --dist-tag $TAG_NAME