CI Publish to NPM Workflow #9
Workflow file for this run
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: CI Publish to NPM Workflow | |
on: | |
push: | |
tags: | |
- 'v*' | |
workflow_dispatch: | |
jobs: | |
build-package: | |
runs-on: ubuntu-latest | |
env: | |
SEED_PHRASE_1: ${{ secrets.SEED_PHRASE_1 }} | |
SEED_PHRASE_2: ${{ secrets.SEED_PHRASE_2 }} | |
SEED_PHRASE_3: ${{ secrets.SEED_PHRASE_3 }} | |
SEED_PHRASE_4: ${{ secrets.SEED_PHRASE_4 }} | |
SEED_PHRASE_5: ${{ secrets.SEED_PHRASE_5 }} | |
SEED_PHRASE_6: ${{ secrets.SEED_PHRASE_6 }} | |
SEED_PHRASE_7: ${{ secrets.SEED_PHRASE_7 }} | |
SEED_PHRASE_8: ${{ secrets.SEED_PHRASE_8 }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run build | |
run: npm run build | |
- name: Run tests | |
run: npm run test | |
- name: Extract Package Version | |
id: extract_version | |
run: echo "package_version=$(node -p "require('./package.json').version")" >> $GITHUB_ENV | |
- name: Upload build artifacts | |
id: upload_build | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build | |
path: ./dist | |
publish-package: | |
runs-on: ubuntu-latest | |
needs: build-package | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Download build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: build | |
path: ./dist | |
pattern: '**/*' | |
- name: Setup Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18.x' | |
- name: Authenticate to npm registry | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc | |
- name: Remove prepare script (Husky) | |
run: | | |
node -e "let pkg = require('./package.json'); delete pkg.scripts.prepare; require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2));" | |
- name: Publish to npm | |
id: publish | |
run: npm publish | |
- name: Send Slack Notification for Publish | |
if: steps.publish.outcome == 'success' | |
uses: slackapi/[email protected] | |
with: | |
payload: | | |
{ | |
"blocks": [ | |
{ | |
"type": "section", | |
"text": { | |
"type": "mrkdwn", | |
"text": "*:tada: :zk-logo-icon-square-black: zkVerifyJS Package v${{ env.package_version }} Published :zk-logo-icon-square-black: :tada:*\n\n*Build URL:* <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|Click here to view the build>\n\n*Published Package:* <https://www.npmjs.com/package/zkverifyjs/v/${{ env.package_version }}|zkverifyjs@${{ env.package_version }}>" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.RELEASES_PROD_SLACK_WEBHOOK_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |