-
Couldn't load subscription status.
- Fork 391
feat: add manual dispatch to backport workflow #5651
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,10 +4,25 @@ on: | |
| pull_request_target: | ||
| types: [closed, labeled] | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| pr_number: | ||
| description: 'PR number to backport' | ||
| required: true | ||
| type: string | ||
| force_rerun: | ||
| description: 'Force rerun even if backports exist' | ||
| required: false | ||
| type: boolean | ||
| default: false | ||
|
|
||
| jobs: | ||
| backport: | ||
| if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'needs-backport') | ||
| if: > | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] low Priority Issue: Complex multiline conditional could be hard to maintain |
||
| (github.event_name == 'pull_request_target' && | ||
| github.event.pull_request.merged == true && | ||
| contains(github.event.pull_request.labels.*.name, 'needs-backport')) || | ||
| github.event_name == 'workflow_dispatch' | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
|
|
@@ -29,7 +44,7 @@ jobs: | |
| id: check-existing | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} | ||
| run: | | ||
| # Check for existing backport PRs for this PR number | ||
| EXISTING_BACKPORTS=$(gh pr list --state all --search "backport-${PR_NUMBER}-to" --json title,headRefName,baseRefName | jq -r '.[].headRefName') | ||
|
|
@@ -39,6 +54,13 @@ jobs: | |
| exit 0 | ||
| fi | ||
|
|
||
| # For manual triggers with force_rerun, proceed anyway | ||
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ "${{ inputs.force_rerun }}" = "true" ]; then | ||
| echo "skip=false" >> $GITHUB_OUTPUT | ||
| echo "::warning::Force rerun requested - existing backports will be updated" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Found existing backport PRs:" | ||
| echo "$EXISTING_BACKPORTS" | ||
| echo "skip=true" >> $GITHUB_OUTPUT | ||
|
|
@@ -50,8 +72,17 @@ jobs: | |
| run: | | ||
| # Extract version labels (e.g., "1.24", "1.22") | ||
| VERSIONS="" | ||
| LABELS='${{ toJSON(github.event.pull_request.labels) }}' | ||
| for label in $(echo "$LABELS" | jq -r '.[].name'); do | ||
|
|
||
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
| # For manual triggers, get labels from the PR | ||
| LABELS=$(gh pr view ${{ inputs.pr_number }} --json labels | jq -r '.labels[].name') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] medium Priority Issue: Missing GH_TOKEN environment variable in step that calls GitHub API |
||
| else | ||
| # For automatic triggers, extract from PR event | ||
| LABELS='${{ toJSON(github.event.pull_request.labels) }}' | ||
| LABELS=$(echo "$LABELS" | jq -r '.[].name') | ||
| fi | ||
|
|
||
| for label in $LABELS; do | ||
| # Match version labels like "1.24" (major.minor only) | ||
| if [[ "$label" =~ ^[0-9]+\.[0-9]+$ ]]; then | ||
| # Validate the branch exists before adding to list | ||
|
|
@@ -75,12 +106,20 @@ jobs: | |
| if: steps.check-existing.outputs.skip != 'true' | ||
| id: backport | ||
| env: | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| MERGE_COMMIT: ${{ github.event.pull_request.merge_commit_sha }} | ||
| PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} | ||
| run: | | ||
| FAILED="" | ||
| SUCCESS="" | ||
|
|
||
| # Get PR data for manual triggers | ||
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
| PR_DATA=$(gh pr view ${{ inputs.pr_number }} --json title,mergeCommit) | ||
| PR_TITLE=$(echo "$PR_DATA" | jq -r '.title') | ||
| MERGE_COMMIT=$(echo "$PR_DATA" | jq -r '.mergeCommit.oid') | ||
| else | ||
| PR_TITLE="${{ github.event.pull_request.title }}" | ||
| MERGE_COMMIT="${{ github.event.pull_request.merge_commit_sha }}" | ||
| fi | ||
|
|
||
| for version in ${{ steps.versions.outputs.versions }}; do | ||
| echo "::group::Backporting to core/${version}" | ||
|
|
@@ -133,10 +172,18 @@ jobs: | |
| if: steps.check-existing.outputs.skip != 'true' && steps.backport.outputs.success | ||
| env: | ||
| GH_TOKEN: ${{ secrets.PR_GH_TOKEN }} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] medium Priority Issue: Inconsistent GitHub token usage between steps |
||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| PR_AUTHOR: ${{ github.event.pull_request.user.login }} | ||
| PR_NUMBER: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number || github.event.pull_request.number }} | ||
| run: | | ||
| # Get PR data for manual triggers | ||
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
| PR_DATA=$(gh pr view ${{ inputs.pr_number }} --json title,author) | ||
| PR_TITLE=$(echo "$PR_DATA" | jq -r '.title') | ||
| PR_AUTHOR=$(echo "$PR_DATA" | jq -r '.author.login') | ||
| else | ||
| PR_TITLE="${{ github.event.pull_request.title }}" | ||
| PR_AUTHOR="${{ github.event.pull_request.user.login }}" | ||
| fi | ||
|
|
||
| for backport in ${{ steps.backport.outputs.success }}; do | ||
| IFS=':' read -r version branch <<< "${backport}" | ||
|
|
||
|
|
@@ -165,9 +212,16 @@ jobs: | |
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| PR_NUMBER="${{ github.event.pull_request.number }}" | ||
| PR_AUTHOR="${{ github.event.pull_request.user.login }}" | ||
| MERGE_COMMIT="${{ github.event.pull_request.merge_commit_sha }}" | ||
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
| PR_DATA=$(gh pr view ${{ inputs.pr_number }} --json author,mergeCommit) | ||
| PR_NUMBER="${{ inputs.pr_number }}" | ||
| PR_AUTHOR=$(echo "$PR_DATA" | jq -r '.author.login') | ||
| MERGE_COMMIT=$(echo "$PR_DATA" | jq -r '.mergeCommit.oid') | ||
| else | ||
| PR_NUMBER="${{ github.event.pull_request.number }}" | ||
| PR_AUTHOR="${{ github.event.pull_request.user.login }}" | ||
| MERGE_COMMIT="${{ github.event.pull_request.merge_commit_sha }}" | ||
| fi | ||
|
|
||
| for failure in ${{ steps.backport.outputs.failed }}; do | ||
| IFS=':' read -r version reason conflicts <<< "${failure}" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[security] medium Priority
Issue: No input validation for pr_number parameter
Context: Workflow accepts pr_number as string input but doesn't validate it's a valid PR number, could cause unexpected behavior or command injection
Suggestion: Add validation to ensure pr_number is numeric and corresponds to an existing PR before using it