generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 24
135 lines (124 loc) · 4.41 KB
/
pr-github-checks.yml
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
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@47b15d52c5c30e94a17ec87eb8dd51ff5221fed9
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@6b2903bdce6310cfbddd87c418f253cf29b2dec9
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