-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (86 loc) · 3.37 KB
/
publish.yml
File metadata and controls
103 lines (86 loc) · 3.37 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: "Monorepo Packages Release to NPM"
on:
push:
branches:
- main
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
discover-packages:
name: "Discover Packages"
runs-on: ubuntu-latest
outputs:
packages: ${{ steps.packages.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: packages
name: "Find packages in ./packages"
run: |
echo "Discovering packages in ./packages..."
# Get folder names under packages/ and convert to JSON array
PACKAGES=$(find packages -maxdepth 1 -mindepth 1 -type d -printf '%f\n' \
| jq -R -s -c 'split("\n")[:-1]')
echo "Found packages: $PACKAGES"
echo "matrix=$PACKAGES" >> "$GITHUB_OUTPUT"
release:
name: "Release ${{ matrix.package }} to NPM"
needs: discover-packages
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
package: ${{ fromJson(needs.discover-packages.outputs.packages) }}
env:
# Directory for the current package in the matrix
PACKAGE_DIR: packages/${{ matrix.package }}
steps:
- uses: actions/checkout@v4
- name: Read version from package.json
id: read_version
run: |
VERSION=$(jq -r '.version' "$PACKAGE_DIR/package.json")
echo "Package dir: $PACKAGE_DIR"
echo "Package version: $VERSION"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Check if version exists on npm
id: check
run: |
PACKAGE_NAME=$(jq -r '.name' "$PACKAGE_DIR/package.json")
VERSION="${{ steps.read_version.outputs.version }}"
echo "Checking npm for $PACKAGE_NAME@$VERSION"
EXISTS=$(npm view "$PACKAGE_NAME" versions --json 2>/dev/null \
| jq -e '.[] | select(.=="'"$VERSION"'")' || echo "no")
if [ "$EXISTS" = "no" ]; then
echo "Version $PACKAGE_NAME@$VERSION does not exist on npm. Will publish."
echo "should_publish=true" >> "$GITHUB_OUTPUT"
else
echo "Version $PACKAGE_NAME@$VERSION already exists on npm. Skipping publish."
echo "should_publish=false" >> "$GITHUB_OUTPUT"
fi
- uses: actions/setup-node@v4
if: steps.check.outputs.should_publish == 'true'
with:
node-version: '25'
registry-url: 'https://registry.npmjs.org'
scope: \@${{ github.repository_owner }}
- name: Update npm
if: steps.check.outputs.should_publish == 'true'
run: npm install -g npm@latest
- name: Install dependencies (root)
if: steps.check.outputs.should_publish == 'true'
run: npm install --workspace=${{ env.PACKAGE_DIR }}
- name: Build package
if: steps.check.outputs.should_publish == 'true'
working-directory: ${{ env.PACKAGE_DIR }}
run: npm run build --if-present
- name: Publish package
if: steps.check.outputs.should_publish == 'true'
working-directory: ${{ env.PACKAGE_DIR }}
run: npm publish --access public
- name: Skip publish (version already exists)
if: steps.check.outputs.should_publish == 'false'
run: |
PACKAGE_NAME=$(jq -r '.name' "$PACKAGE_DIR/package.json")
echo "Version ${{ steps.read_version.outputs.version }} for $PACKAGE_NAME already exists on npm. Skipping publish."