You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.6 KiB
112 lines
3.6 KiB
name: Release Packages
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
inputs:
|
|
packages:
|
|
description: 'Packages to release (comma-separated, or "all" for all packages)'
|
|
required: false
|
|
default: 'all'
|
|
|
|
jobs:
|
|
release:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
id-token: write # <-- required for JSR OIDC
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v4
|
|
with:
|
|
version: latest
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 22
|
|
cache: pnpm
|
|
cache-dependency-path: '**/pnpm-lock.yaml'
|
|
|
|
- name: Install dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Configure npm auth
|
|
env:
|
|
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
|
run: |
|
|
pnpm config set //registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}
|
|
pnpm config set registry https://registry.npmjs.org/
|
|
|
|
- name: Resolve package list
|
|
id: pkgs
|
|
shell: bash
|
|
run: |
|
|
if [ "${{ github.event.inputs.packages }}" = "all" ] || [ -z "${{ github.event.inputs.packages }}" ]; then
|
|
mapfile -t TARGETS < <(ls -d packages/* | grep -v 'packages/web')
|
|
else
|
|
IFS=',' read -ra TARGETS <<< "${{ github.event.inputs.packages }}"
|
|
TARGETS=("${TARGETS[@]/#/packages/}")
|
|
fi
|
|
printf '%s\n' "${TARGETS[@]}" | paste -sd, - > targets.txt
|
|
echo "list=$(cat targets.txt)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build selected packages (tsdown)
|
|
run: |
|
|
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
|
|
for dir in "${TARGETS[@]}"; do
|
|
echo "Building $dir"
|
|
pnpm --filter "./$dir" run build
|
|
done
|
|
|
|
- name: Sync jsr.json version from package.json
|
|
run: |
|
|
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
|
|
for dir in "${TARGETS[@]}"; do
|
|
if [ -f "$dir/jsr.json" ] && [ -f "$dir/package.json" ]; then
|
|
PKG_VER=$(jq -r .version "$dir/package.json")
|
|
jq --arg v "$PKG_VER" '.version = $v' "$dir/jsr.json" > "$dir/jsr.json.tmp" && mv "$dir/jsr.json.tmp" "$dir/jsr.json"
|
|
echo "Updated $dir/jsr.json to version $PKG_VER"
|
|
fi
|
|
done
|
|
|
|
- name: Publish to JSR (OIDC)
|
|
run: |
|
|
set -euo pipefail
|
|
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
|
|
for dir in "${TARGETS[@]}"; do
|
|
if [ -f "$dir/jsr.json" ]; then
|
|
echo "Publishing $dir to JSR via OIDC…"
|
|
cd "$dir"
|
|
[ -d dist ] || pnpm run build
|
|
if ! npx --yes jsr publish 2>&1 | tee jsr_publish.log; then
|
|
echo "JSR publish failed for $dir. Error output:"
|
|
cat jsr_publish.log
|
|
fi
|
|
cd - >/dev/null
|
|
fi
|
|
done
|
|
|
|
- name: Replace exports entry in package.json
|
|
run: |
|
|
tmp=$(mktemp)
|
|
jq '.exports["."] = "./dist/mod.mjs"' package.json > "$tmp" \
|
|
&& mv "$tmp" package.json
|
|
|
|
- name: Publish to npm
|
|
run: |
|
|
set -euo pipefail
|
|
IFS=',' read -ra TARGETS <<< "${{ steps.pkgs.outputs.list }}"
|
|
for dir in "${TARGETS[@]}"; do
|
|
if [ -f "$dir/package.json" ]; then
|
|
echo "Publishing $dir to npm…"
|
|
cd "$dir"
|
|
[ -d dist ] || pnpm run build
|
|
npm publish --access public || echo "npm publish failed for $dir"
|
|
cd - >/dev/null
|
|
fi
|
|
done
|
|
|
|
|
|
|