Skip to content

Publish packages

Publish packages #21

Workflow file for this run

name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
jobs:
build:
name: Build / Node ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18, 20, 21 ]
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm test
success:
name: Success
needs: [build]
runs-on: ubuntu-latest
if: always()
steps:
- run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
- run: exit 0
publish-npm:
name: Publish / npm / ${{ matrix.target }}
runs-on: ubuntu-latest
needs: [success]
permissions:
contents: read
id-token: write
pull-requests: write
strategy:
matrix:
target: [ "@gw2api/types", "@gw2api/fetch" ]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 21
cache: 'npm'
- run: npm ci
- name: Build package
run: npm run build -w ${{ matrix.target }}
- name: Run Publish
run: npm run publish-package -w ${{ matrix.target }}
id: publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_CONFIG_PROVENANCE: true
GITHUB_EVENT_NAME: ${{ github.event_name }}
- name: Find Comment
if: github.event_name == 'pull_request'
uses: peter-evans/find-comment@v3
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: Publish / npm / ${{ matrix.target }}
- name: Delete comment if found but nothing will be published
if: github.event_name == 'pull_request' && steps.fc.outputs.comment-id && !steps.publish.outputs.publish
uses: actions/github-script@v7
with:
script: |
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.fc.outputs.comment-id }}
})
- name: Add comment with packages to be published
if: github.event_name == 'pull_request' && steps.publish.outputs.publish
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
edit-mode: replace
body: |
**Publish / npm / ${{ matrix.target }}**
Merging this PR will publish the npm package `${{ steps.publish.outputs.publish }}`