diff --git a/.github/workflows/publish-svn-v2.yml b/.github/workflows/publish-svn-v2.yml index 598dc1a..4f6c9f2 100644 --- a/.github/workflows/publish-svn-v2.yml +++ b/.github/workflows/publish-svn-v2.yml @@ -126,11 +126,50 @@ jobs: github-release: needs: publish + runs-on: ubuntu-latest permissions: contents: write pull-requests: read - uses: OneSignal/sdk-shared/.github/workflows/github-release.yml@main - with: - version: ${{ needs.publish.outputs.bare_version }} - secrets: - GH_PUSH_TOKEN: ${{ secrets.GH_PUSH_TOKEN }} + steps: + - name: Create GitHub Release + uses: actions/github-script@v9 + env: + TAG: ${{ github.ref_name }} + VERSION: ${{ needs.publish.outputs.bare_version }} + with: + github-token: ${{ secrets.GH_PUSH_TOKEN || github.token }} + script: | + // Tags are v-prefixed (e.g. v2.4.6); releases are titled with the bare version (e.g. 2.4.6). + const tag = process.env.TAG; + const version = process.env.VERSION; + const { owner, repo } = context.repo; + + try { + await github.rest.repos.getReleaseByTag({ owner, repo, tag }); + core.info(`Release for ${tag} already exists; skipping.`); + return; + } catch (e) { + if (e.status !== 404) throw e; + } + + // The tagged commit is the merge commit of the "Release " PR; look it up by + // SHA so this is immune to title prefix collisions (2.4.1 vs 2.4.10) and pagination. + const { data: prs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ + owner, repo, commit_sha: context.sha, + }); + const releasePr = + prs.find(pr => pr.merged_at && pr.title.replace(/^chore:\s*/i, '') === `Release ${version}`) || + prs.find(pr => pr.merged_at); + if (!releasePr) { + core.warning(`No merged release PR found for ${tag}; publishing release with empty notes.`); + } + const body = releasePr && releasePr.body ? releasePr.body.split('