-
Notifications
You must be signed in to change notification settings - Fork 31
141 lines (130 loc) · 5 KB
/
pr-github-checks.yml
File metadata and controls
141 lines (130 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
name: PR GitHub Checks
permissions:
contents: read
on:
pull_request_target:
branches:
- "main"
- "release-*"
- "feature-new-centralized-arch" # TODO: Remove after merging feature branch
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
jobs:
pr-milestone-project-check:
permissions:
pull-requests: write # Required for setting the milestone
contents: read
runs-on: ubuntu-latest
steps:
- name: Set milestone to latest open 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:
permissions:
pull-requests: write # Required for setting the labels
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- 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 presence
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 for absence of 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@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
types: |
deps
chore
docs
feat
fix
test
# ensures the subject doesn't start with an uppercase character
subjectPattern: ^(?![A-Z]).+$
subjectPatternError: |
The subject "{subject}" found in the pull request title "{title}"
didn't match the configured pattern. Please ensure that the subject
doesn't start with an uppercase character.
requireScope: false
pr-prevent-kustomization:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.base.ref == 'main' }}
steps:
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
repository: ${{ github.event.pull_request.head.repo.full_name }}
- name: Verify kustomization.yaml has no changes
run: |
git diff origin/main --exit-code -- config/manager/kustomization.yaml || (echo "config/manager/kustomization.yaml has changes compared to main branch. Please, revert them" && exit 1)