Release #12
This file contains hidden or 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: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: 'Version bump type' | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| overview: | |
| description: 'Release overview (will be placed at top of notes)' | |
| required: true | |
| jobs: | |
| release: | |
| name: Create tag and release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| steps: | |
| - name: Checkout target branch | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.ref_name }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: '20' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Push version bump and tag | |
| id: version | |
| env: | |
| BUMP: ${{ github.event.inputs.bump }} | |
| REF_NAME: ${{ github.ref_name }} | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| npm version $BUMP --no-git-tag-version | |
| version=$(jq -r .version package.json) | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| sed -i "s/^export const BitpayPluginInfo = .*$/export const BitpayPluginInfo = 'BitPay_NodeJs_Client_v$version';/" src/Env.ts | |
| git add package.json package-lock.json src/Env.ts | |
| git commit -m "Bump version to $version" | |
| git tag $version | |
| git push origin $REF_NAME | |
| git push origin $version | |
| - name: Get merged PR titles and format release notes | |
| id: changelog | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| REF_NAME: ${{ github.ref_name }} | |
| OVERVIEW: ${{ github.event.inputs.overview }} | |
| REPOSITORY: ${{ github.repository }} | |
| run: | | |
| git fetch --tags | |
| tags=($(git tag --sort=-creatordate)) | |
| new_tag="${tags[0]}" | |
| prev_tag="${tags[1]}" | |
| if [ -z "$prev_tag" ]; then | |
| changelog="" | |
| else | |
| changelog="**Full Changelog**: https://github.com/$REPOSITORY/compare/$prev_tag...$new_tag" | |
| fi | |
| prs=$(gh pr list --state merged --base "$REF_NAME" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]') | |
| joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /') | |
| echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV | |
| echo "$OVERVIEW" >> $GITHUB_ENV | |
| echo "" >> $GITHUB_ENV | |
| echo "## What's Changed" >> $GITHUB_ENV | |
| echo "$joined" >> $GITHUB_ENV | |
| echo "" >> $GITHUB_ENV | |
| echo "$changelog" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Create GitHub release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ steps.version.outputs.version }} | |
| RELEASE_NOTES: ${{ env.RELEASE_NOTES }} | |
| run: | | |
| gh release create "$VERSION" \ | |
| --title "$VERSION" \ | |
| --notes "$RELEASE_NOTES" | |
| readme-changelog: | |
| name: Publish changelog to Readme | |
| needs: release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v6 | |
| - name: Extract release data | |
| id: release_data | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| VERSION: ${{ needs.release.outputs.version }} | |
| run: | | |
| echo "title=$VERSION" >> $GITHUB_OUTPUT | |
| body=$(gh release view $VERSION --json body --jq .body) | |
| body_escaped=$(echo "$body" \ | |
| | sed 's/&/\&/g' \ | |
| | sed 's/</\</g' \ | |
| | sed 's/>/\>/g' \ | |
| | sed 's/{/\{/g' \ | |
| | sed 's/}/\}/g') | |
| { | |
| echo "body<<EOF" | |
| echo "$body_escaped" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Publish changelog to Readme | |
| env: | |
| README_API_KEY: ${{ secrets.README_API_KEY }} | |
| RELEASE_TITLE: ${{ steps.release_data.outputs.title }} | |
| RELEASE_BODY: ${{ steps.release_data.outputs.body }} | |
| run: | | |
| jq -n --arg title "Node.js Unified SDK v$RELEASE_TITLE" \ | |
| --arg body "$RELEASE_BODY" \ | |
| '{ | |
| title: $title, | |
| content: { | |
| body: $body | |
| }, | |
| privacy: { view: "public" } | |
| }' > payload.json | |
| curl --location 'https://api.readme.com/v2/changelogs' \ | |
| --header "Authorization: Bearer $README_API_KEY" \ | |
| --header 'Content-Type: application/json' \ | |
| --data @payload.json |