Compare commits

...

9 Commits

Author SHA1 Message Date
tequ
b43f5a4d8e Merge branch 'main-xahau' into workflow-publish 2026-05-24 12:10:07 +09:00
tequ
8e371d5fb7 Merge branch 'main-xahau' into workflow-publish 2026-05-20 13:26:14 +09:00
tequ
d1670c5f3b Merge branch 'main-xahau' into workflow-publish 2026-05-20 12:52:15 +09:00
tequ
e4569e492a Fix build command 2026-05-20 11:31:53 +09:00
tequ
6eb09d8606 Merge branch 'main-xahau' into workflow-publish 2026-05-18 20:30:40 +09:00
tequ
bd0e5e6537 add ref: ${{ github.event.release.tag_name }} 2026-05-18 18:59:00 +09:00
tequ
355bb3fcce Publish npm packages by GitHub release 2026-05-18 18:47:07 +09:00
tequ
40c07a68b9 add workflow_dispatch 2026-05-18 16:16:32 +09:00
tequ
b2046efe85 Add npm trusted publishing workflow
Add GitHub Actions workflow for npm trusted publishing via OIDC.

The workflow validates package version bumps on PRs with npm publish dry-runs, publishes changed workspace packages from main-xahau, and creates matching GitHub releases. Shared npm publish logic is implemented as a local composite action used by both dry-run and publish jobs.
2026-05-13 12:01:45 +09:00

102
.github/workflows/npm-publish.yml vendored Normal file
View File

@@ -0,0 +1,102 @@
name: Publish npm packages
on:
release:
types: [published]
concurrency:
group: npm-publish-${{ github.event.release.tag_name }}
cancel-in-progress: false
jobs:
publish:
name: Publish ${{ github.event.release.tag_name }}
runs-on: ubuntu-latest
environment: npm
permissions:
contents: read
id-token: write
steps:
- id: release
name: Resolve package from tag
shell: bash
run: |
case "$RELEASE_TAG" in
xahau@*) package_path="packages/xahau" ;;
xahau-address-codec@*) package_path="packages/xahau-address-codec" ;;
xahau-binary-codec@*) package_path="packages/xahau-binary-codec" ;;
xahau-keypairs@*) package_path="packages/xahau-keypairs" ;;
*)
echo "Unsupported release tag: $RELEASE_TAG" >&2
echo "Expected xahau@<version>, xahau-address-codec@<version>, xahau-binary-codec@<version>, or xahau-keypairs@<version>." >&2
exit 1
;;
esac
echo "package-path=$package_path" >> "$GITHUB_OUTPUT"
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
- uses: actions/checkout@v6
with:
ref: ${{ github.event.release.tag_name }}
- uses: actions/setup-node@v6
with:
node-version: "20"
registry-url: https://registry.npmjs.org
package-manager-cache: false
- name: Install dependencies
run: npm ci
- name: Build package
run: npm run build "${{ steps.release.outputs.package-path }}"
- id: package
name: Read package metadata
shell: bash
run: |
package_json="${{ steps.release.outputs.package-path }}/package.json"
name="$(jq -r .name "$package_json")"
version="$(jq -r .version "$package_json")"
tag="$name@$version"
{
echo "name=$name"
echo "version=$version"
echo "tag=$tag"
} >> "$GITHUB_OUTPUT"
- name: Check release tag matches package version
shell: bash
run: |
if [[ "$RELEASE_TAG" != "$PACKAGE_TAG" ]]; then
echo "Release tag $RELEASE_TAG does not match package tag $PACKAGE_TAG." >&2
exit 1
fi
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
PACKAGE_TAG: ${{ steps.package.outputs.tag }}
- name: Check package version is unpublished
shell: bash
run: |
package_spec="${{ steps.package.outputs.tag }}"
stderr_file="$(mktemp)"
if npm view "$package_spec" version --registry https://registry.npmjs.org 2>"$stderr_file"; then
echo "$package_spec is already published." >&2
exit 1
fi
if grep -Eq "E404|404 Not Found|is not in this registry" "$stderr_file"; then
echo "$package_spec is not published yet."
exit 0
fi
cat "$stderr_file" >&2
exit 1
- name: Publish to npm
run: npm publish --workspace "${{ steps.release.outputs.package-path }}" --registry https://registry.npmjs.org