Enforce backport label #13
Workflow file for this run
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
| name: Check | |
| on: | |
| pull_request: | |
| 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 --json name --search "backport" --limit 1000)" | |
| readarray -t all_labels < <(echo "${json_all_labels}" | jq -r -c '.[].name') | |
| all_backport_labels=() | |
| floating_majors=() | |
| backport_regex="^backport ([0-9])+\.([0-9]+|x)$" | |
| echo "::group::Available Labels" | |
| for label in "${all_labels[@]}"; do | |
| if [ "${label}" = "skip-backport" ]; then | |
| all_backport_labels+=("${label}") | |
| echo " - ${label}" | |
| continue | |
| fi | |
| if [[ "${label}" =~ ${backport_regex} ]]; then | |
| major="${BASH_REMATCH[1]}" | |
| all_backport_labels+=("${label}") | |
| echo " - ${label}" | |
| if [[ "${label}" == *x ]]; then | |
| floating_majors+=("${major}") | |
| fi | |
| fi | |
| done | |
| echo "::endgroup::" | |
| has_backport_label=false | |
| echo "::group::Detected Labels" | |
| for pr_label in "${pr_labels[@]}"; do | |
| for backport_label in "${all_backport_labels[@]}"; do | |
| if [ "${pr_label}" = "${backport_label}" ]; then | |
| has_backport_label=true | |
| echo " - ${pr_label}" | |
| fi | |
| done | |
| done | |
| echo "::endgroup::" | |
| if [ "${has_backport_label}" != true ]; then | |
| echo "::error::No backport label found." | |
| exit 1 | |
| fi | |
| has_floating_backport_label=false | |
| for floating_major in "${floating_majors[@]}"; do | |
| done | |