Skip to content

Commit dfa7669

Browse files
committed
Add CI to auto publish packages
1 parent 1a2314a commit dfa7669

2 files changed

Lines changed: 166 additions & 6 deletions

File tree

.github/workflows/publish.yml

Lines changed: 159 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,178 @@
1-
name: Publish Package
1+
name: Publish Packages
22

33
on:
44
push:
55
branches:
66
- main
7+
paths:
8+
- 'packages/*/package.json'
9+
workflow_dispatch:
10+
inputs:
11+
package:
12+
description: 'Package to publish (web-client, components, or all)'
13+
required: true
14+
default: 'all'
15+
type: choice
16+
options:
17+
- all
18+
- web-client
19+
- components
720

821
permissions:
922
id-token: write # Required for OIDC
1023
contents: read
1124

1225
jobs:
13-
publish:
26+
detect-changes:
1427
runs-on: ubuntu-latest
28+
outputs:
29+
web-client-changed: ${{ steps.changes.outputs.web-client }}
30+
components-changed: ${{ steps.changes.outputs.components }}
31+
web-client-version: ${{ steps.versions.outputs.web-client }}
32+
components-version: ${{ steps.versions.outputs.components }}
1533
steps:
1634
- uses: actions/checkout@v4
35+
with:
36+
fetch-depth: 2 # Need previous commit to compare
37+
38+
- name: Check for version changes
39+
id: changes
40+
run: |
41+
# Check if web-client version changed
42+
if git diff HEAD~1 HEAD -- packages/web-client/package.json | grep -q '"version"'; then
43+
echo "web-client=true" >> $GITHUB_OUTPUT
44+
else
45+
echo "web-client=false" >> $GITHUB_OUTPUT
46+
fi
47+
48+
# Check if components version changed
49+
if git diff HEAD~1 HEAD -- packages/components/package.json | grep -q '"version"'; then
50+
echo "components=true" >> $GITHUB_OUTPUT
51+
else
52+
echo "components=false" >> $GITHUB_OUTPUT
53+
fi
54+
55+
- name: Get package versions
56+
id: versions
57+
run: |
58+
WEB_CLIENT_VERSION=$(node -p "require('./packages/web-client/package.json').version")
59+
COMPONENTS_VERSION=$(node -p "require('./packages/components/package.json').version")
60+
echo "web-client=${WEB_CLIENT_VERSION}" >> $GITHUB_OUTPUT
61+
echo "components=${COMPONENTS_VERSION}" >> $GITHUB_OUTPUT
62+
63+
publish-web-client:
64+
needs: detect-changes
65+
if: |
66+
needs.detect-changes.outputs.web-client-changed == 'true' ||
67+
(github.event_name == 'workflow_dispatch' && (github.event.inputs.package == 'web-client' || github.event.inputs.package == 'all'))
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
72+
- uses: pnpm/action-setup@v4
73+
with:
74+
version: 9
75+
76+
- uses: actions/setup-node@v4
77+
with:
78+
node-version: '24'
79+
registry-url: 'https://registry.npmjs.org'
80+
cache: 'pnpm'
81+
82+
- name: Install dependencies
83+
run: pnpm install --frozen-lockfile
84+
85+
- name: Build web-client
86+
working-directory: packages/web-client
87+
run: pnpm run build
88+
89+
# - name: Test web-client
90+
# working-directory: packages/web-client
91+
# run: pnpm run test
92+
93+
- name: Check if version exists on npm
94+
id: check-version
95+
working-directory: packages/web-client
96+
run: |
97+
PACKAGE_NAME=$(node -p "require('./package.json').name")
98+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
99+
100+
if npm view ${PACKAGE_NAME}@${PACKAGE_VERSION} version 2>/dev/null; then
101+
echo "exists=true" >> $GITHUB_OUTPUT
102+
echo "⚠️ Version ${PACKAGE_VERSION} already exists on npm"
103+
else
104+
echo "exists=false" >> $GITHUB_OUTPUT
105+
echo "✅ Version ${PACKAGE_VERSION} is new"
106+
fi
107+
108+
- name: Publish web-client
109+
if: steps.check-version.outputs.exists == 'false'
110+
working-directory: packages/web-client
111+
run: pnpm publish --no-git-checks --access public
112+
113+
- name: Create release tag
114+
if: steps.check-version.outputs.exists == 'false'
115+
run: |
116+
VERSION=${{ needs.detect-changes.outputs.web-client-version }}
117+
git tag "web-client-v${VERSION}"
118+
echo "Created tag: web-client-v${VERSION}"
119+
120+
publish-components:
121+
needs: detect-changes
122+
if: |
123+
needs.detect-changes.outputs.components-changed == 'true' ||
124+
(github.event_name == 'workflow_dispatch' && (github.event.inputs.package == 'components' || github.event.inputs.package == 'all'))
125+
runs-on: ubuntu-latest
126+
steps:
127+
- uses: actions/checkout@v4
128+
129+
- uses: pnpm/action-setup@v4
130+
with:
131+
version: 9
17132

18133
- uses: actions/setup-node@v4
19134
with:
20135
node-version: '24'
21136
registry-url: 'https://registry.npmjs.org'
22-
- run: npm ci
23-
- run: npm run build --if-present
24-
- run: npm test
25-
- run: npm publish
137+
cache: 'pnpm'
138+
139+
- name: Install dependencies
140+
run: pnpm install --frozen-lockfile
141+
142+
- name: Build components (and dependencies)
143+
run: |
144+
pnpm --filter @pelicanplatform/web-client run build
145+
pnpm --filter @pelicanplatform/components run build
146+
147+
- name: Test components
148+
working-directory: packages/components
149+
run: pnpm run test
150+
151+
- name: Check if version exists on npm
152+
id: check-version
153+
working-directory: packages/components
154+
run: |
155+
PACKAGE_NAME=$(node -p "require('./package.json').name")
156+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
157+
158+
if npm view ${PACKAGE_NAME}@${PACKAGE_VERSION} version 2>/dev/null; then
159+
echo "exists=true" >> $GITHUB_OUTPUT
160+
echo "⚠️ Version ${PACKAGE_VERSION} already exists on npm"
161+
else
162+
echo "exists=false" >> $GITHUB_OUTPUT
163+
echo "✅ Version ${PACKAGE_VERSION} is new"
164+
fi
165+
166+
- name: Publish components
167+
if: steps.check-version.outputs.exists == 'false'
168+
working-directory: packages/components
169+
run: pnpm publish --no-git-checks --access public
170+
env:
171+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
172+
173+
- name: Create release tag
174+
if: steps.check-version.outputs.exists == 'false'
175+
run: |
176+
VERSION=${{ needs.detect-changes.outputs.components-version }}
177+
git tag "components-v${VERSION}"
178+
echo "Created tag: components-v${VERSION}"

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
# Pelican Platform Monorepo
22

3+
## Publishing
4+
5+
This monorepo contains two independently versioned and published npm packages:
6+
- `@pelicanplatform/web-client` (packages/web-client)
7+
- `@pelicanplatform/components` (packages/components)
8+
9+
To bump the version of a package, run `npm version patch` (or minor/major) in the appropriate package directory, commit the change, and push to main. The GitHub Actions workflow will automatically publish the package if the version is new.

0 commit comments

Comments
 (0)