Skip to content

Commit df19461

Browse files
BCDA-9225: Reconfigure golang linting (#1155)
## 🎫 Ticket https://jira.cms.gov/browse/BCDA-9225 ## πŸ›  Changes - configured the standard golangci-lint pre-commit hook to replace the wrapper hook we had been using before - set predefined versions for our linters that we can update ourselves (this version management may change when we upgrade to go 1.24) - updated configuration of ci linter to specifically lint the changes that are different from main - configured setup-go job to fetch the go version from go.mod in all workflows - changed create-group integration test to hard delete created group instead of soft delete <!-- What was added, updated, or removed in this PR? --> ## ℹ️ Context There are two golang-ci linters configured for this repo: one in a pre-commit hook, and one in a docker container which is run by a make command during ci-checks. The goals for my changes here were the following: - reduce the number of false positives with pre-commit linting errors. this was addressed by changing the pre-commit linting scope from "every package of every updated file" to "every updated line" -- there was clearly something buggy about the former, but I'm not quite sure what it was. - bring the pre-commit and the ci-checks linters closer together with respect to their versions and the results they create - ensure that the pre-commit linter does not take too long - define a set version for the linters that we can increment manually, so as to increase the stability of our ci workflow - only lint new changes for a specific commit during the pre-commit hook - lint all changes to main for the PR linter Also for the create-group integration test, it turns out soft deleting the group is not enough to make the test re-runnable ## πŸ§ͺ Validation for the linters: 1. create a new branch from this branch 2. make an update to any go file with a linting error. when you try to commit, the pre-commit hook should catch the error and not raise a bunch of false positives 3. commit the error from step 2 with `go commit --no-verify` and push the branch. verify that the `ci-checks` workflow catches the error for the create-group workflow: 1. run the workflow and verify that it passes 2. immediately re-run the workflow and verify that it passes again <!-- How were the changes verified? Did you fully test the acceptance criteria in the ticket? Provide reproducible testing instructions and screenshots if applicable. -->
1 parent ff2249a commit df19461

12 files changed

+23
-23
lines changed

β€Ž.github/workflows/admin-aco-deny-deploy.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- uses: actions/checkout@v4
3535
- uses: actions/setup-go@v5
3636
with:
37-
go-version: '1.23.1'
37+
go-version-file: 'go.mod'
3838
- name: Build admin-aco-deny zip file
3939
env:
4040
CGO_ENABLED: 0

β€Ž.github/workflows/admin-create-aco-creds-deploy.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@v4
4141
- uses: actions/setup-go@v5
4242
with:
43-
go-version: '1.23.1'
43+
go-version-file: 'go.mod'
4444
- name: Build admin-create-aco-creds zip file
4545
env:
4646
CGO_ENABLED: 0

β€Ž.github/workflows/admin-create-aco-deploy.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@v4
4141
- uses: actions/setup-go@v5
4242
with:
43-
go-version: '1.23.1'
43+
go-version-file: 'go.mod'
4444
- name: Build admin_create_aco zip file
4545
env:
4646
CGO_ENABLED: 0

β€Ž.github/workflows/admin-create-group-deploy.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
- uses: actions/checkout@v4
3636
- uses: actions/setup-go@v5
3737
with:
38-
go-version: '1.23.1'
38+
go-version-file: 'go.mod'
3939
- name: Build create-group zip file
4040
env:
4141
CGO_ENABLED: 0

β€Ž.github/workflows/admin-create-group-integration-test.ymlβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,15 @@ jobs:
7979
run: |
8080
HOST=$(aws rds describe-db-instances --db-instance-identifier bcda-dev 2>&1 | jq -r '.DBInstances[0].Endpoint.Address' 2>&1)
8181
CONNECTION_URL=$(echo $CONNECTION_INFO 2>&1 | sed -E "s/@.*\/bcda/\@$HOST\/bcda/" 2>&1)
82-
GROUP_COUNT=`psql -tA "$CONNECTION_URL" -c "SELECT COUNT(*) FROM groups WHERE group_id='${{ env.GROUP }}' AND deleted_at IS NULL" 2>&1`
82+
GROUP_COUNT=`psql -tA "$CONNECTION_URL" -c "SELECT COUNT(*) FROM groups WHERE group_id='${{ env.GROUP }}' " 2>&1`
8383
if [[ $? -ne 0 || $GROUP_COUNT -ne 1 ]]; then
8484
echo "number of groups with group_id = ${{ env.GROUP }} not equal to 1"
8585
echo "matching number of groups: $GROUP_COUNT"
8686
exit 1
8787
fi
88-
UPDATED_COUNT=`psql -tA "$CONNECTION_URL" -c "UPDATE groups SET deleted_at=NOW() WHERE group_id = '${{ env.GROUP }}' AND deleted_at IS NULL" 2>&1`
89-
if [[ $? -ne 0 || $UPDATED_COUNT != "UPDATE 1" ]]; then
90-
echo "group deletion command failed"
91-
echo "deletion command results: $UPDATED_COUNT"
88+
DELETED_COUNT=`psql -tA "$CONNECTION_URL" -c "DELETE FROM groups WHERE group_id='${{ env.GROUP }}' " 2>&1`
89+
if [[ $? -ne 0 || $DELETED_COUNT != "DELETE 1" ]]; then
90+
echo "group deletion command failed; DELETED_COUNT does not match expected result"
91+
echo "deletion command results: $DELETED_COUNT"
9292
exit 1
9393
fi

β€Ž.github/workflows/cclf-import-deploy.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- uses: actions/checkout@v4
4545
- uses: actions/setup-go@v5
4646
with:
47-
go-version: '1.23.1'
47+
go-version-file: 'go.mod'
4848
- name: Build cclf-import zip file
4949
env:
5050
CGO_ENABLED: 0

β€Ž.github/workflows/ci-checks.ymlβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Get Go # TEMP
3535
uses: actions/setup-go@v5
3636
with:
37-
go-version: '>=1.23.1'
37+
go-version-file: 'go.mod'
3838
- name: Tidy modules
3939
run: |
4040
go mod tidy -v
@@ -49,15 +49,15 @@ jobs:
4949
name: Lint and Test
5050
runs-on: codebuild-bcda-app-${{github.run_id}}-${{github.run_attempt}}
5151
steps:
52-
- name: Get Go
53-
uses: actions/setup-go@v5
54-
with:
55-
go-version: '>=1.23.1'
5652
- name: Checkout code
5753
uses: actions/checkout@v4
5854
with:
5955
repository: CMSgov/bcda-app
6056
ref: ${{ env.RELEASE_VERSION }}
57+
- name: Get Go
58+
uses: actions/setup-go@v5
59+
with:
60+
go-version-file: 'go.mod'
6161
- name: Install Ansible
6262
run: |
6363
sudo yum update -y

β€Ž.github/workflows/migrate-db.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- name: Get Go
5858
uses: actions/setup-go@v5
5959
with:
60-
go-version: '>=1.23.6'
60+
go-version-file: 'go.mod'
6161
- name: Get golang-migrate
6262
run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
6363
- name: Migrate DB

β€Ž.github/workflows/opt-out-import-deploy.ymlβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- uses: actions/checkout@v4
4545
- uses: actions/setup-go@v5
4646
with:
47-
go-version: '1.23.1'
47+
go-version-file: 'go.mod'
4848
- name: Build opt-out-import zip file
4949
env:
5050
CGO_ENABLED: 0

β€Ž.pre-commit-config.yamlβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ repos:
33
rev: v8.19.2
44
hooks:
55
- id: gitleaks
6-
- repo: https://github.com/tekwizely/pre-commit-golang
7-
rev: v1.0.0-rc.1
6+
- repo: https://github.com/golangci/golangci-lint
7+
rev: v2.2.1
88
hooks:
9-
- id: golangci-lint-pkg
10-
args: ['--new', '-v']
9+
- id: golangci-lint
10+
args: ['--new', '-v', '--fast-only']

0 commit comments

Comments
Β (0)