Skip to content

Commit

Permalink
fix hack scripts to run locally again
Browse files Browse the repository at this point in the history
Fix hack scripts to run locally again. We have some Git permissions
issues, formatting issues, deprecated linters, bad Go configs, custom
mount points etc. Now it should be cleaner, runs on Linux and Mac
equally (zsh can't handle "${@}" for example)...

Signed-off-by: Tuomo Tanskanen <tuomo.tanskanen@est.tech>
  • Loading branch information
tuminoid committed Jun 28, 2024
1 parent 693fda2 commit 897843b
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 97 deletions.
46 changes: 23 additions & 23 deletions hack/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@

# Ignore the rule that says we should always quote variables, because
# in this script we *do* want globbing.
# shellcheck disable=SC2086
# shellcheck disable=SC2086,SC2292

set -eux

IS_CONTAINER=${IS_CONTAINER:-false}
ARTIFACTS=${ARTIFACTS:-/tmp}
IS_CONTAINER="${IS_CONTAINER:-false}"
ARTIFACTS="${ARTIFACTS:-/tmp}"
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"

if [ "${IS_CONTAINER}" != "false" ]; then
eval "$(go env)"
cd "${GOPATH}"/src/github.com/metal3-io/baremetal-operator
export XDG_CACHE_HOME="/tmp/.cache"
# we need to tell git its OK to use dir owned by someone else
git config --global safe.directory /workdir
export XDG_CACHE_HOME="/tmp/.cache"

INPUT_FILES="$(git ls-files config) $(git ls-files | grep zz_generated)"
cksum $INPUT_FILES > "$ARTIFACTS/lint.cksums.before"
export VERBOSE="--verbose"
make generate manifests
cksum $INPUT_FILES > "$ARTIFACTS/lint.cksums.after"
diff "$ARTIFACTS/lint.cksums.before" "$ARTIFACTS/lint.cksums.after"
INPUT_FILES="$(git ls-files config) $(git ls-files | grep zz_generated)"
cksum ${INPUT_FILES} > "${ARTIFACTS}/lint.cksums.before"
export VERBOSE="--verbose"
make generate manifests
cksum ${INPUT_FILES} > "${ARTIFACTS}/lint.cksums.after"
diff "${ARTIFACTS}/lint.cksums.before" "${ARTIFACTS}/lint.cksums.after"

else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--env DEPLOY_KERNEL_URL=http://172.22.0.1/images/ironic-python-agent.kernel \
--env DEPLOY_RAMDISK_URL=http://172.22.0.1/images/ironic-python-agent.initramfs \
--env IRONIC_ENDPOINT=http://localhost:6385/v1/ \
--volume "${PWD}:/go/src/github.com/metal3-io/baremetal-operator:rw,z" \
--entrypoint sh \
--workdir /go/src/github.com/metal3-io/baremetal-operator \
docker.io/golang:1.22 \
/go/src/github.com/metal3-io/baremetal-operator/hack/generate.sh "${@}"
fi;
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--env DEPLOY_KERNEL_URL=http://172.22.0.1/images/ironic-python-agent.kernel \
--env DEPLOY_RAMDISK_URL=http://172.22.0.1/images/ironic-python-agent.initramfs \
--env IRONIC_ENDPOINT=http://localhost:6385/v1/ \
--volume "${PWD}:/workdir:rw,z" \
--entrypoint sh \
--workdir /workdir \
docker.io/golang:1.22 \
/workdir/hack/generate.sh "$@"
fi
20 changes: 0 additions & 20 deletions hack/golint.sh

This file was deleted.

1 change: 1 addition & 0 deletions hack/gomod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# 2. Verify that running the above doesn't change go.mod and go.sum
#
# NOTE: This won't work unless the build environment has internet access
# shellcheck disable=SC2292

set -eux

Expand Down
31 changes: 16 additions & 15 deletions hack/manifestlint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/sh
# shellcheck disable=SC2292

set -eux

IS_CONTAINER=${IS_CONTAINER:-false}
IS_CONTAINER="${IS_CONTAINER:-false}"
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"
K8S_VERSION="${K8S_VERSION:-master}"

Expand All @@ -24,19 +25,19 @@ if [ "${IS_CONTAINER}" != "false" ]; then
{ set +x; } 2>/dev/null
echo "<-------------------------STARTING MANIFESTS VALIDATION CHECKS------------------------->"
"${KUBECONFORM_PATH:-}"kubeconform --strict --ignore-missing-schemas \
--kubernetes-version "${K8S_VERSION}" \
--ignore-filename-pattern kustom --ignore-filename-pattern patch \
--ignore-filename-pattern controller_manager_config \
--output tap \
config/ examples/
--kubernetes-version "${K8S_VERSION}" \
--ignore-filename-pattern kustom --ignore-filename-pattern patch \
--ignore-filename-pattern controller_manager_config \
--output tap \
config/ examples/
echo "<-------------------------COMPLETED MANIFESTS VALIDATION CHECKS------------------------>"
else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--env KUBECONFORM_PATH="/" \
--volume "${PWD}:/workdir:ro,z" \
--entrypoint sh \
--workdir /workdir \
ghcr.io/yannh/kubeconform:v0.6.2-alpine@sha256:49b5f6b320d30c1b8b72a7abdf02740ac9dc36a3ba23b934d1c02f7b37e6e740 \
/workdir/hack/manifestlint.sh "${@}"
fi;
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--env KUBECONFORM_PATH="/" \
--volume "${PWD}:/workdir:ro,z" \
--entrypoint sh \
--workdir /workdir \
ghcr.io/yannh/kubeconform:v0.6.2-alpine@sha256:49b5f6b320d30c1b8b72a7abdf02740ac9dc36a3ba23b934d1c02f7b37e6e740 \
/workdir/hack/manifestlint.sh "$@"
fi
1 change: 1 addition & 0 deletions hack/markdownlint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
# markdownlint-cli2 has config file(s) named .markdownlint-cli2.yaml in the repo
# shellcheck disable=SC2292

set -eux

Expand Down
21 changes: 11 additions & 10 deletions hack/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#!/bin/sh
# shellcheck disable=SC2292

set -eux

IS_CONTAINER=${IS_CONTAINER:-false}
IS_CONTAINER="${IS_CONTAINER:-false}"
CONTAINER_RUNTIME="${CONTAINER_RUNTIME:-podman}"

if [ "${IS_CONTAINER}" != "false" ]; then
TOP_DIR="${1:-.}"
find "${TOP_DIR}" -path ./vendor -prune -o -name '*.sh' -type f -exec shellcheck -s bash {} \+
TOP_DIR="${1:-.}"
find "${TOP_DIR}" -path ./vendor -prune -o -name '*.sh' -type f -exec shellcheck -s bash {} \+
else
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/workdir:ro,z" \
--entrypoint sh \
--workdir /workdir \
docker.io/koalaman/shellcheck-alpine:v0.10.0@sha256:5921d946dac740cbeec2fb1c898747b6105e585130cc7f0602eec9a10f7ddb63 \
/workdir/hack/shellcheck.sh "$@"
"${CONTAINER_RUNTIME}" run --rm \
--env IS_CONTAINER=TRUE \
--volume "${PWD}:/workdir:ro,z" \
--entrypoint sh \
--workdir /workdir \
docker.io/koalaman/shellcheck-alpine:v0.10.0@sha256:5921d946dac740cbeec2fb1c898747b6105e585130cc7f0602eec9a10f7ddb63 \
/workdir/hack/shellcheck.sh "$@"
fi
29 changes: 0 additions & 29 deletions hack/unit.sh

This file was deleted.

0 comments on commit 897843b

Please sign in to comment.