From bd8a3cee96beced80a7547044c73765d76426942 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Thu, 14 Aug 2025 13:44:52 +0100 Subject: [PATCH] Refactor `prepare` job into a reusable workflow --- .github/workflows/prepare-release.yml | 73 +++++++++++++++++++++ .github/workflows/update-release-branch.yml | 39 +---------- 2 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 .github/workflows/prepare-release.yml diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 000000000..7678870cc --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,73 @@ +name: Prepare release +on: + workflow_call: + outputs: + version: + description: "The version that is being released." + value: ${{ jobs.prepare.outputs.version }} + major_version: + description: "The major version of the release." + value: ${{ jobs.prepare.outputs.major_version }} + latest_tag: + description: "The most recent, existing release tag." + value: ${{ jobs.prepare.outputs.latest_tag }} + backport_source_branch: + description: "The release branch for the given tag." + value: ${{ jobs.prepare.outputs.backport_source_branch }} + backport_target_branches: + description: "JSON encoded list of branches to target with backports." + value: ${{ jobs.prepare.outputs.backport_target_branches }} + + push: + paths: + - .github/workflows/prepare-release.yml + +jobs: + prepare: + name: "Prepare release" + runs-on: ubuntu-latest + if: github.repository == 'github/codeql-action' + + permissions: + contents: read + + outputs: + version: ${{ steps.versions.outputs.version }} + major_version: ${{ steps.versions.outputs.major_version }} + latest_tag: ${{ steps.versions.outputs.latest_tag }} + backport_source_branch: ${{ steps.branches.outputs.backport_source_branch }} + backport_target_branches: ${{ steps.branches.outputs.backport_target_branches }} + + steps: + - name: Checkout repository + uses: actions/checkout@v5 + with: + fetch-depth: 0 # Need full history for calculation of diffs + + - name: Configure runner for release + uses: ./.github/actions/release-initialise + + - name: Get version tags + id: versions + run: | + VERSION="v$(jq '.version' -r 'package.json')" + echo "version=${VERSION}" >> $GITHUB_OUTPUT + MAJOR_VERSION=$(cut -d '.' -f1 <<< "${VERSION}") + echo "major_version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT + LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1) + echo "latest_tag=${LATEST_TAG}" >> $GITHUB_OUTPUT + + - name: Determine older release branches + id: branches + uses: ./.github/actions/release-branches + with: + major_version: ${{ steps.versions.outputs.major_version }} + latest_tag: ${{ steps.versions.outputs.latest_tag }} + + - name: Print release information + run: | + echo 'version: ${{ steps.versions.outputs.version }}' + echo 'major_version: ${{ steps.versions.outputs.major_version }}' + echo 'latest_tag: ${{ steps.versions.outputs.latest_tag }}' + echo 'backport_source_branch: ${{ steps.branches.outputs.backport_source_branch }}' + echo 'backport_target_branches: ${{ steps.branches.outputs.backport_target_branches }}' diff --git a/.github/workflows/update-release-branch.yml b/.github/workflows/update-release-branch.yml index 9dfeeb536..463ffaf7b 100644 --- a/.github/workflows/update-release-branch.yml +++ b/.github/workflows/update-release-branch.yml @@ -14,46 +14,11 @@ on: jobs: prepare: - runs-on: ubuntu-latest - if: github.repository == 'github/codeql-action' - outputs: - version: ${{ steps.versions.outputs.version }} - major_version: ${{ steps.versions.outputs.major_version }} - latest_tag: ${{ steps.versions.outputs.latest_tag }} - backport_source_branch: ${{ steps.branches.outputs.backport_source_branch }} - backport_target_branches: ${{ steps.branches.outputs.backport_target_branches }} + name: "Prepare release" permissions: contents: read - steps: - - uses: actions/checkout@v5 - with: - fetch-depth: 0 # Need full history for calculation of diffs - - uses: ./.github/actions/release-initialise - - name: Get version tags - id: versions - run: | - VERSION="v$(jq '.version' -r 'package.json')" - echo "version=${VERSION}" >> $GITHUB_OUTPUT - MAJOR_VERSION=$(cut -d '.' -f1 <<< "${VERSION}") - echo "major_version=${MAJOR_VERSION}" >> $GITHUB_OUTPUT - LATEST_TAG=$(git tag --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+' | head -1) - echo "latest_tag=${LATEST_TAG}" >> $GITHUB_OUTPUT - - - id: branches - name: Determine older release branches - uses: ./.github/actions/release-branches - with: - major_version: ${{ steps.versions.outputs.major_version }} - latest_tag: ${{ steps.versions.outputs.latest_tag }} - - - name: debug logging - run: | - echo 'version: ${{ steps.versions.outputs.version }}' - echo 'major_version: ${{ steps.versions.outputs.major_version }}' - echo 'latest_tag: ${{ steps.versions.outputs.latest_tag }}' - echo 'backport_source_branch: ${{ steps.branches.outputs.backport_source_branch }}' - echo 'backport_target_branches: ${{ steps.branches.outputs.backport_target_branches }}' + uses: .github/workflows/prepare-release.yml update: timeout-minutes: 45