-
Notifications
You must be signed in to change notification settings - Fork 0
73 lines (61 loc) · 2.35 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
name: Publish packages to npm
on:
push:
branches:
- main
- 0.6.0
concurrency:
group: "publish"
cancel-in-progress: false
defaults:
run:
shell: bash
jobs:
publish:
strategy:
max-parallel: 1 # has to be 1 (one) as there are dependencies between the published packages
matrix:
package: [base, server]
runs-on: ubuntu-latest
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 [ "$LOCAL_VERSION" = "$REMOTE_VERSION" ]; then
echo "[!!] Publishing skipped as the version 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
cat package-lock.json | jq .packages.'"node_modules/@krmx/$pkg"'
done
fi
# Print information about the package
cat package.json
cat package-lock.json
# Run tests and build the package
npm run precommit
# Publish the package
# npm publish --access public
fi