-
Notifications
You must be signed in to change notification settings - Fork 0
81 lines (69 loc) · 3.05 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
name: Publish packages to npm
on:
push:
branches:
- main
concurrency:
group: "publish"
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
strategy:
max-parallel: 1 # has to be 1 (one) as there are dependencies between the published packages
matrix:
package: [ base, server, client, client-react ]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22.x'
registry-url: 'https://registry.npmjs.org'
scope: '@krmx'
- name: Publish Packages
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
cd ${{ matrix.package }}
echo "-- @krmx/${{ matrix.package }} --"
LOCAL_VERSION=$(node -e "console.log(require('./package.json').version);")
echo "Local version: $LOCAL_VERSION"
REMOTE_VERSION=$(npm show "@krmx/${{ matrix.package }}" version)
echo "Remote version: $REMOTE_VERSION"
if ! .github/tools/semver-greater.sh "$REMOTE_VERSION" "$LOCAL_VERSION"; then
echo "[!!] Skipped publish as the local version of @krmx/${{ matrix.package }} is not greater than what is already published."
else
echo "[!!] Publishing is required."
# Install the package dependencies
npm install
# Check if there are local dependencies in the package.json
if jq -e '.dependencies | to_entries[] | select(.value | startswith("file:")) | length > 0' package.json &> /dev/null; then
echo "Found local dependencies in package.json, updating them now."
jq -r '.dependencies | to_entries[] | select(.value | startswith("file:")) | .key + "|" + .value' package.json |
while IFS="|" read -r pkg path; do
version=$(jq -r .version ${path#file:}/package.json)
echo "- Updating dependencies $pkg to ^$version (found in ${path#file:}/package.json)"
npm install $pkg@^$version
done
fi
# Check if there are local dev dependencies in the package.json
if jq -e '.devDependencies | to_entries[] | select(.value | startswith("file:")) | length > 0' package.json &> /dev/null; then
echo "Found local dev dependencies in package.json, updating them now."
jq -r '.devDependencies | to_entries[] | select(.value | startswith("file:")) | .key + "|" + .value' package.json |
while IFS="|" read -r pkg path; do
version=$(jq -r .version ${path#file:}/package.json)
echo "- Updating dev dependencies $pkg to ^$version (found in ${path#file:}/package.json)"
npm install $pkg@^$version --save-dev
done
fi
# Run tests and build the package
npm run validate
# Publish the package
npm publish --provenance --access public
fi