v0.2.0 bump #26
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: 02-Release-Publish | |
on: | |
push: | |
tags: | |
- "*" | |
jobs: | |
test_bundle: | |
uses: ./.github/workflows/test-bundle.yml | |
prepare: | |
runs-on: ubuntu-latest | |
outputs: | |
RELEASE_TAG: ${{ steps.taginfo.outputs.release_tag }} ## v1.2.3-xyz | |
PKG_SEMVER: ${{ steps.taginfo.outputs.pkg_semver }} ## 1.2.3 | |
IS_DRYRUN: ${{ steps.taginfo.outputs.is_dryrun }} ## yes|not | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
## Tag pattern: v1.2.3-xyz | |
## Version pattern: 1.2.3 | |
- name: Get version from Github Tag | |
id: taginfo | |
run: | | |
GITHUBREF="${{ github.ref }}" | |
RELEASETAG=${GITHUBREF##*/} | |
PKGSEMVER=$(echo "$RELEASETAG" | sed 's/\s*//g' | sed 's/^v//g' | sed 's/-.*//g') | |
echo "release_tag=$RELEASETAG" >> $GITHUB_OUTPUT | |
echo "pkg_semver=$PKGSEMVER" >> $GITHUB_OUTPUT | |
echo "Release tag: $RELEASETAG" | |
echo "Semver: $PKGSEMVER" | |
if [[ "$RELEASETAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-.*$ ]]; then | |
ISDRYRUN="yes" | |
else | |
ISDRYRUN="not" | |
fi | |
echo "Is dryrun: $ISDRYRUN" | |
echo "is_dryrun=$ISDRYRUN" >> $GITHUB_OUTPUT | |
publish_npm: | |
runs-on: ubuntu-latest | |
needs: [prepare] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup NodeJS | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18.x | |
registry-url: https://registry.npmjs.org | |
- name: Install deps & build | |
run: | | |
yarn install --frozen-lockfile | |
yarn run build | |
## Publish NPM if tag != v1.2.3-xyz (dryrun) | |
- name: Publish NPM ${{ needs.prepare.outputs.PKG_SEMVER }} | |
if: ${{ needs.prepare.outputs.IS_DRYRUN == 'not' }} | |
run: yarn publish --no-git-tag-version --new-version ${{ needs.prepare.outputs.PKG_SEMVER }} | |
env: | |
NODE_AUTH_TOKEN: ${{secrets.VOCDONI_NPM_TOKEN}} | |
publish_release: | |
runs-on: ubuntu-latest | |
needs: [prepare] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
## The CHANGELOG.md must contain the current version being published (i.e. [1.2.3])" | |
- name: Check if CHANGELOG.md is updated | |
id: checkchangelog | |
run: | | |
LINE_PATTERN_1="## \[Unreleased\]" | |
LINE_PATTERN_2="## \[${{ needs.prepare.outputs.PKG_SEMVER }}\] -" | |
##MATCHES_PATTERN=$(grep -c "$LINE_PATTERN_1\|$LINE_PATTERN_2" CHANGELOG.md) | |
MATCHES_PATTERN=$(grep -c "$LINE_PATTERN_2" CHANGELOG.md) | |
echo "matches_pattern=$MATCHES_PATTERN" >> $GITHUB_OUTPUT | |
echo "Number of matches: $MATCHES_PATTERN" ## It should be 1 | |
## Title: v1.2.3 | |
## Head text: Vocdoni SDK v1.2.3 | |
## Body: | |
## NPM: https://www.npmjs.com/package/@vocdoni/sdk/v/1.2.3 | |
## Full Changelog: https://github.com/vocdoni/vocdoni-sdk/blob/v1.2.3/CHANGELOG.md | |
- name: Compose release-notes.txt | |
run: | | |
echo "Vocdoni SDK ${{ needs.prepare.outputs.RELEASE_TAG }}" >> release-notes.txt | |
echo " " >> release-notes.txt | |
echo "* NPM: https://www.npmjs.com/package/@vocdoni/sdk/v/${{ needs.prepare.outputs.PKG_SEMVER }}" >> release-notes.txt | |
echo "* Full Changelog: https://github.com/vocdoni/vocdoni-sdk/blob/${{ needs.prepare.outputs.RELEASE_TAG }}/CHANGELOG.md" >> release-notes.txt | |
- name: Create a Github Release | |
id: setrelease | |
uses: softprops/action-gh-release@v1 | |
##if: ${{ steps.checkchangelog.outputs.matches_pattern == '1' && needs.prepare.outputs.IS_DRYRUN == 'not' }} | |
if: ${{ steps.checkchangelog.outputs.matches_pattern == '1' }} | |
with: | |
name: ${{ needs.prepare.outputs.RELEASE_TAG }} | |
body_path: release-notes.txt | |
draft: ${{ needs.prepare.outputs.IS_DRYRUN == 'yes' }} | |
prerelease: true | |
- name: Confirm Release creation | |
if: always() | |
run: | | |
if [[ "${{ steps.setrelease.outcome }}" != 'success' ]]; then | |
echo "Error: The Release ${{ needs.prepare.outputs.RELEASE_TAG }} cannot be created." >> $GITHUB_STEP_SUMMARY | |
else | |
echo "The Release ${{ needs.prepare.outputs.RELEASE_TAG }} has been created successfully." >> $GITHUB_STEP_SUMMARY | |
echo "Release URL: ${{ steps.setrelease.outputs.url }}" >> $GITHUB_STEP_SUMMARY | |
fi |