mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-11-22 04:50:40 -05:00
ci: adopt tidy workflow for bazel
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
This commit is contained in:
parent
64e1f553d1
commit
cc60de312e
6 changed files with 57 additions and 25 deletions
5
.github/workflows/test-bazel.yml
vendored
5
.github/workflows/test-bazel.yml
vendored
|
|
@ -7,13 +7,11 @@ on:
|
||||||
- main
|
- main
|
||||||
- "release/**"
|
- "release/**"
|
||||||
paths:
|
paths:
|
||||||
- "*.go"
|
|
||||||
- "**.bzl"
|
- "**.bzl"
|
||||||
- "**.bazel"
|
- "**.bazel"
|
||||||
- ".github/workflows/test-bazel.yml"
|
- ".github/workflows/test-bazel.yml"
|
||||||
pull_request:
|
pull_request:
|
||||||
paths:
|
paths:
|
||||||
- "*.go"
|
|
||||||
- "**.bzl"
|
- "**.bzl"
|
||||||
- "**.bazel"
|
- "**.bazel"
|
||||||
- ".github/workflows/test-bazel.yml"
|
- ".github/workflows/test-bazel.yml"
|
||||||
|
|
@ -28,11 +26,10 @@ jobs:
|
||||||
with:
|
with:
|
||||||
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
|
ref: ${{ !github.event.pull_request.head.repo.fork && github.head_ref || '' }}
|
||||||
|
|
||||||
- name: Run buildifier and gazelle test
|
- name: Run buildifier
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
bazelisk test //:buildifier-check
|
bazelisk test //:buildifier-check
|
||||||
bazelisk run //:gazelle-check
|
|
||||||
|
|
||||||
# TODO(malt3): Find workflows to run bazel unit tests
|
# TODO(malt3): Find workflows to run bazel unit tests
|
||||||
# - name: Run unit tests
|
# - name: Run unit tests
|
||||||
|
|
|
||||||
28
.github/workflows/test-tidy.yml
vendored
28
.github/workflows/test-tidy.yml
vendored
|
|
@ -30,16 +30,28 @@ jobs:
|
||||||
# No token available for forks, so we can't push changes
|
# No token available for forks, so we can't push changes
|
||||||
token: ${{ !github.event.pull_request.head.repo.fork && secrets.CI_COMMIT_PUSH_PR || '' }}
|
token: ${{ !github.event.pull_request.head.repo.fork && secrets.CI_COMMIT_PUSH_PR || '' }}
|
||||||
|
|
||||||
- name: Setup Go environment
|
- name: Run Bazel tidy
|
||||||
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
|
shell: bash
|
||||||
with:
|
run: |
|
||||||
go-version: "1.20.2"
|
bazelisk run //bazel/ci:tidy
|
||||||
|
bazelisk run //:gazelle-check
|
||||||
|
|
||||||
- name: Go tidy check
|
- name: Check if tidy made modifications
|
||||||
id: tidycheck
|
id: tidycheck
|
||||||
uses: katexochen/go-tidy-check@2f5d75dbd503b372466fa9d8bc85710558b953c7 # v2.0.0
|
shell: bash
|
||||||
with:
|
run: |
|
||||||
submodules: "true"
|
diff=$(git diff)
|
||||||
|
if [[ -z "$diff" ]]; then
|
||||||
|
echo "Everything is tidy"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
cat << EOF >> "${GITHUB_STEP_SUMMARY}"
|
||||||
|
\`\`\`diff
|
||||||
|
${diff}
|
||||||
|
\`\`\`
|
||||||
|
EOF
|
||||||
|
echo "::error::The repo is not tidy. Please run 'bazel run bazel/ci:tidy' and commit the changes."
|
||||||
|
exit 1
|
||||||
|
|
||||||
# The following steps are only executed if the previous tidy check failed
|
# The following steps are only executed if the previous tidy check failed
|
||||||
# and the action runs on an renovat branche. In this case, we tidy all
|
# and the action runs on an renovat branche. In this case, we tidy all
|
||||||
|
|
|
||||||
12
BUILD.bazel
12
BUILD.bazel
|
|
@ -12,18 +12,6 @@ gazelle(
|
||||||
mode = "diff",
|
mode = "diff",
|
||||||
)
|
)
|
||||||
|
|
||||||
gazelle(
|
|
||||||
name = "gazelle-update-repos",
|
|
||||||
args = [
|
|
||||||
"-from_file=go.work",
|
|
||||||
"-to_macro=toolchains/go_module_deps.bzl%go_dependencies",
|
|
||||||
"-build_file_proto_mode=disable_global",
|
|
||||||
"-build_file_generation=on",
|
|
||||||
"-prune",
|
|
||||||
],
|
|
||||||
command = "update-repos",
|
|
||||||
)
|
|
||||||
|
|
||||||
bazeldnf(name = "bazeldnf")
|
bazeldnf(name = "bazeldnf")
|
||||||
|
|
||||||
buildifier_test(
|
buildifier_test(
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ add_test(NAME integration-license COMMAND bash -c "go test -tags integration" WO
|
||||||
add_custom_target(format
|
add_custom_target(format
|
||||||
COMMAND bash -c "${BAZEL} run //:buildifier-fix"
|
COMMAND bash -c "${BAZEL} run //:buildifier-fix"
|
||||||
COMMAND bash -c "${BAZEL} run //:gazelle"
|
COMMAND bash -c "${BAZEL} run //:gazelle"
|
||||||
COMMAND bash -c "${BAZEL} run //:gazelle-update-repos"
|
COMMAND bash -c "${BAZEL} run //bazel/ci:tidy"
|
||||||
COMMAND bash -c "shfmt -i 2 -s -w -sr $(shfmt -f ${CMAKE_SOURCE_DIR} | grep -v helm/charts/cilium)"
|
COMMAND bash -c "shfmt -i 2 -s -w -sr $(shfmt -f ${CMAKE_SOURCE_DIR} | grep -v helm/charts/cilium)"
|
||||||
COMMAND bash -c "gofumpt -l -w ${CMAKE_SOURCE_DIR}"
|
COMMAND bash -c "gofumpt -l -w ${CMAKE_SOURCE_DIR}"
|
||||||
VERBATIM
|
VERBATIM
|
||||||
|
|
|
||||||
12
bazel/ci/BUILD.bazel
Normal file
12
bazel/ci/BUILD.bazel
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
sh_binary(
|
||||||
|
name = "tidy",
|
||||||
|
srcs = ["tidy.sh"],
|
||||||
|
data = [
|
||||||
|
"@bazel_gazelle//cmd/gazelle",
|
||||||
|
"@go_sdk//:bin/go",
|
||||||
|
],
|
||||||
|
env = {
|
||||||
|
"GAZELLE": "$(location @bazel_gazelle//cmd/gazelle)",
|
||||||
|
"GO": "$(location @go_sdk//:bin/go)",
|
||||||
|
},
|
||||||
|
)
|
||||||
23
bazel/ci/tidy.sh
Executable file
23
bazel/ci/tidy.sh
Executable file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
shopt -s inherit_errexit
|
||||||
|
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
gazelle=$(realpath "${GAZELLE}")
|
||||||
|
go=$(realpath "${GO}")
|
||||||
|
|
||||||
|
cd "${BUILD_WORKSPACE_DIRECTORY}"
|
||||||
|
|
||||||
|
submodules=$(${go} list -f '{{.Dir}}' -m)
|
||||||
|
|
||||||
|
for mod in ${submodules}; do
|
||||||
|
${go} mod tidy -C "${mod}"
|
||||||
|
done
|
||||||
|
|
||||||
|
${gazelle} update-repos \
|
||||||
|
-from_file=go.work \
|
||||||
|
-to_macro=toolchains/go_module_deps.bzl%go_dependencies \
|
||||||
|
-build_file_proto_mode=disable_global \
|
||||||
|
-build_file_generation=on \
|
||||||
|
-prune
|
||||||
Loading…
Add table
Add a link
Reference in a new issue