mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-12-06 17:52:16 +00:00
Publish npm packages automatically on version bumps (#1431)
* publish npm packages automatically when their version changes * run the publish job in a main-only npm environment * drop release tags so the publish job only needs read access * split the package check and publish into separate workflows
This commit is contained in:
37
.github/workflows/npm-packages-check.yml
vendored
Normal file
37
.github/workflows/npm-packages-check.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: NPM Packages Check
|
||||
|
||||
# Type-checks and builds the shared packages on every PR that touches them.
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'resources/js/packages/**'
|
||||
- 'package.json'
|
||||
- 'package-lock.json'
|
||||
- '.github/workflows/npm-packages-check.yml'
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
check:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
env:
|
||||
# Dependency order: ui and composables build against api
|
||||
PACKAGES: api ui composables
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: '24.x'
|
||||
- run: npm ci
|
||||
- name: Type-check and build packages
|
||||
run: |
|
||||
for package in $PACKAGES; do
|
||||
dir="resources/js/packages/$package"
|
||||
[ -d "$dir" ] || continue
|
||||
echo "::group::$package"
|
||||
npm run type-check --if-present --prefix "$dir"
|
||||
npm run build --prefix "$dir"
|
||||
echo "::endgroup::"
|
||||
done
|
||||
66
.github/workflows/npm-packages.yml
vendored
Normal file
66
.github/workflows/npm-packages.yml
vendored
Normal file
@@ -0,0 +1,66 @@
|
||||
name: NPM Packages
|
||||
|
||||
# Publishes each shared package whose version isn't on npm yet. npm's trusted
|
||||
# publisher config points at this file, so keep unrelated changes out of it.
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- 'resources/js/packages/**'
|
||||
- '.github/workflows/npm-packages.yml'
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
# Restricted to main in the repo settings, which a branch can't override
|
||||
# by editing this file. npm's trusted publisher config requires it too.
|
||||
environment: npm
|
||||
concurrency:
|
||||
group: npm-publish
|
||||
cancel-in-progress: false
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write # npm trusted publishing and provenance
|
||||
env:
|
||||
# Dependency order: ui and composables build against api
|
||||
PACKAGES: api ui composables
|
||||
steps:
|
||||
- uses: actions/checkout@v7
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
# npm >= 11.5.1 is required for trusted publishing
|
||||
node-version: '24.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- run: npm ci
|
||||
- name: Publish new package versions
|
||||
env:
|
||||
# Fallback until trusted publishing is configured for every package
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
for package in $PACKAGES; do
|
||||
dir="resources/js/packages/$package"
|
||||
[ -d "$dir" ] || continue
|
||||
name=$(node -p "require('./$dir/package.json').name")
|
||||
version=$(node -p "require('./$dir/package.json').version")
|
||||
|
||||
# Build every package so later ones can build against it
|
||||
npm run type-check --if-present --prefix "$dir"
|
||||
npm run build --prefix "$dir"
|
||||
|
||||
if existing=$(npm view "$name@$version" version 2>&1); then
|
||||
echo "$name@$version is already published"
|
||||
continue
|
||||
elif ! grep -q E404 <<< "$existing"; then
|
||||
echo "$existing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
(cd "$dir" && npm publish --provenance --access public)
|
||||
done
|
||||
32
.github/workflows/npm-publish-api.yml
vendored
32
.github/workflows/npm-publish-api.yml
vendored
@@ -1,32 +0,0 @@
|
||||
name: Publish API package to NPM
|
||||
on:
|
||||
workflow_dispatch
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@v7
|
||||
# Setup .npmrc file to publish to npm
|
||||
- name: Install root project dependencies
|
||||
run: npm ci
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: '20.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
working-directory: ./resources/js/packages/api
|
||||
- name: Build package
|
||||
run: npm run build
|
||||
working-directory: ./resources/js/packages/api
|
||||
- name: Publish Package
|
||||
run: npm publish --provenance --access public
|
||||
working-directory: ./resources/js/packages/api
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
32
.github/workflows/npm-publish-ui.yml
vendored
32
.github/workflows/npm-publish-ui.yml
vendored
@@ -1,32 +0,0 @@
|
||||
name: Publish UI package to NPM
|
||||
on:
|
||||
workflow_dispatch
|
||||
permissions:
|
||||
contents: read
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
id-token: write
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@v7
|
||||
# Setup .npmrc file to publish to npm
|
||||
- uses: actions/setup-node@v7
|
||||
with:
|
||||
node-version: '20.x'
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
- name: Install root project dependencies
|
||||
run: npm ci
|
||||
- name: Install package dependencies
|
||||
run: npm ci
|
||||
working-directory: ./resources/js/packages/ui
|
||||
- name: Build package
|
||||
run: npm run build
|
||||
working-directory: ./resources/js/packages/ui
|
||||
- name: Publish Package
|
||||
run: npm publish --provenance --access public
|
||||
working-directory: ./resources/js/packages/ui
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -12,6 +12,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vite build",
|
||||
"type-check": "tsc --noEmit",
|
||||
"watch": "vite build --watch",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user