From 82b1efcec3c4b9d5474bb2d242fc4f34dbf2d66f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Ba=CC=88chler?= Date: Tue, 31 Mar 2026 21:13:05 +0200 Subject: [PATCH] ci: Update github jobs to create a Github release entry --- .github/workflows/publish.yml | 20 ++------------------ .github/workflows/release.yml | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 5e7ac2a..361fa39 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,12 +1,6 @@ name: Publish Package on: - workflow_run: - workflows: - - "Manual release" - types: - - completed - # optionally also respond to manual release events (fallback) release: types: [published] @@ -16,10 +10,7 @@ permissions: jobs: publish: - # Only run when the release workflow completed successfully and produced a tag starting with "v" - if: >- - ${{ (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success') || - (github.event_name == 'release' && startsWith(github.event.release.tag_name, 'v')) }} + if: startsWith(github.event.release.tag_name, 'v') runs-on: ubuntu-latest steps: @@ -30,14 +21,7 @@ jobs: - name: Resolve tag to publish id: tag run: | - # Prefer the release tag if available; otherwise try to read from workflow_run head_branch/ref - if [ "${{ github.event_name }}" = "release" ]; then - echo "tag=${{ github.event.release.tag_name }}" >>"$GITHUB_OUTPUT" - else - # for a workflow_run we can try to use the ref from the completed run (head_branch/head_sha) - # adjust logic here to extract the correct tag if your release.yml sets outputs or artifacts - echo "tag=${GITHUB_REF#refs/tags/}" >>"$GITHUB_OUTPUT" || true - fi + echo "tag=${{ github.event.release.tag_name }}" >>"$GITHUB_OUTPUT" - name: Setup Node.js uses: actions/setup-node@v6 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2164ae0..3af6262 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,7 +7,7 @@ permissions: jobs: release: - name: Run commit-and-tag-version and push to main + name: Run commit-and-tag-version, push to main, and create GitHub release if: github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: @@ -44,4 +44,33 @@ jobs: # After the tool creates the new version commit and tag locally, push commit and tags to main. # Ensure we push HEAD to main in case the workflow is running from a different ref. echo "Pushing commit and tags to main..." - git push origin HEAD:main --follow-tags \ No newline at end of file + git push origin HEAD:main --follow-tags + + - name: Resolve release tag and notes + id: release + run: | + tag="v$(node -p "JSON.parse(require('fs').readFileSync('package.json', 'utf8')).version")" + version="${tag#v}" + + awk -v version="$version" ' + $0 ~ "^## \\[" version "\\]" { in_section=1; next } + in_section && $0 ~ "^## \\[" { exit } + in_section { print } + ' CHANGELOG.md > RELEASE_NOTES.md + + if [ ! -s RELEASE_NOTES.md ]; then + printf 'Release %s\n' "$tag" > RELEASE_NOTES.md + fi + + echo "tag=$tag" >>"$GITHUB_OUTPUT" + + - name: Create or update GitHub release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + TAG: ${{ steps.release.outputs.tag }} + run: | + if gh release view "$TAG" >/dev/null 2>&1; then + gh release edit "$TAG" --title "$TAG" --notes-file RELEASE_NOTES.md + else + gh release create "$TAG" --title "$TAG" --notes-file RELEASE_NOTES.md + fi