Skip to content

Commit

Permalink
linting (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
djeebus authored Mar 21, 2024
1 parent aeffb33 commit 2935ffa
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 24 deletions.
15 changes: 6 additions & 9 deletions .github/actions/build-image/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ runs:

- name: Build and push the Docker image
shell: bash
run: |
GIT_COMMIT=$(git rev-parse --short HEAD)
earthly \
--push \
+build \
--GIT_TAG=${{ inputs.image_tag }} \
--GIT_COMMIT=${GIT_COMMIT} \
--IMAGE_NAME=ghcr.io/${{ github.repository }}:${{ inputs.image_tag }}
run: >-
./earthly
--push
+build
--GIT_TAG=${{ inputs.image_tag }}
--IMAGE_NAME=ghcr.io/${{ github.repository }}:${{ inputs.image_tag }}
4 changes: 1 addition & 3 deletions .github/workflows/on_pull-request_docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ jobs:
with: { version: "${{ env.EARTHLY_TOOL_VERSION }}" }

- name: rebuild the docs
run: |
earthly \
+rebuild-docs
run: ./earthly +rebuild-docs

- name: verify that the checked in file has not changed
run: ./hacks/exit-on-changed-files.sh "Please run './earthly +rebuild-docs' and commit the results to this PR"
4 changes: 2 additions & 2 deletions .github/workflows/on_pull_request_go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
steps:
- uses: actions/checkout@v3

- uses: wistia/parse-tool-versions@v1.0
- uses: djeebus/parse-tool-versions@v2.1

- uses: earthly/actions-setup@v1
with: { version: "v${{ env.EARTHLY_TOOL_VERSION }}" }
with: { version: "v${{ env.EARTHLY }}" }

- run: ./earthly +ci-golang
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
earthly 0.7.23
golang 1.21.6
golangci-lint 1.56.1
helm 3.12.2
helm-cr 1.6.1
helm-ct 3.8.0
kubeconform 0.6.3
kustomize 5.1.0
staticcheck 2023.1.6
tilt 0.33.2
21 changes: 17 additions & 4 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
VERSION 0.7

ARG --global USERARCH
ARG --global GOLANG_VERSION="1.21"

test:
BUILD +ci-golang
BUILD +ci-helm

ci-golang:
BUILD +fmt-golang
BUILD +lint-golang
BUILD +staticcheck-golang
BUILD +golang-ci-lint
BUILD +validate-golang
BUILD +test-golang

Expand All @@ -27,6 +27,7 @@ release:
go-deps:
ARG GOOS=linux
ARG GOARCH=$USERARCH
ARG --required GOLANG_VERSION

FROM --platform=linux/$USERARCH golang:$GOLANG_VERSION-bullseye

Expand Down Expand Up @@ -131,6 +132,8 @@ docker:
SAVE IMAGE --push $IMAGE_NAME

dlv:
ARG --required GOLANG_VERSION

FROM golang:$GOLANG_VERSION-bullseye

RUN apt update && apt install -y ca-certificates curl git
Expand Down Expand Up @@ -159,8 +162,18 @@ fmt-golang:
RUN go fmt \
&& ./hacks/exit-on-changed-files.sh

lint-golang:
ARG STATICCHECK_VERSION="2023.1.6"
golang-ci-lint:
ARG --required GOLANGCI_LINT_VERSION

FROM golangci/golangci-lint:v${GOLANGCI_LINT_VERSION}

WORKDIR /src
COPY . .

RUN golangci-lint --timeout 15m run --verbose

staticcheck-golang:
ARG --required STATICCHECK_VERSION

FROM +go-deps

Expand Down
8 changes: 6 additions & 2 deletions earthly
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ read_tool_versions_write_to_env() {
# ignore comments, comments always start with #
if [[ ${key:0:1} != "#" ]]; then
full_key="${key/-/_}_tool_version"
export "${full_key}=${value}"
export "${full_key/-/_}=${value}"
fi
done <"$tool_versions_file"
}
Expand All @@ -30,9 +30,13 @@ read_tool_versions_write_to_env '.tool-versions'

set -x

# shellcheck disable=SC2048
earthly $* \
--CHART_RELEASER_VERSION=${helm_cr_tool_version} \
--GOLANG_VERSION=${golang_tool_version} \
--GOLANGCI_LINT_VERSION=${golangci_lint_tool_version} \
--HELM_VERSION=${helm_tool_version} \
--KUBECONFORM_VERSION=${kubeconform_tool_version} \
--KUSTOMIZE_VERSION=${kustomize_tool_version}
--KUSTOMIZE_VERSION=${kustomize_tool_version} \
--STATICCHECK_VERSION=${staticcheck_tool_version} \
--GIT_COMMIT=$(git rev-parse --short HEAD)
6 changes: 6 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ unit_test_race:

rebuild_docs:
./earthly +rebuild-docs

lint-golang:
./earthly +lint-golang

ci-golang:
./earthly +ci-golang
2 changes: 1 addition & 1 deletion pkg/app_watcher/app_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (ctrl *ApplicationWatcher) newApplicationInformerAndLister(refreshTimeout t
DeleteFunc: ctrl.onApplicationDeleted,
},
); err != nil {
log.Error().Err(err).Msg("failed to add event handlers")
log.Error().Err(err).Msg("failed to add event handler")
}
return informer, lister
}
Expand Down
13 changes: 10 additions & 3 deletions pkg/checks/preupgrade/kubepug.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,30 @@ func checkApp(ctx context.Context, appName, targetKubernetesVersion string, mani
_, span := tracer.Start(ctx, "KubePug")
defer span.End()

logger := log.With().
Ctx(ctx).
Str("app_name", appName).
Logger()

var outputString []string

log.Debug().Str("app_name", appName).Msg("KubePug CheckApp")
logger.Debug().Msg("KubePug CheckApp")

// write manifests to temp file because kubepug can only read from file or STDIN
// Create a temporary directory
tempDir, err := os.MkdirTemp("/tmp", "kubechecks-kubepug")
if err != nil {
log.Error().Err(err).Msg("could not create temp directory to write manifests for kubepug check")
logger.Error().Err(err).Msg("could not create temp directory to write manifests for kubepug check")
//return "", err
return msg.Result{}, err
}
defer os.RemoveAll(tempDir)

for i, manifest := range manifests {
tmpFile := fmt.Sprintf("%s/%b.yaml", tempDir, i)
os.WriteFile(tmpFile, []byte(manifest), 0666)
if err = os.WriteFile(tmpFile, []byte(manifest), 0666); err != nil {
logger.Error().Err(err).Str("path", tmpFile).Msg("failed to write file")
}
}

nextVersion, err := nextKubernetesVersion(targetKubernetesVersion)
Expand Down

0 comments on commit 2935ffa

Please sign in to comment.