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

chore: update golangci to 1.57 #555

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
212 changes: 107 additions & 105 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "stable"
go-version-file: go.mod

- name: "Setup yq" # Required for rendering the files.
shell: bash
Expand Down Expand Up @@ -219,107 +219,109 @@ jobs:
./hack/ci/render_and_upload_manifests.sh

bump-sec-scanners-config-main:
name: Bump sec-scanners-config.yaml on main branch
needs: create-draft
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.generate-version.outputs.VERSION }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main

- uses: actions/setup-go@v5
with:
go-version: "stable"

- name: "Setup yq" # Required for rendering the files.
shell: bash
run: |
go install github.com/mikefarah/yq/v4@latest
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- name: Render sec-scanners-config.yaml
shell: bash
run: |
yq --version
./hack/ci/render-sec-scanners-config.sh "${VERSION}"
FILE="sec-scanners-config.yaml"
echo "******* ${FILE} *******"
[ -f "${FILE}" ] && cat "${FILE}" || echo "${FILE} not found."

# Check if there are changes, so we can determine if all following steps can be skipped.
- name: Check for changes
shell: bash
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "No changes found. No need to create a PR"
else
echo "Changes found. Creating a PR and waiting for it to be merged."
echo "CREATE_PR=true" >> $GITHUB_ENV
fi

