diff --git a/.github/workflows/pull-requests-release-manual.yaml b/.github/workflows/pull-requests-release-manual.yaml new file mode 100644 index 00000000..13f23676 --- /dev/null +++ b/.github/workflows/pull-requests-release-manual.yaml @@ -0,0 +1,84 @@ +name: Manual Release + +on: + workflow_dispatch: + inputs: + tag: + description: 'Release tag (e.g. v0.1.3 or v0.1.3-rc1)' + required: true + type: string + +jobs: + finalize: + name: Finalize Release + runs-on: [self-hosted] + permissions: + contents: write + + if: | + github.event_name == 'workflow_dispatch' && github.ref_name == 'main' + + steps: + - name: Checkout repo + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Create tag on merge commit + run: | + git tag -f ${{ steps.get_tag.outputs.tag }} ${{ github.sha }} + git push -f origin ${{ steps.get_tag.outputs.tag }} + + - name: Ensure maintenance branch release-X.Y + uses: actions/github-script@v7 + with: + script: | + const tag = '${{ inputs.tag }}'; // e.g. v0.1.3 or v0.1.3-rc3 + const match = tag.match(/^v(\d+)\.(\d+)\.\d+(?:[-\w\.]+)?$/); + if (!match) { + core.setFailed(`❌ tag '${tag}' must match 'vX.Y.Z' or 'vX.Y.Z-suffix'`); + return; + } + const line = `${match[1]}.${match[2]}`; + const branch = `release-${line}`; + + // Get main branch commit for the tag + const ref = await github.rest.git.getRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `tags/${tag}` + }); + + const commitSha = ref.data.object.sha; + + try { + await github.rest.repos.getBranch({ + owner: context.repo.owner, + repo: context.repo.repo, + branch + }); + + await github.rest.git.updateRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `heads/${branch}`, + sha: commitSha, + force: true + }); + console.log(`🔁 Force-updated '${branch}' to ${commitSha}`); + } catch (err) { + if (err.status === 404) { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/heads/${branch}`, + sha: commitSha + }); + console.log(`✅ Created branch '${branch}' at ${commitSha}`); + } else { + console.error('Unexpected error --', err); + core.setFailed(`Unexpected error creating/updating branch: ${err.message}`); + throw err; + } + } + diff --git a/.github/workflows/pull-requests-release.yaml b/.github/workflows/pull-requests-release.yaml index 7f7c2fcd..b4ca30d0 100644 --- a/.github/workflows/pull-requests-release.yaml +++ b/.github/workflows/pull-requests-release.yaml @@ -128,6 +128,7 @@ jobs: core.setFailed(`Unexpected error creating/updating branch: ${err.message}`); throw err; } + } # Get the latest published release - name: Get the latest published release