Publish to npm #11
This file contains 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 to npm | |
on: | |
workflow_dispatch: | |
permissions: | |
id-token: write | |
jobs: | |
publish: | |
name: Publish package | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22.x | |
cache: "npm" | |
registry-url: "https://registry.npmjs.org" | |
- run: npm ci | |
- run: npm publish --provenance --access public | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
test: | |
name: Test published package | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
package-manager: [npm, yarn, pnpm] | |
needs: | |
- publish | |
steps: | |
- uses: pnpm/action-setup@v4 | |
name: Install pnpm | |
with: | |
version: "9" | |
if: matrix.package-manager == 'pnpm' | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 22.x | |
- name: Create project | |
run: ${{ matrix.package-manager }} create ts-node project | |
- name: Install project dependencies | |
run: ${{ matrix.package-manager }} install | |
working-directory: project | |
- name: Run build | |
run: ${{ matrix.package-manager }} run build | |
working-directory: project | |
- name: Run tests | |
run: ${{ matrix.package-manager }} test | |
working-directory: project | |
- name: Start app | |
run: ${{ matrix.package-manager }} start & | |
working-directory: project | |
- name: Test app | |
run: curl --fail --silent --show-error --max-time 10 localhost:3000 | jq . | |
shell: bash |