- name: Set up git
if: ${{ env.CREATE_PR == 'true' }}
env:
GH_TOKEN: ${{ secrets.BOT_PAT }}
REPO: ${{ github.repository }}
shell: bash
run: |
# set git username
ghusername=$(curl -s -H "Authorization: token ${GH_TOKEN}" https://api.github.com/user | jq '.login')
git config user.name "${ghusername}"
# set git mail address
ghemailaddress="${ghusername}@users.noreply.github.com"
git config user.email "${ghemailaddress}"
# set remote url
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"

- name: Set all variables
if: ${{ env.CREATE_PR == 'true' }}
shell: bash
run: |
PR_DATE="$(date '+%Y-%m-%d-%H-%M-%S')"
echo "pr date: ${PR_DATE}"
echo "PR_DATE=${PR_DATE}" >> $GITHUB_ENV

BRANCH_NAME="sec-scanners-bump-main-${PR_DATE}"
echo "name of the new branch: ${BRANCH_NAME}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV

- name: Create a pull request
if: ${{ env.CREATE_PR == 'true' }}
env:
REPO: ${{ github.repository }}
PR_DATE: ${{ env.PR_DATE }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
GH_TOKEN: ${{ secrets.BOT_PAT }}
shell: bash
run: |
# Create a new branch for our changes.
git checkout -b "${BRANCH_NAME}"

# Stage the changes to sec-scanner-config.yaml and create a commit.
git add sec-scanners-config.yaml
git commit -m "auto-bump sec-scanners-config: ${PR_DATE}"

# Push the changes to origin, as defined earlier.
git push origin "$BRANCH_NAME"

# Create a PR.
BODY="This is an auto-generated PR to bump the sec-scanners-config.yml on ${REPO}."
PR_URL=$(gh pr create --base "main" --head "${BRANCH_NAME}" --title "chore: bump sec-scanners-config on main" --body "${BODY}")
echo "PR_URL=${PR_URL}" >> $GITHUB_ENV

- name: USER INTERACTION REQUIRED
if: ${{ env.CREATE_PR == 'true' }}
shell: bash
timeout-minutes: 60
env:
PR_URL: ${{ env.PR_URL }}
GH_TOKEN: ${{ secrets.BOT_PAT }}
run: |
echo "please review: ${PR_URL}"
./hack/ci/await-pr-merge.sh
name: Bump sec-scanners-config.yaml on main branch
needs:
- create-draft
- generate-version
runs-on: ubuntu-latest
env:
VERSION: ${{ needs.generate-version.outputs.VERSION }}

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main

- uses: actions/setup-go@v5
with:
go-version-file: go.mod

- name: "Setup yq" # Required for rendering the files.
shell: bash
run: |
go install github.com/mikefarah/yq/v4@latest
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH

- name: Render sec-scanners-config.yaml
shell: bash
run: |
yq --version
./hack/ci/render-sec-scanners-config.sh "${VERSION}"
FILE="sec-scanners-config.yaml"
echo "******* ${FILE} *******"
[ -f "${FILE}" ] && cat "${FILE}" || echo "${FILE} not found."

# Check if there are changes, so we can determine if all following steps can be skipped.
- name: Check for changes
shell: bash
run: |
if [ -z "$(git status --porcelain)" ]; then
echo "No changes found. No need to create a PR"
else
echo "Changes found. Creating a PR and waiting for it to be merged."
echo "CREATE_PR=true" >> $GITHUB_ENV
fi

- name: Set up git
if: ${{ env.CREATE_PR == 'true' }}
env:
GH_TOKEN: ${{ secrets.BOT_PAT }}
REPO: ${{ github.repository }}
shell: bash
run: |
# set git username
ghusername=$(curl -s -H "Authorization: token ${GH_TOKEN}" https://api.github.com/user | jq '.login')
git config user.name "${ghusername}"
# set git mail address
ghemailaddress="${ghusername}@users.noreply.github.com"
git config user.email "${ghemailaddress}"
# set remote url
git remote set-url origin "https://x-access-token:${GH_TOKEN}@github.com/${REPO}.git"

- name: Set all variables
if: ${{ env.CREATE_PR == 'true' }}
shell: bash
run: |
PR_DATE="$(date '+%Y-%m-%d-%H-%M-%S')"
echo "pr date: ${PR_DATE}"
echo "PR_DATE=${PR_DATE}" >> $GITHUB_ENV

BRANCH_NAME="sec-scanners-bump-main-${PR_DATE}"
echo "name of the new branch: ${BRANCH_NAME}"
echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV

- name: Create a pull request
if: ${{ env.CREATE_PR == 'true' }}
env:
REPO: ${{ github.repository }}
PR_DATE: ${{ env.PR_DATE }}
BRANCH_NAME: ${{ env.BRANCH_NAME }}
GH_TOKEN: ${{ secrets.BOT_PAT }}
shell: bash
run: |
# Create a new branch for our changes.
git checkout -b "${BRANCH_NAME}"

# Stage the changes to sec-scanner-config.yaml and create a commit.
git add sec-scanners-config.yaml
git commit -m "auto-bump sec-scanners-config: ${PR_DATE}"

# Push the changes to origin, as defined earlier.
git push origin "$BRANCH_NAME"

# Create a PR.
BODY="This is an auto-generated PR to bump the sec-scanners-config.yml on ${REPO}."
PR_URL=$(gh pr create --base "main" --head "${BRANCH_NAME}" --title "chore: bump sec-scanners-config on main" --body "${BODY}")
echo "PR_URL=${PR_URL}" >> $GITHUB_ENV

- name: USER INTERACTION REQUIRED
if: ${{ env.CREATE_PR == 'true' }}
shell: bash
timeout-minutes: 60
env:
PR_URL: ${{ env.PR_URL }}
GH_TOKEN: ${{ secrets.BOT_PAT }}
run: |
echo "please review: ${PR_URL}"
./hack/ci/await-pr-merge.sh
10 changes: 5 additions & 5 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: 1.22 # This can be a specific version. E.g. 1.19 or 1.21.x

- name: Checkout code
uses: actions/checkout@v4
go-version-file: go.mod

- name: golangci-lint
uses: golangci/golangci-lint-action@v4.0.0
with:
version: v1.55
version: v1.57
2 changes: 1 addition & 1 deletion .github/workflows/sink.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.19
go-version-file: go.mod
cache: true

- name: Build
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ linters:
- testpackage
- wrapcheck
- paralleltest
- copyloopvar
- perfsprint

linters-settings:
stylecheck:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest
## Tool Versions
KUSTOMIZE_VERSION ?= v5.0.0
CONTROLLER_TOOLS_VERSION ?= v0.14.0
GOLANG_CI_LINT_VERSION ?= v1.55.2
GOLANG_CI_LINT_VERSION ?= v1.57

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand Down
2 changes: 1 addition & 1 deletion api/operator/v1alpha1/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func assertConditionsEqual(t *testing.T, expected, actual []kmetav1.Condition) {
t.Helper()

assert.Equal(t, len(expected), len(actual))
for i := 0; i < len(expected); i++ {
for i := range len(expected) {
assertConditionEqual(t, expected[i], actual[i])
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/errors/skip.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func IsSkippable(err error) bool {
if err == nil {
return true
}
_, ok := err.(skippable) //nolint:errorlint // here we do not want to check the chain
_, ok := err.(skippable)
return ok
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ func StartTestEnv(ens *Ensemble) error {
}
}),
)

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/operator/eventing/eventmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func Test_reconcileEventMeshSubManager(t *testing.T) {
// then
if testcase.wantError != nil {
require.Error(t, err)
require.ErrorAs(t, err, &testcase.wantError)
require.ErrorAs(t, err, &testcase.wantError) //nolint:testifylint // testifylint is disabled as it would not work without a pointer here
} else {
require.NoError(t, err)
require.NotNil(t, testEnv.Reconciler.eventMeshSubManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func Test_ReconcileSameEventingCR(t *testing.T) {
// Ensure reconciling the same Eventing CR multiple times does not update the EPP deployment.
const runs = 3
resourceVersionBefore := eppDeployment.ObjectMeta.ResourceVersion
for r := 0; r < runs; r++ {
for r := range runs {
// when
runID := fmt.Sprintf("run-%d", r)

Expand Down
2 changes: 1 addition & 1 deletion internal/controller/operator/eventing/nats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func Test_UpdateNatsConfig(t *testing.T) {

// then
require.Equal(t, testcase.expectedError, err)
require.Equal(t, testcase.expectedConfig, testcase.expectedConfig)
require.Equal(t, testcase.expectedConfig, natsConfig)
})
}
}
2 changes: 1 addition & 1 deletion pkg/backend/cleaner/eventmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (c *EventMeshCleaner) getMergedSegments(eventType string) string {
if totalSegments > maxEventMeshSegmentsLimit {
combinedSegment := ""
// combine the first n-2 segments without dots "."
for i := 0; i < totalSegments-2; i++ {
for i := range totalSegments - 2 {
combinedSegment += segments[i]
}
// append the last two segment with preceding dots "."
Expand Down
2 changes: 1 addition & 1 deletion pkg/backend/jetstream/config_internal_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestUnitValidate_For_Errors(t *testing.T) {

func fixtureStreamNameTooLong() string {
b := strings.Builder{}
for i := 0; i < (jsMaxStreamNameLength + 1); i++ {
for range jsMaxStreamNameLength + 1 {
b.WriteString("a")
}
streamName := b.String()
Expand Down
4 changes: 2 additions & 2 deletions pkg/backend/jetstream/jetstream_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,11 @@ func TestMultipleJSSubscriptionsToSameEvent(t *testing.T) {
types.ContentModeBinary),
)
// Check for the 3 events that should be received by the subscriber
for i := 0; i < len(subs); i++ {
for range len(subs) {
require.NoError(t, subscriber.CheckEvent(eventingtesting.CloudEventData))
}
// Delete all 3 subscription
for i := 0; i < len(subs); i++ {
for i := range len(subs) {
require.NoError(t, jsBackend.DeleteSubscription(subs[i]))
}
// Check if all subscriptions are deleted in NATS
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/utils_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestGetRandSuffix(t *testing.T) {
totalExecutions := 10
lengthOfRandomSuffix := 6
results := make(map[string]bool)
for i := 0; i < totalExecutions; i++ {
for range totalExecutions {
result := GetRandString(lengthOfRandomSuffix)
if _, ok := results[result]; ok {
t.Fatalf("generated string already exists: %s", result)
Expand Down
1 change: 0 additions & 1 deletion pkg/watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (w *ResourceWatcher) Start() {
UpdateFunc: w.updateFunc,
DeleteFunc: w.deleteFunc,
})

if err != nil {
runtime.HandleError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion test/utils/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ func (env TestEnvironment) TearDown() error {
// retry to stop the api-server
sleepTime := 1 * time.Second
const retries = 20
for i := 0; i < retries; i++ {
for range retries {
if err = env.EnvTestInstance.Stop(); err == nil {
break
}
Expand Down
2 changes: 1 addition & 1 deletion testing/eventmeshmock.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (m *EventMeshMock) handleMessaging() func(w http.ResponseWriter, r *http.Re

// extract get request key from /messaging/events/subscriptions/%s/state
key := strings.TrimSuffix(r.URL.Path, "/state")
for i := 0; i < 3; i++ {
for i := range 3 {
err := m.UpdateStateResponse(w, key, state)
if err == nil {
break
Expand Down
Loading