Publish package #15
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 package | |
on: | |
workflow_dispatch: | |
permissions: | |
contents: read | |
jobs: | |
check: | |
name: Check before publish | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Check main branch | |
if: github.ref != 'refs/heads/main' | |
run: | | |
echo "::error::Can only publish from the main branch" | |
exit 1 | |
build: | |
name: Build | |
runs-on: ubuntu-22.04 | |
needs: [check] | |
steps: | |
- name: Checkout | |
uses: actions/[email protected] | |
- name: Setup Node.js environment | |
uses: actions/[email protected] | |
with: | |
node-version: '18.18.2' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run lint | |
run: npm run lint | |
- name: Run test | |
run: npm run test | |
- name: Run build | |
run: npm run build | |
- name: Run package | |
id: run-package | |
run: echo "filename=$(npm pack -q)" >> "$GITHUB_OUTPUT" | |
- name: Upload build artifact | |
uses: actions/[email protected] | |
with: | |
name: ${{ steps.run-package.outputs.filename }} | |
path: ${{ steps.run-package.outputs.filename }} | |
if-no-files-found: error | |
outputs: | |
filename: ${{ steps.run-package.outputs.filename }} | |
publish-npm: | |
name: Publish to NPM | |
runs-on: ubuntu-22.04 | |
needs: [build] | |
env: | |
ARTIFACT_FILENAME: ${{ needs.build.outputs.filename }} | |
environment: | |
name: npm | |
url: https://www.npmjs.com/package/read-vietnamese-number | |
steps: | |
- name: Download build artifact | |
uses: actions/[email protected] | |
with: | |
name: ${{ env.ARTIFACT_FILENAME }} | |
- name: Setup Node.js environment | |
uses: actions/[email protected] | |
with: | |
node-version: '18.18.2' | |
registry-url: https://registry.npmjs.org/ | |
- name: Run publish | |
run: npm publish ${{ env.ARTIFACT_FILENAME }} | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |