-
Notifications
You must be signed in to change notification settings - Fork 124
ci: support release label backport workflows #4598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Yicong-Huang
merged 29 commits into
apache:main
from
Yicong-Huang:feat/direct-backport-release-labels-v2
May 1, 2026
Merged
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
d9ed771
ci: add release label backport workflows
Yicong-Huang 5568cc2
ci: harden backport workflow portability
github-actions[bot] 234f7e9
ci: preserve existing build check names
github-actions[bot] 4b64702
ci: dispatch backport CI from build workflow
Yicong-Huang f81edc8
ci: route build vs backport via precheck job
Yicong-Huang 2175cae
ci: split backport CI into standalone workflow
Yicong-Huang a705870
ci: shorten backport check names
Yicong-Huang 91aab8c
ci: shorten backport check display names
Yicong-Huang 565e67b
ci: identify backport runs by workflow run, not check name
Yicong-Huang 06e2b65
ci: re-run backport CI on PR sync events
Yicong-Huang 13ce4b6
ci: rename detect job to precheck
Yicong-Huang 2d0cc5b
ci: gate main build jobs on a precheck routing job
Yicong-Huang b25cb9b
ci: clean up stale Backport runs on unlabeled events
Yicong-Huang 843265a
ci: rename create-backport-pr.yml to direct-backport-push.yml
Yicong-Huang f7e0568
ci: merge backport CI into the Build workflow
Yicong-Huang d02693e
ci: drop has_backport_targets, gate on JSON string instead
Yicong-Huang d18971a
ci: clean up build/backport job naming
Yicong-Huang 1fd1de7
ci: remove summary job from reusable-build
Yicong-Huang bc560eb
ci: drop explicit name on backport matrix jobs
Yicong-Huang 770b548
ci: split backport cleanup into its own workflow on unlabeled
Yicong-Huang 82c8704
ci: pin frontend display name to 18 for ASF YAML parity
Yicong-Huang 7989b89
ci: re-run full Build on labeled and unlabeled events
Yicong-Huang 18a0558
ci: clean up obsolete backport checks on unlabeled
Yicong-Huang 6a5e1aa
Merge branch 'main' into feat/direct-backport-release-labels-v2
Yicong-Huang 3d96cc7
Merge branch 'main' into feat/direct-backport-release-labels-v2
Yicong-Huang 28099c4
ci: squash the PR range before cherry-picking onto release
Yicong-Huang c557153
ci: use the PR title and description for backport commit message
Yicong-Huang becbc2c
ci: revert unrelated formatting drift and tighten CONTRIBUTING
Yicong-Huang 8e600fd
ci: address PR review comments on github-action-build.yml
Yicong-Huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| target_branch="${1:?target branch is required}" | ||
| commit_range="${2:?commit range is required}" | ||
| workspace_branch="ci-backport-${target_branch//\//-}" | ||
|
|
||
| git fetch --no-tags origin "${target_branch}" | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| if [[ "${commit_range}" != *..* ]]; then | ||
| echo "Invalid commit range: ${commit_range}" >&2 | ||
| exit 1 | ||
| fi | ||
| start_sha="${commit_range%..*}" | ||
| end_sha="${commit_range##*..}" | ||
|
|
||
| if [[ -z "$(git rev-list -n 1 "${commit_range}")" ]]; then | ||
| echo "No commits found in range ${commit_range}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Build a single squash commit whose parent is the range start and whose tree | ||
| # matches the range end. Cherry-picking this squash onto the release branch | ||
| # applies the cumulative diff in one 3-way merge, which avoids spurious | ||
| # conflicts when intermediate commits in the range happen to overlap with | ||
| # changes already present (under different SHAs) on the release branch. | ||
| end_tree="$(git rev-parse "${end_sha}^{tree}")" | ||
| squash_sha="$(git commit-tree -p "${start_sha}" -m "ci: squashed backport of ${commit_range}" "${end_tree}")" | ||
|
|
||
| git checkout -B "${workspace_branch}" "origin/${target_branch}" | ||
| git cherry-pick -x "${squash_sha}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| name: Direct Backport Push | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| actions: read | ||
| contents: write | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| discover: | ||
| name: Discover direct backport targets | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| pr_number: ${{ steps.discover.outputs.pr_number }} | ||
| targets: ${{ steps.discover.outputs.targets }} | ||
| has_targets: ${{ steps.discover.outputs.has_targets }} | ||
| steps: | ||
| - name: Resolve merged PR and green targets | ||
| id: discover | ||
| uses: actions/github-script@v8 | ||
| with: | ||
| script: | | ||
| const sha = context.sha; | ||
| const { owner, repo } = context.repo; | ||
|
|
||
| const response = await github.request( | ||
| "GET /repos/{owner}/{repo}/commits/{commit_sha}/pulls", | ||
| { | ||
| owner, | ||
| repo, | ||
| commit_sha: sha, | ||
| } | ||
| ); | ||
|
|
||
| const pullRequest = response.data.find((pr) => pr.merge_commit_sha === sha) ?? response.data[0]; | ||
| if (!pullRequest) { | ||
| core.info(`No merged pull request is associated with ${sha}.`); | ||
| core.setOutput("pr_number", ""); | ||
| core.setOutput("targets", "[]"); | ||
| core.setOutput("has_targets", "false"); | ||
| return; | ||
| } | ||
|
|
||
| const requestedTargets = [...new Set( | ||
| pullRequest.labels | ||
| .map((label) => label.name) | ||
| .filter((name) => /^release\/.+$/.test(name)) | ||
| )].sort(); | ||
|
|
||
| if (requestedTargets.length === 0) { | ||
| core.info(`PR #${pullRequest.number} does not request any backports.`); | ||
| core.setOutput("pr_number", String(pullRequest.number)); | ||
| core.setOutput("targets", "[]"); | ||
| core.setOutput("has_targets", "false"); | ||
| return; | ||
| } | ||
|
|
||
| const buildRuns = await github.paginate( | ||
| github.rest.actions.listWorkflowRuns, | ||
| { | ||
| owner, | ||
| repo, | ||
| workflow_id: "github-action-build.yml", | ||
| head_sha: pullRequest.head.sha, | ||
| per_page: 100, | ||
| } | ||
| ); | ||
|
|
||
| let greenTargets = []; | ||
| if (buildRuns.length === 0) { | ||
| core.warning(`No Build workflow runs found for ${pullRequest.head.sha}.`); | ||
| } else { | ||
| const allJobs = []; | ||
| for (const run of buildRuns) { | ||
| const jobs = await github.paginate( | ||
| github.rest.actions.listJobsForWorkflowRun, | ||
| { | ||
| owner, | ||
| repo, | ||
| run_id: run.id, | ||
| per_page: 100, | ||
| } | ||
| ); | ||
| allJobs.push(...jobs); | ||
| } | ||
|
|
||
| greenTargets = requestedTargets.filter((target) => { | ||
| const prefix = `backport (${target}) / `; | ||
| const targetJobs = allJobs.filter((job) => job.name.startsWith(prefix)); | ||
| return targetJobs.length > 0 && targetJobs.every((job) => job.conclusion === "success"); | ||
| }); | ||
| } | ||
|
|
||
| const skippedTargets = requestedTargets.filter((target) => !greenTargets.includes(target)); | ||
| if (skippedTargets.length > 0) { | ||
| core.warning(`Skipping targets without a successful Backport run: ${skippedTargets.join(", ")}`); | ||
| } | ||
|
|
||
| core.setOutput("pr_number", String(pullRequest.number)); | ||
| core.setOutput("targets", JSON.stringify(greenTargets)); | ||
| core.setOutput("has_targets", greenTargets.length > 0 ? "true" : "false"); | ||
|
|
||
| push-backports: | ||
| needs: discover | ||
| if: ${{ needs.discover.outputs.has_targets == 'true' }} | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| target: ${{ fromJson(needs.discover.outputs.targets) }} | ||
| steps: | ||
| - name: Checkout main | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Cherry-pick merge commit onto target branch | ||
| env: | ||
| MERGE_SHA: ${{ github.sha }} | ||
| TARGET_BRANCH: ${{ matrix.target }} | ||
| PR_NUMBER: ${{ needs.discover.outputs.pr_number }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| parent_count=$(git rev-list --parents -n 1 "${MERGE_SHA}" | awk '{print NF-1}') | ||
| if [[ "${parent_count}" -ne 1 ]]; then | ||
| echo "Direct backport expects a squash-merged commit on main. ${MERGE_SHA} has ${parent_count} parents." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| pr_title=$(gh pr view "${PR_NUMBER}" --json title --jq .title) | ||
| pr_body=$(gh pr view "${PR_NUMBER}" --json body --jq .body) | ||
|
|
||
| git fetch --no-tags origin "${TARGET_BRANCH}" | ||
| git checkout -B "${TARGET_BRANCH}" "origin/${TARGET_BRANCH}" | ||
| git cherry-pick --no-commit "${MERGE_SHA}" | ||
|
|
||
| { | ||
| printf '%s (#%s)\n\n' "${pr_title}" "${PR_NUMBER}" | ||
| if [[ -n "${pr_body}" ]]; then | ||
| printf '%s\n\n' "${pr_body}" | ||
| fi | ||
| printf '(cherry picked from commit %s)\n' "${MERGE_SHA}" | ||
| } | git commit -F - | ||
|
|
||
| git push origin "HEAD:${TARGET_BRANCH}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.