|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - '[0-9]+.[0-9]+.[0-9]+' # Matches x.y.z version tags |
| 7 | + |
| 8 | +jobs: |
| 9 | + release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout code |
| 13 | + uses: actions/checkout@v5 |
| 14 | + |
| 15 | + - name: Extract version from tag |
| 16 | + id: version |
| 17 | + run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT |
| 18 | + |
| 19 | + - name: Extract release notes from CHANGELOG.md |
| 20 | + id: release_notes |
| 21 | + run: | |
| 22 | + # Find the section for this version in CHANGELOG.md |
| 23 | + VERSION="${{ steps.version.outputs.version }}" |
| 24 | + # Look for the version heading (## [x.y.z] or ## x.y.z) |
| 25 | + SECTION_START=$(grep -n "^## \[$VERSION\]\|^## $VERSION" CHANGELOG.md | head -1 | cut -d: -f1) |
| 26 | +
|
| 27 | + if [ -z "$SECTION_START" ]; then |
| 28 | + echo "Could not find version $VERSION in CHANGELOG.md" |
| 29 | + echo "release_notes=Release for version $VERSION" >> $GITHUB_OUTPUT |
| 30 | + else |
| 31 | + # Find the next version section or end of file |
| 32 | + NEXT_SECTION=$(tail -n +$((SECTION_START + 1)) CHANGELOG.md | grep -n "^## " | head -1 | cut -d: -f1) |
| 33 | +
|
| 34 | + if [ -z "$NEXT_SECTION" ]; then |
| 35 | + # No next section, read to end of file, but skip the first line (version header) |
| 36 | + # Write directly to temp file to avoid shell interpretation of backticks |
| 37 | + tail -n +$((SECTION_START + 1)) CHANGELOG.md > /tmp/release_notes_temp.txt |
| 38 | + else |
| 39 | + # Read until next section, but skip the first line (version header) |
| 40 | + # Write directly to temp file to avoid shell interpretation of backticks |
| 41 | + tail -n +$((SECTION_START + 1)) CHANGELOG.md | head -n $((NEXT_SECTION - 2)) > /tmp/release_notes_temp.txt |
| 42 | + fi |
| 43 | +
|
| 44 | + # Clean up the notes (remove empty lines at start/end) directly in the file |
| 45 | + sed -i '/^$/d' /tmp/release_notes_temp.txt |
| 46 | + sed -i -e :a -e '/^\n*$/{$d;N;ba' -e '}' /tmp/release_notes_temp.txt |
| 47 | +
|
| 48 | + # Use base64 encoding to safely pass the content through GitHub Actions |
| 49 | + RELEASE_NOTES_B64=$(base64 -w 0 < /tmp/release_notes_temp.txt) |
| 50 | + echo "release_notes_b64=$RELEASE_NOTES_B64" >> $GITHUB_OUTPUT |
| 51 | + fi |
| 52 | +
|
| 53 | + - name: Create Release |
| 54 | + run: | |
| 55 | + # Decode the base64-encoded release notes |
| 56 | + echo "${{ steps.release_notes.outputs.release_notes_b64 }}" | base64 -d > release_notes.txt |
| 57 | + gh release create ${{ steps.version.outputs.version }} \ |
| 58 | + --title "${{ steps.version.outputs.version }}" \ |
| 59 | + --notes-file release_notes.txt \ |
| 60 | + --repo ${{ github.repository }} |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments