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

ci: retrieve Go version from go.mod and ensure go.mod is tidied #43

Merged
merged 7 commits into from
Jan 28, 2025
Merged
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
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 @@
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 @@
- 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 @@
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