Skip to content

Commit

Permalink
ci: retrieve Go version from go.mod and ensure go.mod is tidied (#43)
Browse files Browse the repository at this point in the history
* retrieve go version to use from go.mod

this commit adds an extra step that parses the  file
to retrieve the correct Go version to use

Signed-off-by: Francesco Ilario <[email protected]>

* add go mod tidy check

Signed-off-by: Francesco Ilario <[email protected]>

* tidy go.mod

Signed-off-by: Francesco Ilario <[email protected]>

* fix outputs

Signed-off-by: Francesco Ilario <[email protected]>

* fix quotes on golangci version

Signed-off-by: Francesco Ilario <[email protected]>

---------

Signed-off-by: Francesco Ilario <[email protected]>
Co-authored-by: Andy Sadler <[email protected]>
  • Loading branch information
filariow and sadlerap authored Jan 28, 2025
1 parent d46c08a commit b9d11e1
Showing 1 changed file with 63 additions and 13 deletions.
76 changes: 63 additions & 13 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ jobs:
runs-on: ubuntu-24.04

steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Determine Go version
id: go_version
run: |
echo "version=$(go mod edit -json | jq -r '.Go')" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Checkout Git Repository
uses: actions/checkout@v4
go-version: ${{ steps.go_version.outputs.version }}

- name: Determine golang-ci version
run: make test
Expand All @@ -37,13 +42,18 @@ jobs:
- proxy: smart-proxy

steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Determine Go version
id: go_version
run: |
echo "version=$(go mod edit -json | jq -r '.Go')" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: Checkout Git Repository
uses: actions/checkout@v4
go-version: ${{ steps.go_version.outputs.version }}

- name: Run tests
env:
Expand All @@ -57,30 +67,70 @@ jobs:
make -C "acceptance/test/${{ matrix.proxy }}" test
echo "##[endgroup]"
lint-go:
name: Lint code
go-tidy:
name: Tidy go mod
runs-on: ubuntu-24.04

steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Determine Go version
id: go_version
run: |
echo "version=$(go mod edit -json | jq -r '.Go')" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"
go-version: ${{ steps.go_version.outputs.version }}

- name: Ensure go.mod is tidy
env:
SHA_FILE: ${{ runner.temp }}/go_mod_shas.txt"
run: |
# generate sha512 for go mod files
sha512sum go.mod go.sum > "${SHA_FILE}"
# run go mod tidy
go mod tidy -v
# check files were left untouched
sha512sum -c "${SHA_FILE}"
if [ "$?" != 0 ]; then
printf "please run go mod tidy to tidy the go.mod\n\n%s\n" "${output}"
exit 1
fi
lint-go:
name: Lint code
runs-on: ubuntu-24.04

steps:
- name: Checkout Git Repository
uses: actions/checkout@v4

- name: Determine Go version
id: go_version
run: |
echo "version=$(go mod edit -json | jq -r '.Go')" >> $GITHUB_OUTPUT
- name: Determine golang-ci version
id: golangci_version
run: |
echo "version=$(go mod edit -json hack/tools/golang-ci/go.mod | \
jq '.Require | map(select(.Path == "github.com/golangci/golangci-lint"))[].Version')" \
jq -r '.Require | map(select(.Path == "github.com/golangci/golangci-lint"))[].Version')" \

Check warning on line 122 in .github/workflows/ci.yaml

View workflow job for this annotation

GitHub Actions / Lint yaml manifests

122:101 [line-length] line too long (102 > 100 characters)
>> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ steps.go_version.outputs.version }}

- name: Lint with golang-ci
uses: golangci/golangci-lint-action@v6
with:
version: ${{ steps.golangci_version.version }}
version: ${{ steps.golangci_version.outputs.version }}
args: --timeout=5m

lint-yaml:
Expand Down

0 comments on commit b9d11e1

Please sign in to comment.