Skip to content

Commit 07e7199

Browse files
authored
Merge pull request #12563 from fejta/lab
Run verify-labels in bazel
2 parents ce5fe7e + 856119c commit 07e7199

File tree

5 files changed

+66
-43
lines changed

5 files changed

+66
-43
lines changed

Diff for: config/jobs/kubernetes/test-infra/test-infra-presubmits.yaml

-19
Original file line numberDiff line numberDiff line change
@@ -159,25 +159,6 @@ presubmits:
159159
requests:
160160
memory: "2Gi"
161161

162-
- name: pull-test-infra-verify-labels
163-
branches:
164-
- master
165-
run_if_changed: '^label_sync/labels.yaml'
166-
decorate: true
167-
labels:
168-
preset-service-account: "true"
169-
preset-bazel-scratch-dir: "true"
170-
spec:
171-
containers:
172-
- image: gcr.io/k8s-testimages/kubekins-e2e:v20190420-93fab49-experimental
173-
command:
174-
- runner.sh
175-
args:
176-
- ./hack/verify-labels.sh
177-
resources:
178-
requests:
179-
memory: "2Gi"
180-
181162
- name: pull-test-infra-verify-file-perms
182163
branches:
183164
- master

Diff for: hack/BUILD.bazel

+24
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ sh_test(
112112
],
113113
)
114114

115+
sh_binary(
116+
name = "update-labels",
117+
srcs = ["update-labels.sh"],
118+
args = ["$(location //label_sync)"],
119+
data = ["//label_sync"],
120+
)
121+
122+
sh_test(
123+
name = "verify-labels",
124+
srcs = ["verify-labels.sh"],
125+
args = [
126+
"$(location :update-labels)",
127+
"$(location //label_sync)",
128+
],
129+
data = [
130+
":update-labels",
131+
"//label_sync",
132+
"//label_sync:labels.md",
133+
"//label_sync:labels.md.tmpl",
134+
"//label_sync:labels.yaml",
135+
],
136+
tags = ["lint"],
137+
)
138+
115139
test_suite(
116140
name = "verify-all",
117141
tags = ["lint"], # picks up all non-manual targets with this tag

Diff for: hack/update-labels.sh

+21-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,25 @@ set -o errexit
1717
set -o nounset
1818
set -o pipefail
1919

20-
TESTINFRA_ROOT=$(git rev-parse --show-toplevel)
21-
LABELS_CONFIG=${LABELS_CONFIG:-"${TESTINFRA_ROOT}/label_sync/labels.yaml"}
22-
LABELS_DOCS_TEMPLATE=${LABELS_DOCS_TEMPLATE:-"${TESTINFRA_ROOT}/label_sync/labels.md.tmpl"}
23-
LABELS_DOCS_OUTPUT=${LABELS_DOCS_OUTPUT:-"${TESTINFRA_ROOT}/label_sync/labels.md"}
20+
if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
21+
echo "Updating labels..." >&2
22+
elif ! command -v bazel &>/dev/null; then
23+
echo "Install bazel at https://bazel.build" >&2
24+
exit 1
25+
else
26+
(
27+
set -o xtrace
28+
bazel run @io_k8s_test_infra//hack:update-labels
29+
)
30+
exit 0
31+
fi
2432

25-
bazel run //label_sync -- \
26-
--config=${LABELS_CONFIG} \
27-
--action=docs \
28-
--docs-template=${LABELS_DOCS_TEMPLATE} \
29-
--docs-output=${LABELS_DOCS_OUTPUT}
33+
label_sync=$PWD/$1
34+
cd "$BUILD_WORKSPACE_DIRECTORY"
35+
out=${2:-label_sync/labels.md}
36+
37+
"$label_sync" \
38+
--config=label_sync/labels.yaml \
39+
--action=docs \
40+
--docs-template=label_sync/labels.md.tmpl \
41+
"--docs-output=$out"

Diff for: hack/verify-labels.sh

+21-9
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,29 @@ set -o errexit
1717
set -o nounset
1818
set -o pipefail
1919

20-
TESTINFRA_ROOT=$(git rev-parse --show-toplevel)
20+
if [[ -n "${TEST_WORKSPACE:-}" ]]; then # Running inside bazel
21+
echo "Validating labels..." >&2
22+
elif ! command -v bazel &> /dev/null; then
23+
echo "Install bazel at https://bazel.build" >&2
24+
exit 1
25+
else
26+
(
27+
set -o xtrace
28+
bazel test --test_output=streamed @io_k8s_test_infra//hack:verify-labels
29+
)
30+
exit 0
31+
fi
2132

22-
TMP_LABELS_DOCS=$(mktemp)
23-
trap 'rm -f "${TMP_LABELS_DOCS}"' EXIT
24-
LABELS_DOCS_OUTPUT="${TMP_LABELS_DOCS}" ${TESTINFRA_ROOT}/hack/update-labels.sh
33+
out=$TEST_TMPDIR/labels.md.expected
34+
BUILD_WORKSPACE_DIRECTORY="$PWD" "$@" "$out"
2535

2636

27-
DIFF=$(diff "${TMP_LABELS_DOCS}" "${TESTINFRA_ROOT}/label_sync/labels.md" || true)
28-
if [ ! -z "$DIFF" ]; then
29-
echo "${DIFF}"
30-
echo ""
31-
echo "FAILED: labels.yaml was updated without updating labels.md, please run 'hack/update-labels.sh'"
37+
DIFF=$(diff label_sync/labels.md "$out" || true)
38+
if [[ -n "$DIFF" ]]; then
39+
echo "< unexpected" >&2
40+
echo "> missing" >&2
41+
echo "${DIFF}" >&2
42+
echo "" >&2
43+
echo "ERROR: labels.md out of date. Fix with hack/update-labels.sh" >&2
3244
exit 1
3345
fi

Diff for: testgrid/config.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -2131,9 +2131,6 @@ test_groups:
21312131
- name: pull-test-infra-verify-deps
21322132
gcs_prefix: kubernetes-jenkins/pr-logs/directory/pull-test-infra-verify-deps
21332133
num_columns_recent: 20
2134-
- name: pull-test-infra-verify-labels
2135-
gcs_prefix: kubernetes-jenkins/pr-logs/directory/pull-test-infra-verify-labels
2136-
num_columns_recent: 20
21372134
- name: pull-test-infra-verify-file-perms
21382135
gcs_prefix: kubernetes-jenkins/pr-logs/directory/pull-test-infra-verify-file-perms
21392136
num_columns_recent: 20
@@ -7235,9 +7232,6 @@ dashboards:
72357232
- name: verify-deps
72367233
test_group_name: pull-test-infra-verify-deps
72377234
base_options: width=10
7238-
- name: verify-labels
7239-
test_group_name: pull-test-infra-verify-labels
7240-
base_options: width=10
72417235
- name: verify-codegen
72427236
test_group_name: pull-test-infra-verify-codegen
72437237
base_options: width=10

0 commit comments

Comments
 (0)