Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 138 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
name: Release

on:
workflow_dispatch:
inputs:
branch:
description: "Branch to release from"
required: true
default: "master"
type: string
version:
description: "Version number (e.g., 2.1.4)"
required: true
type: string
overview:
description: "Release overview (will be placed at top of notes)"
required: true
type: string

jobs:
release:
name: Create tag and release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ inputs.branch }}
fetch-depth: 0

- name: Validate version format
id: version
run: |
if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Version must be in format X.Y.Z (e.g., 9.3.3)"
exit 1
fi
version="${{ inputs.version }}"
echo "version=$version" >> $GITHUB_OUTPUT

- name: Configure Git
run: |
git config user.name "github-actions"
git config user.email "[email protected]"

- name: Create and push tag
run: |
git tag "${{ steps.version.outputs.version }}"
git push origin "${{ steps.version.outputs.version }}"

- name: Get merged PR titles and format release notes
id: changelog
run: |
git fetch --tags

# Get most recent and previous tags
tags=($(git tag --sort=-creatordate))
new_tag="${tags[0]}"
prev_tag="${tags[1]}"

if [ -z "$prev_tag" ]; then
echo "Warning: No previous tag found. Skipping full changelog link."
changelog=""
else
changelog="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$prev_tag...$new_tag"
fi

prs=$(gh pr list --state merged --base "${{ inputs.branch }}" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]')
joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /')

echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "${{ github.event.inputs.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
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Create GitHub Release
run: |
gh release create "${{ steps.version.outputs.version }}" \
--title "${{ steps.version.outputs.version }}" \
--notes "${{ env.RELEASE_NOTES }}"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

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
run: |
echo "title=${{ needs.release.outputs.version }}" >> $GITHUB_OUTPUT
body=$(gh release view ${{ needs.release.outputs.version }} --json body --jq .body)
body_escaped=$(echo "$body" \
| sed 's/&/\&#38;/g' \
| sed 's/</\&#60;/g' \
| sed 's/>/\&#62;/g' \
| sed 's/{/\&#123;/g' \
| sed 's/}/\&#125;/g')
{
echo "body<<EOF"
echo "$body_escaped"
echo "EOF"
} >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Publish changelog to Readme
env:
README_API_KEY: ${{ secrets.README_API_KEY }}
run: |
jq -n --arg title "BitPay Utils cryptography pack v${{ steps.release_data.outputs.title }}" \
--arg body "${{ steps.release_data.outputs.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