diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..9b1efd59 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,43 @@ +name: Release + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Extract version from tag + id: version + run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT + + - name: Extract changelog section + id: changelog + run: | + VERSION="${{ steps.version.outputs.VERSION }}" + awk -v ver="$VERSION" ' + /^## \[/ { + if (found) exit + if ($0 ~ "\\[" ver "\\]") found=1 + } + found {print} + ' CHANGELOG.md > release_notes.md + + if [ ! -s release_notes.md ]; then + echo "## v$VERSION" > release_notes.md + echo "" >> release_notes.md + echo "See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details." >> release_notes.md + fi + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + body_path: release_notes.md