Repository navigation
Expand file tree
/
Copy path.pre-commit-config.yaml
More file actions
149 lines (126 loc) · 4.17 KB
/
Copy path.pre-commit-config.yaml
File metadata and controls
149 lines (126 loc) · 4.17 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
142
143
144
145
146
147
148
149
minimum_pre_commit_version: "3.2.0"
fail_fast: false
repos:
- repo: local
hooks:
# ------------------------------------------------------------
# PRE-COMMIT
# ------------------------------------------------------------
- id: generate-and-format
name: Generate code, manifests and format
description: Regenerate generated Go files, CRDs, RBAC and formatting
entry: >-
bash -c '
set -euo pipefail
make generate manifests
make fmt
'
language: system
pass_filenames: false
always_run: true
stages:
- pre-commit
- id: verify-go-modules
name: Verify Go modules
description: Verify that downloaded Go modules have not been modified
entry: go mod verify
language: system
pass_filenames: false
always_run: true
stages:
- pre-commit
- id: test
name: Run tests
description: Run the complete operator test suite
entry: make test
language: system
pass_filenames: false
always_run: true
stages:
- pre-commit
# ------------------------------------------------------------
# PRE-PUSH
# ------------------------------------------------------------
- id: generated-files
name: Verify generated files
description: Ensure generated files are committed before pushing
entry: >-
bash -c '
set -euo pipefail
make generate manifests
make fmt
if [[ -n "$(git status --porcelain)" ]]; then
echo
echo "Generated or formatted files are not committed."
echo
git status --short
echo
echo "Run:"
echo
echo " make generate manifests"
echo " make fmt"
echo " git add ."
echo
exit 1
fi
'
language: system
pass_filenames: false
always_run: true
stages:
- pre-push
- id: lint
name: Run golangci-lint
description: Run the complete Go linter configuration
entry: golangci-lint run --timeout=5m
language: system
pass_filenames: false
always_run: true
stages:
- pre-push
- id: validate-helm-chart
name: Validate Helm chart
description: Package and verify the operator Helm chart
entry: >-
bash -c '
set -euo pipefail
chart_version="0.0.0-pre-push"
app_version="v0.0.0-pre-push"
chart="dist/helm/github-platform-operator-${chart_version}.tgz"
rendered="$(mktemp)"
trap "rm -f ${rendered}" EXIT
rm -rf dist/helm
./hack/package-release-helm-chart.sh \
"${chart_version}" \
"${app_version}"
if [[ ! -f "${chart}" ]]; then
echo "Helm chart was not generated: ${chart}" >&2
exit 1
fi
helm lint "${chart}"
helm template \
github-platform-operator \
"${chart}" \
--namespace github-platform-operator-system \
> "${rendered}"
if ! grep -q "githubrepositoryrulesets/status" "${rendered}"; then
echo "Missing GitHubRepositoryRuleset status RBAC in Helm chart." >&2
exit 1
fi
if ! grep -q "githubrepositoryrulesets/finalizers" "${rendered}"; then
echo "Missing GitHubRepositoryRuleset finalizers RBAC in Helm chart." >&2
exit 1
fi
if ! grep -Eq \
"^[[:space:]]*-[[:space:]]*githubrepositoryrulesets[[:space:]]*$" \
"${rendered}"; then
echo "Missing GitHubRepositoryRuleset RBAC in Helm chart." >&2
exit 1
fi
echo "Helm chart and GitHubRepositoryRuleset RBAC are valid."
'
language: system
pass_filenames: false
always_run: true
stages:
- pre-push