-
Notifications
You must be signed in to change notification settings - Fork 115
Enforce backport label #3423
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
Merged
Enforce backport label #3423
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
defefcc
Enforce backport label
pquentin 408e177
Fix bash syntax
pquentin cd89354
Fix another shell syntax issue
pquentin 8200ad5
Display current labels
pquentin d0714f5
More debug
pquentin d5f08bc
Fix syntax
pquentin d9b0448
More debug
pquentin 505af1e
Improve
flobernd 4f3b64b
Update .github/workflows/check-backport-labels.yml
flobernd b4663c4
Update .github/workflows/check-backport-labels.yml
flobernd 0ef5e0c
Update .github/workflows/check-backport-labels.yml
flobernd e728242
Update .github/workflows/check-backport-labels.yml
flobernd 1fce9c1
Update .github/workflows/check-backport-labels.yml
flobernd cccb08a
Update .github/workflows/check-backport-labels.yml
flobernd 3fb671e
Do not allow standalone floating backport labels
flobernd 4dc5960
Update .github/workflows/check-backport-labels.yml
flobernd 956b106
Fix logic
flobernd 2b35871
Fix logic 2
flobernd dd92a26
Update .github/workflows/check-backport-labels.yml
flobernd 1956876
Simplify code
flobernd cb13658
Skip label should not be used in combination with other backport labels
flobernd 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,133 @@ | ||
| name: Check | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| types: [labeled, unlabeled, opened, reopened, synchronize] | ||
|
|
||
| permissions: | ||
| pull-requests: "read" | ||
|
|
||
| jobs: | ||
| check-backport-label: | ||
| name: backport label | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: "Check backport label" | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| run: | | ||
| json_pr_labels='${{ toJSON(github.event.pull_request.labels) }}' | ||
| readarray -t pr_labels < <(echo "${json_pr_labels}" | jq -r -c '.[].name') | ||
|
|
||
| json_all_labels="$(gh label list --repo ${{ github.repository }} --json name --search "backport" --limit 1000)" | ||
| readarray -t all_labels < <(echo "${json_all_labels}" | jq -r -c '.[].name') | ||
|
|
||
| declare -A all_backport_labels=() | ||
| declare -A all_floating_majors=() | ||
|
|
||
| backport_regex="^backport ([0-9])+\.([0-9]+|x)$" | ||
|
|
||
| echo "::group::Available Labels" | ||
| echo "skip-backport" | ||
|
|
||
| for label in "${all_labels[@]}"; do | ||
| if [[ "${label}" =~ ${backport_regex} ]]; then | ||
| major="${BASH_REMATCH[1]}" | ||
flobernd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| minor="${BASH_REMATCH[2]}" | ||
| all_backport_labels["${label}"]=1 | ||
| echo "${label}" | ||
|
|
||
| if [ "${minor}" = "x" ]; then | ||
| all_floating_majors["${major}"]=1 | ||
| fi | ||
| fi | ||
| done | ||
|
|
||
| echo "::endgroup::" | ||
|
|
||
| has_skip_backport_label=false | ||
| has_exact_backport_label=false | ||
| declare -A pr_exact_majors=() | ||
| declare -A pr_floating_majors=() | ||
|
|
||
| echo "::group::Detected Labels" | ||
|
|
||
| for pr_label in "${pr_labels[@]}"; do | ||
| if [ "${pr_label}" = "skip-backport" ]; then | ||
| has_skip_backport_label=true | ||
| echo "${pr_label}" | ||
| continue | ||
| fi | ||
|
|
||
| if [ -z "${all_backport_labels[${pr_label}]}" ]; then | ||
| continue | ||
| fi | ||
|
|
||
| if [[ "${pr_label}" =~ ${backport_regex} ]]; then | ||
| major="${BASH_REMATCH[1]}" | ||
| minor="${BASH_REMATCH[2]}" | ||
| if [ "${minor}" != "x" ]; then | ||
| pr_exact_majors["${major}"]=1 | ||
| has_exact_backport_label=true | ||
| else | ||
| pr_floating_majors["${major}"]=1 | ||
| fi | ||
| fi | ||
|
|
||
| echo "${pr_label}" | ||
| done | ||
|
|
||
| echo "::endgroup::" | ||
|
|
||
| if [ "${has_skip_backport_label}" = true ] && [ "${has_exact_backport_label}" = true ]; then | ||
| echo "::error::The 'skip-backport' not be used in combination with another backport"\ | ||
| "label." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [ "${has_skip_backport_label}" != true ] && [ "${has_exact_backport_label}" != true ]; then | ||
| echo "::error::No exact backport label found. Please add at least one of the"\ | ||
| "'backport {major}.{minor}' labels or use 'skip-backport',"\ | ||
| "if this PR should not be backported." | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Validate that a floating backport label exists for each exact backport label major | ||
| # version. | ||
|
|
||
| has_required_floating_labels=true | ||
|
|
||
| for pr_major in "${!pr_exact_majors[@]}"; do | ||
| if [ -z "${all_floating_majors[${pr_major}]}" ]; then | ||
| # There is no floating version branch for the given major version. | ||
| continue | ||
| fi | ||
|
|
||
| if [ -z "${pr_floating_majors[${pr_major}]}" ]; then | ||
| has_required_floating_labels=false | ||
| echo "::error::Missing floating backport label for '${pr_major}.x'" | ||
| fi | ||
| done | ||
|
|
||
| if [ "${has_required_floating_labels}" != true ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Validate that an exact backport label exists for each floating backport label major | ||
| # version. | ||
|
|
||
| has_required_exact_labels=true | ||
|
|
||
| for pr_floating_major in "${!pr_floating_majors[@]}"; do | ||
| if [ -z "${pr_exact_majors[${pr_floating_major}]}" ]; then | ||
| has_required_exact_labels=false | ||
| echo "::error::Missing exact backport label for '${pr_floating_major}.x'" | ||
| fi | ||
| done | ||
|
|
||
| if [ "${has_required_exact_labels}" != true ]; then | ||
| exit 1 | ||
| fi | ||
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.