diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e55bc2c..0106fdd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 @@ -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: @@ -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')" \ >> $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: