From 590f14a6140f2ff757ad8e3dc781c38775479d9f Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Thu, 24 Apr 2025 16:19:09 +0200 Subject: [PATCH] =?UTF-8?q?[ci]=20Create=20long=E2=80=91lived=20maintenanc?= =?UTF-8?q?e=20branch=20after=20release=20published?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrei Kvapil --- .github/workflows/pull-requests-release.yaml | 30 ++++++++++++++++++++ .github/workflows/tags.yaml | 26 ----------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pull-requests-release.yaml b/.github/workflows/pull-requests-release.yaml index 8a863ea9..bc955f55 100644 --- a/.github/workflows/pull-requests-release.yaml +++ b/.github/workflows/pull-requests-release.yaml @@ -76,6 +76,36 @@ jobs: git tag -f ${{ steps.get_tag.outputs.tag }} ${{ github.sha }} git push -f origin ${{ steps.get_tag.outputs.tag }} + # Ensure maintenance branch release-X.Y + - name: Ensure maintenance branch release-X.Y + uses: actions/github-script@v7 + with: + script: | + const tag = '${{ steps.get_tag.outputs.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}`; + try { + await github.rest.repos.getBranch({ + owner: context.repo.owner, + repo: context.repo.repo, + branch + }); + console.log(`Branch '${branch}' already exists`); + } catch (_) { + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/heads/${branch}`, + sha: context.sha + }); + console.log(`✅ Branch '${branch}' created at ${context.sha}`); + } + # Get the latest published release - name: Get the latest published release id: latest_release diff --git a/.github/workflows/tags.yaml b/.github/workflows/tags.yaml index 5cc32c42..34e13a76 100644 --- a/.github/workflows/tags.yaml +++ b/.github/workflows/tags.yaml @@ -178,32 +178,6 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # Ensure long‑lived maintenance branch release‑X.Y - - name: Ensure maintenance branch release‑${{ steps.tag.outputs.line }} - if: | - steps.check_release.outputs.skip == 'false' && - steps.get_base.outputs.branch == 'main' - uses: actions/github-script@v7 - with: - script: | - const branch = `release-${'${{ steps.tag.outputs.line }}'}`; - try { - await github.rest.repos.getBranch({ - owner: context.repo.owner, - repo: context.repo.repo, - branch - }); - console.log(`Branch '${branch}' already exists`); - } catch (_) { - await github.rest.git.createRef({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `refs/heads/${branch}`, - sha: context.sha - }); - console.log(`Branch '${branch}' created at ${context.sha}`); - } - # Create release‑X.Y.Z branch and push (force‑update) - name: Create release branch if: steps.check_release.outputs.skip == 'false'