-
-
Save jodh-intel/8686dd0ad04c9526cb5ba93283805561 to your computer and use it in GitHub Desktop.
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: Ensure all PRs have the required porting labels | |
on: | |
pull_request: | |
types: | |
- closed | |
jobs: | |
check-pr-porting-labels: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install hub | |
run: | | |
HUB_ARCH="amd64" | |
HUB_VER=$(curl -sL "https://api.github.com/repos/github/hub/releases/latest" |\ | |
jq -r .tag_name | sed 's/^v//') | |
curl -sL \ | |
"https://github.com/github/hub/releases/download/v${HUB_VER}/hub-linux-${HUB_ARCH}-${HUB_VER}.tgz" |\ | |
tar xz --strip-components=2 --wildcards '*/bin/hub' && \ | |
sudo install hub /usr/local/bin | |
- name: Stop PR being merged unless it has atleast one backport label and one forward port label | |
env: | |
GITHUB_TOKEN: ${{ secrets.KATA_GITHUB_ACTIONS_TOKEN }} | |
DEBUG: true | |
run: | | |
pr=${{ github.event.number }} | |
# Every PR must have two porting labels before it can be merged. | |
# This is to ensure it is clear that a reviewer has considered both | |
# porting directions. | |
backport_labels=("needs-backport" "no-backport-needed") | |
forward_port_labels=("needs-forward-port" "no-forward-port-needed") | |
pr_details=$(hub pr list -f '%I;%L%n' | grep "^${pr}" || true) | |
[ -z "$pr_details" ] \ | |
&& echo "::error::Cannot determine details for PR $pr" \ | |
&& exit 1 | |
labels=$(echo "$pr_details"|cut -d';' -f2|tr ',' ' ') | |
[ -z "$labels" ] \ | |
&& echo "::error::PR $pr does not have required porting labels" \ | |
&& exit 1 | |
backport_label="" | |
for label in ${backport_labels[@]} | |
do | |
echo "$labels"|grep -qw "$label" \ | |
&& backport_label="$label" \ | |
&& break | |
done | |
[ -z "$backport_label" ] \ | |
&& echo "::error::PR $pr missing a backport label (${backport_labels[@]})" \ | |
&& exit 1 | |
forward_port_label="" | |
for label in ${forward_port_labels[@]} | |
do | |
echo "$labels"|grep -qw "$label" \ | |
&& forward_port_label="$label" \ | |
&& break | |
done | |
[ -z "$forward_port_label" ] \ | |
&& echo "::error::PR $pr missing a forward port label (${backport_labels[@]})" \ | |
&& exit 1 | |
echo "::debug::PR $pr has required porting labels ($backport_label, $forward_port_label)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think that although we are trying to reduce the amount of labels, in this case since there is a script enforcing their existence it does make sense.
As long as the error messages are clear enough and it's document it should work.
I would however explain in the error message what is required from the developer to fix it (and not just read the XXXXXXX manual :-)).
So for example, in "PR $pr does not have required porting labels" I'd also point out what labels should be added for it to actually pass (backport / forward-port/no-backport-needed / no-forward-port-needed)