PR Github Checks #11467
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: PR Github Checks | |
on: | |
pull_request_target: | |
branches: | |
- "main" | |
- "release-*" | |
types: | |
- opened | |
- reopened | |
- edited | |
- synchronize | |
- labeled | |
- unlabeled | |
- milestoned | |
workflow_dispatch: | |
env: | |
PROJECT_NAME: "Huskies" | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} | |
NUMBER: ${{ github.event.number }} | |
TITLE: ${{ github.event.pull_request.title }} | |
GH_HOST: github.com | |
permissions: write-all | |
jobs: | |
pr-milestone-project-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set milestone | |
if: github.event.pull_request.milestone == null | |
run: | | |
# set milestone to the latest open milestone | |
latest_milestone=$(gh api \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${GH_REPO}/milestones --hostname ${GH_HOST} | jq -r '.[]|.title' | sort -r | head -n 1) | |
# fail if there is no open milestone | |
if [ -z "$latest_milestone" ]; then | |
echo "No open milestone found" | |
exit 1 | |
fi | |
gh pr edit ${{ github.event.number }} --milestone "${latest_milestone}" | |
pr-label-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Code | |
uses: actions/checkout@v4 | |
- name: Add kind label based on PR title prefix | |
if: always() | |
run: | | |
# get title prefix | |
# get kind label | |
# check if kind label is the same as title prefix | |
# check if there is a kind label for the title prefix based on the mapping | |
# if label is missing, add the correct one | |
# if label is incorrect, remove it and add the correct one | |
# | |
prefix=$(echo "$TITLE" | grep -o '^[a-z]*') | |
kind_label=$( gh pr view "$NUMBER" --json labels -q '.labels[]|.name' | grep '^kind/' || true ) | |
prefix_to_label_file=.github/workflows/titleprefix_to_label.json | |
correct_kind_label=$(cat $prefix_to_label_file | jq -r ".\"$prefix\"") | |
if [ -z "$kind_label" ]; then | |
echo "Adding $correct_kind_label label" | |
gh pr edit "$NUMBER" --add-label $correct_kind_label | |
elif [ "$kind_label" != "$correct_kind_label" ]; then | |
echo "Removing $kind_label label" | |
gh pr edit "$NUMBER" --remove-label $kind_label | |
echo "Adding $correct_kind_label label" | |
gh pr edit "$NUMBER" --add-label $correct_kind_label | |
fi | |
- name: Check for area label | |
if: always() | |
run: | | |
gh api --jq '.labels.[].name' /repos/${REPO}/pulls/${NUMBER} | \ | |
grep -q '^area\/' || (echo "area label missing"; exit 1) | |
env: | |
GH_TOKEN: ${{ github.token }} | |
REPO: ${{ github.repository }} | |
NUMBER: ${{ github.event.number }} | |
- name: Check that there is no do-not-merge label | |
if: always() | |
run: | | |
labels=$(gh api --jq '.labels.[]' /repos/${REPO}/pulls/${NUMBER} ) | |
echo "Labels found: $( echo $labels | jq -r '.name' )" | |
! echo "$labels" | jq 'select(.name | startswith("do-not-merge"))' | jq -n "input.name" | |
env: | |
GH_TOKEN: ${{ github.token }} | |
REPO: ${{ github.repository }} | |
NUMBER: ${{ github.event.number }} | |
pr-title-check: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Validate title | |
uses: amannn/action-semantic-pull-request@40166f00814508ec3201fc8595b393d451c8cd80 | |
env: | |
GITHUB_TOKEN: ${{ github.token }} | |
with: | |
types: | | |
deps | |
chore | |
docs | |
feat | |
fix | |
test | |
requireScope: false | |
pr-prevent-kustomization: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.pull_request.base.ref == 'main' }} | |
steps: | |
- name: Check-out code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- name: Check kustomization.yaml changes | |
uses: tj-actions/changed-files@251f07ed5250f0c01a1745b77a54289a678b3928 | |
id: changed-kustomization | |
with: | |
files: "config/manager/kustomization.yaml" | |
- name: Prevent kustomization.yaml changes | |
run: | | |
if ${{ steps.changed-kustomization.outputs.any_changed }}; then | |
echo "kustomization.yaml file changed!" | |
exit 1 | |
fi |