Publish #24
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: Publish | |
| on: | |
| workflow_run: | |
| workflows: ['Check Issues'] | |
| types: | |
| - completed | |
| jobs: | |
| #debug: | |
| # runs-on: ubuntu-latest | |
| # if: github.event.workflow_run.conclusion == 'success' | |
| # steps: | |
| # - run: echo '${{ toJson(github.event.workflow_run) }}' | |
| publish: | |
| name: Publish package | |
| runs-on: ubuntu-latest | |
| # Only publish when: | |
| # - "Check Issues" finished successfully | |
| # - the triggering event was a tag push (tag name starts with "v") | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| startsWith(github.event.workflow_run.head_branch, 'v') | |
| permissions: | |
| actions: read | |
| contents: write | |
| id-token: write | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| fetch-depth: 0 | |
| - name: Get tag name | |
| id: tag | |
| run: | | |
| TAG=$(git tag --points-at HEAD | head -n 1) | |
| if [ -z "$TAG" ]; then | |
| echo "No tag found on HEAD" >&2 | |
| exit 1 | |
| fi | |
| echo "tag=$TAG" >> "$GITHUB_OUTPUT" | |
| - name: Substring version | |
| id: substring | |
| uses: bhowell2/github-substring-action@1.0.2 | |
| with: | |
| value: ${{ steps.tag.outputs.tag }} | |
| index_of_str: v | |
| - name: Create GitHub release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: ${{ steps.substring.outputs.substring }} | |
| tag_name: ${{ steps.tag.outputs.tag }} | |
| generate_release_notes: true | |
| body: Version ${{ steps.substring.outputs.substring }} of the package | |
| body_path: ./CHANGELOG.md | |
| draft: false | |
| prerelease: false | |
| # Use the build artifact produced by build.yml (triggered from Check Issues) | |
| - name: Download build artifact | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| RUN_ID: ${{ github.event.workflow_run.id }} | |
| run: | | |
| set -euo pipefail | |
| echo "Using workflow_run.id: $RUN_ID" | |
| API_URL="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/runs/$RUN_ID/artifacts" | |
| echo "Listing artifacts from: $API_URL" | |
| JSON=$(curl -sSL \ | |
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "$API_URL") | |
| echo "Artifacts:" | |
| echo "$JSON" | |
| ARTIFACT_ID=$(echo "$JSON" \ | |
| | jq -r '.artifacts[] | select(.name == "jscv-solutions-logger") | .id' \ | |
| | head -n 1) | |
| if [ -z "$ARTIFACT_ID" ]; then | |
| echo "Artifact 'jscv-solutions-logger' not found for run $RUN_ID" >&2 | |
| exit 1 | |
| fi | |
| echo "Found artifact id: $ARTIFACT_ID" | |
| DOWNLOAD_URL="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/actions/artifacts/$ARTIFACT_ID/zip" | |
| echo "Downloading from: $DOWNLOAD_URL" | |
| curl -sSL \ | |
| -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "$DOWNLOAD_URL" \ | |
| -o artifact.zip | |
| mkdir -p dist | |
| unzip -o artifact.zip -d dist | |
| rm artifact.zip | |
| echo "Artifact downloaded and extracted into dist/" | |
| - name: Install PNPM | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| version: '10.15.0' | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '22.18.0' | |
| registry-url: 'https://registry.npmjs.org' | |
| - name: Publish to NPM | |
| env: | |
| NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
| run: npm publish --provenance --access public |