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 # Node + pnpm (with cache) - name: Setup Node uses: actions/setup-node@v4 with: node-version: 22 cache: pnpm cache-dependency-path: '**/pnpm-lock.yaml' - name: Setup pnpm uses: pnpm/action-setup@v4 with: version: latest - 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: Install deps (root) run: pnpm install - 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: 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 PUBLISH_OUTPUT=$(npm publish --access public 2>&1); PUBLISH_EXIT=$?; if [ $PUBLISH_EXIT -ne 0 ]; then echo "npm publish failed for $dir (exit code: $PUBLISH_EXIT)"; echo "$PUBLISH_OUTPUT"; fi cd - >/dev/null fi 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 npx --yes jsr publish || echo "JSR publish failed for $dir" cd - >/dev/null fi done