test #127
Workflow file for this run
This file contains 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: Add backport label | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
- edited | |
- labeled | |
- unlabeled | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
check-issues: | |
if: ${{ github.event.label.name != 'auto-backport' }} | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code to get gh-utils script | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') }} | |
uses: actions/checkout@v4 | |
- name: Determine whether to add label | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CONTAINS_AUTO_BACKPORT: ${{ contains(github.event.pull_request.labels.*.name, 'auto-backport') }} | |
id: add_label | |
run: | | |
pr=${{ github.event.pull_request.number }} | |
linked_issues=$(./ci/gh-util.sh \ | |
list-issues-for-pr "$pr" |\ | |
grep -v "^\#" || true) | |
[ -z "${linked_issues}" ] && { | |
echo "::error::No linked issues for PR $pr" | |
exit 1 | |
} | |
has_bug=false | |
for issue in $(echo "$linked_issues") | |
do | |
labels=$(./ci/gh-util.sh list-labels-for-issue "$issue") | |
label_names=$(echo $labels | jq -r '.labels[].name' || true) | |
if [[ "$label_names" =~ "bug" ]]; then | |
has_bug=true | |
break | |
fi | |
done | |
has_backport_needed_label=${{ contains(github.event.pull_request.labels.*.name, 'needs-backport') }} | |
has_no_backport_needed_label=${{ contains(github.event.pull_request.labels.*.name, 'no-backport-needed') }} | |
echo "add_backport_label=false" >> $GITHUB_OUTPUT | |
if [ $has_backport_needed_label = true ] || [ $has_bug = true ]; then | |
if [[ $has_no_backport_needed_label = false ]]; then | |
echo "add_backport_label=true" >> $GITHUB_OUTPUT | |
fi | |
fi | |
# Do not spam comment, only if auto-backport label is going to be newly added. | |
echo "auto_backport_added=$CONTAINS_AUTO_BACKPORT" >> $GITHUB_OUTPUT | |
- name: Add comment | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') && steps.add_label.outputs.add_backport_label == 'true' && steps.add_label.outputs.auto_backport_added == 'false' }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: 'This issue has been marked for auto-backporting. Add label(s) backport-to-BRANCHNAME to backport to them' | |
}) | |
# Allow label to be removed by adding no-backport-needed label | |
- name: Remove auto-backport label | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') && steps.add_label.outputs.add_backport_label == 'false' }} | |
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 | |
with: | |
remove-labels: "auto-backport" | |
repo-token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Add auto-backport label | |
if: ${{ !contains(github.event.pull_request.labels.*.name, 'force-skip-ci') && steps.add_label.outputs.add_backport_label == 'true' }} | |
uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 | |
with: | |
add-labels: "auto-backport" | |
repo-token: ${{ secrets.GITHUB_TOKEN }} |