Web3 1195 readme and slack / github release notes (#16) #10
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-and-publish: | |
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 | |
with: | |
fetch-depth: 0 | |
- 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: Authenticate to npm registry | |
env: | |
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | |
run: echo "//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}" > ~/.npmrc | |
- name: Generate Release Notes | |
id: generate_release_notes | |
run: | | |
git fetch --tags | |
current_tag="v${{ env.package_version }}" | |
last_tag=$(git tag --sort=-creatordate | grep -B1 "$current_tag" | head -n 1) | |
if [ -z "$last_tag" ]; then | |
echo "No previous tag found. Generating release notes for all history." | |
npx conventional-changelog -p angular -o release_notes.md | |
else | |
echo "Generating release notes from $last_tag to $current_tag." | |
npx conventional-changelog -p angular -o release_notes.md --from "$last_tag" --to "$current_tag" | |
fi | |
if [ ! -s release_notes.md ]; then | |
echo "Error: No new conventional commits found to generate release notes." | |
exit 1 | |
fi | |
echo "release_notes<<EOF" >> $GITHUB_ENV | |
cat release_notes.md >> $GITHUB_ENV | |
echo "EOF" >> $GITHUB_ENV | |
- name: Publish to npm | |
id: publish | |
run: npm publish --ignore-scripts | |
- name: Create GitHub Release | |
if: ${{ steps.publish.outcome == 'success' }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
gh release create "$current_tag" -F release_notes.md -t "Release $current_tag" | |
- 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 }}>\n\n*Release Notes:*\n```${{ env.release_notes }}```" | |
} | |
} | |
] | |
} | |
env: | |
SLACK_WEBHOOK_URL: ${{ secrets.RELEASES_PROD_SLACK_WEBHOOK_URL }} | |
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK |