Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Golang linting to pre-commit #83

Merged
merged 9 commits into from
Sep 19, 2024
Merged
26 changes: 13 additions & 13 deletions .github/workflows/helm-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ jobs:
run: |
# Enable pipefail so git command failures do not result in null versions downstream
set -x
echo "RELEASE_VERSION=$(date +'%Y.%-m.%-d%H%M%S')" >> $GITHUB_OUTPUT
echo "RELEASE_VERSION=$(date +'%Y.%-m.%-d%H%M%S')" >> "${GITHUB_OUTPUT}"

# This ensures that the latest tag we grab will be of the operator image, and not the helm chart
echo "OPERATOR_VERSION=$(\
git ls-remote --tags --refs --sort="v:refname" \
origin 'v[0-9].[0-9].[0-9]' | tail -n1 | sed 's/.*\///'
)" >> $GITHUB_OUTPUT
)" >> "${GITHUB_OUTPUT}"

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"

- name: Set up Helm
uses: azure/setup-helm@v4
Expand Down Expand Up @@ -68,15 +68,15 @@ jobs:
mkdir -p /tmp/chart
cd deploy/charts
# Update the operator version tag in values.yaml
sed -i "s/tag:.*$/tag: $OPERATOR_VERSION/g" prefect-operator/values.yaml
sed -i "s/tag:.*$/tag: ${OPERATOR_VERSION}/g" prefect-operator/values.yaml
helm package prefect-operator \
--destination /tmp/chart \
--dependency-update \
--version $RELEASE_VERSION \
--app-version $OPERATOR_VERSION \
--version "${RELEASE_VERSION}" \
--app-version "${OPERATOR_VERSION}" \
--sign --key 'jamie@prefect.io' \
--keyring $SIGN_KEYRING \
--passphrase-file $SIGN_PASSPHRASE_FILE
--keyring "${SIGN_KEYRING}" \
--passphrase-file "${SIGN_PASSPHRASE_FILE}"
env:
RELEASE_VERSION: ${{ steps.get_version.outputs.RELEASE_VERSION }}
OPERATOR_VERSION: ${{ steps.get_version.outputs.OPERATOR_VERSION }}
Expand All @@ -92,19 +92,19 @@ jobs:
- name: Commit and push
run: |
cp /tmp/chart/index.yaml .
cp /tmp/chart/prefect-operator-$RELEASE_VERSION.* ./charts
git add ./index.yaml ./charts/prefect-operator-$RELEASE_VERSION.* ./charts/
cp "/tmp/chart/prefect-operator-${RELEASE_VERSION}.*" ./charts
git add ./index.yaml "./charts/prefect-operator-$RELEASE_VERSION.*" ./charts/
git commit -m "Release $RELEASE_VERSION"
git push origin gh-pages
env:
RELEASE_VERSION: ${{ steps.get_version.outputs.RELEASE_VERSION }}

- name: Create Github Release + Tag
run: |
gh release create $RELEASE_VERSION \
gh release create "${RELEASE_VERSION}" \
--latest=false \
--notes "Packaged with prefect-operator version \
[$OPERATOR_VERSION](https://github.com/PrefectHQ/prefect-operator/releases/tag/$OPERATOR_VERSION)"
[${OPERATOR_VERSION}](https://github.com/PrefectHQ/prefect-operator/releases/tag/${OPERATOR_VERSION})"
env:
GITHUB_TOKEN: ${{ github.token }}
RELEASE_VERSION: ${{ steps.get_version.outputs.RELEASE_VERSION }}
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
name: Static analysis

"on":
pull_request:

# Limit concurrency by workflow/branch combination.
#
# For pull request builds, pushing additional changes to the
# branch will cancel prior in-progress and pending builds.
#
# For builds triggered on a branch push, additional changes
# will wait for prior builds to complete before starting.
#
# https://docs.github.com/en/actions/using-jobs/using-concurrency
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
pre-commit-checks:
name: pre-commit checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false

- name: Install tool dependencies
uses: jdx/mise-action@v2

- name: Install tool dependencies (non-mise)
run: |
go install github.com/BurntSushi/toml/cmd/tomlv@latest
go install golang.org/x/tools/cmd/goimports@latest

- name: Build helm dependencies
run: |
helm repo add bitnami https://charts.bitnami.com/bitnami
helm dependency build deploy/charts/prefect-operator

- name: Run pre-commit
run: |
pre-commit run --show-diff-on-failure --color=always --all-files
2 changes: 1 addition & 1 deletion .github/workflows/update-helm-versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
run: echo "date=$(date +'%Y-%m-%d')" >> "${GITHUB_OUTPUT}"

- name: create branch for helm version updates
run: |
Expand Down
4 changes: 4 additions & 0 deletions .mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ kustomize = '5.3.0'
pre-commit = '3.8.0'
setup-envtest = '0.17.0'
yamllint = '1.35.1'

# tomlv does not currently have an entry in the registry.
# For now, install with `go`:
# go install github.com/BurntSushi/toml/cmd/tomlv@latest
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,18 @@ repos:
- id: yamllint
args:
- --strict

- repo: https://github.com/dnephin/pre-commit-golang
rev: v0.5.1
hooks:
- id: go-fmt
# This one doesn't work because no Go files are in the root.
# See https://github.com/dnephin/pre-commit-golang/issues/30
# - id: go-vet
- id: go-imports
- id: validate-toml
- id: golangci-lint
# We already run unit tests in tests.yaml, which ensures
# they're called properly by using the `make` target.
# - id: go-unit-tests
- id: go-mod-tidy
10 changes: 6 additions & 4 deletions internal/controller/prefectserver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,13 @@ func (r *PrefectServerReconciler) prefectServerDeployment(server *prefectiov1.Pr
}

// Set PrefectServer instance as the owner and controller
ctrl.SetControllerReference(server, dep, r.Scheme)
// TODO: handle errors from SetControllerReference.
_ = ctrl.SetControllerReference(server, dep, r.Scheme)
if pvc != nil {
ctrl.SetControllerReference(server, pvc, r.Scheme)
_ = ctrl.SetControllerReference(server, pvc, r.Scheme)
}
if migrationJob != nil {
ctrl.SetControllerReference(server, migrationJob, r.Scheme)
_ = ctrl.SetControllerReference(server, migrationJob, r.Scheme)
}
return *dep, pvc, migrationJob
}
Expand Down Expand Up @@ -574,7 +575,8 @@ func (r *PrefectServerReconciler) prefectServerService(server *prefectiov1.Prefe
},
}

ctrl.SetControllerReference(server, &service, r.Scheme)
// TODO: handle errors from SetControllerReference.
_ = ctrl.SetControllerReference(server, &service, r.Scheme)

return service
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ import (
// Run e2e tests using the Ginkgo runner.
func TestE2E(t *testing.T) {
RegisterFailHandler(Fail)
fmt.Fprintf(GinkgoWriter, "Starting prefect-operator suite\n")
_, _ = fmt.Fprintf(GinkgoWriter, "Starting prefect-operator suite\n")
RunSpecs(t, "e2e suite")
}
6 changes: 3 additions & 3 deletions test/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
)

func warnError(err error) {
fmt.Fprintf(GinkgoWriter, "warning: %v\n", err)
_, _ = fmt.Fprintf(GinkgoWriter, "warning: %v\n", err)
}

// InstallPrometheusOperator installs the prometheus Operator to be used to export the enabled metrics.
Expand All @@ -52,12 +52,12 @@ func Run(cmd *exec.Cmd) ([]byte, error) {
cmd.Dir = dir

if err := os.Chdir(cmd.Dir); err != nil {
fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
_, _ = fmt.Fprintf(GinkgoWriter, "chdir dir: %s\n", err)
}

cmd.Env = append(os.Environ(), "GO111MODULE=on")
command := strings.Join(cmd.Args, " ")
fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
_, _ = fmt.Fprintf(GinkgoWriter, "running: %s\n", command)
output, err := cmd.CombinedOutput()
if err != nil {
return output, fmt.Errorf("%s failed with error: (%v) %s", command, err, string(output))
Expand Down