Update dependencies #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
branches: | |
- 'main' | |
workflow_dispatch: | |
inputs: | |
tag: | |
description: 'Release tag (e.g., v1.2.3)' | |
required: true | |
type: string | |
skip_ci_check: | |
description: 'Skip CI status check' | |
required: false | |
type: boolean | |
default: false | |
permissions: | |
contents: write | |
id-token: write | |
jobs: | |
check_release: | |
name: Check for release tag | |
runs-on: ubuntu-latest | |
outputs: | |
proceed: ${{ github.event_name == 'workflow_dispatch' && 'true' || steps.check_tag.outputs.proceed }} | |
release_tag: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || steps.check_tag.outputs.release_tag }} | |
steps: | |
- name: Checkout | |
if: github.event_name != 'workflow_dispatch' | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Check if release tag exists for this commit | |
if: github.event_name != 'workflow_dispatch' | |
id: check_tag | |
run: | | |
# For push to main branch, check if a release tag points to this commit | |
TAGS=$(git tag --points-at ${{ github.sha }} | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$' || true) | |
if [[ -z "$TAGS" ]]; then | |
echo "No release tag found for commit ${{ github.sha }} on main branch" | |
echo "proceed=false" >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
# Check for multiple tags and fail if found | |
TAG_COUNT=$(echo "$TAGS" | wc -l) | |
if [[ $TAG_COUNT -gt 1 ]]; then | |
echo "Multiple release tags found for this commit:" | |
echo "$TAGS" | |
echo "Please use workflow dispatch to specify which tag to release" | |
exit 1 | |
fi | |
RELEASE_TAG="$TAGS" | |
echo "Found release tag: $RELEASE_TAG" | |
echo "proceed=true" >> $GITHUB_OUTPUT | |
echo "release_tag=$RELEASE_TAG" >> $GITHUB_OUTPUT | |
release: | |
name: Release | |
runs-on: ubuntu-latest | |
needs: check_release | |
if: needs.check_release.outputs.proceed == 'true' | |
environment: npm | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event_name == 'workflow_dispatch' && inputs.tag || github.ref }} | |
fetch-depth: 0 | |
- name: Verify tag matches package.json version | |
run: | | |
jq --raw-output --exit-status --arg tag "$RELEASE_TAG" ' | |
if (.version == ($tag | ltrimstr("v"))) then | |
"Package version (\(.version)) matches tag version (\($tag | ltrimstr("v")))" | |
else | |
"Package version (\(.version)) does not match tag version (\($tag | ltrimstr("v")))" | halt_error(1) | |
end' package.json | |
env: | |
RELEASE_TAG: ${{ needs.check_release.outputs.release_tag }} | |
- name: Check CI status | |
if: ${{ github.event_name != 'workflow_dispatch' || !inputs.skip_ci_check }} | |
run: | | |
# Check if CI has completed successfully for this commit | |
gh run list --commit ${{ github.sha }} --status success --json workflowName | jq --raw-output --exit-status ' | |
if any(.[]; .workflowName == "Install and test AVA") then | |
"All CI checks have passed!" | |
else | |
"CI has not completed successfully for this commit" | halt_error(1) | |
end' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: package.json | |
cache: npm | |
registry-url: https://registry.npmjs.org | |
- name: Publish to npm with provenance | |
run: npm publish --provenance | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
- name: Create GitHub Release | |
run: | | |
gh release create "$RELEASE_TAG" \ | |
--title "$RELEASE_TAG" \ | |
--draft \ | |
--generate-notes | |
env: | |
RELEASE_TAG: ${{ needs.check_release.outputs.release_tag }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |