diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..6425b3bb --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,87 @@ +name: Tests and Linters Scalingo go-utils Packages + +on: [push] + +# # The list of permissions is explained on the GitHub doc: +# # https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs +# permissions: +# # allow read access to pull request. Use with golangci-lint `only-new-issues` option. +# pull-requests: read + +jobs: + detect-modules: + name: Detect the Go modules declared in go-utils + runs-on: ubuntu-22.04 + outputs: + modules: ${{ steps.set-modules.outputs.modules }} + steps: + - uses: actions/checkout@v4 + with: + # We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch + fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version: stable + check-latest: true + - id: set-modules + run: | + echo -n "modules=" > $GITHUB_OUTPUT + for m in ./*/*go.mod; do + pushd $(dirname "$m") > /dev/null + module_path="$(go list -m -json | jq --slurp '.' | jq --compact-output --raw-output '.[].Dir')" + echo $module_path + popd > /dev/null + done | jq --raw-input --slurp 'split("\n")' | jq --compact-output 'map(select(length > 0))' >> $GITHUB_OUTPUT + + linter-pull-request: + needs: detect-modules + name: golangci-lint on a PR or from a tag + runs-on: ubuntu-22.04 + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + if: github.ref != 'refs/heads/master' + steps: + - uses: actions/checkout@v4 + with: + # We need to define the fetch-depth to 0 so that we can get the commit ID of the master branch + fetch-depth: 0 + - uses: actions/setup-go@v5 + with: + go-version: stable + check-latest: true + - name: Get golangci-lint configuration file + run: wget --output-document=$(pwd)/.golangci.yml https://sc-devtools.s3.eu-west-1.amazonaws.com/golang-ci/golangci.yml + - name: Get master branch commit ID + id: new-from-rev + run: echo "NEW_FROM_REV=$( git rev-parse origin/master )" >> "$GITHUB_OUTPUT" + - name: "Execute golangci-lint on a pull request" + uses: golangci/golangci-lint-action@v6 + with: + working-directory: ${{ matrix.modules }} + # The `only-new-issues` flag is not working (https://github.com/golangci/golangci-lint-action/issues/531). + # We rather decided to use the suggestion from the FAQ (https://golangci-lint.run/welcome/faq/#how-to-integrate-golangci-lint-into-large-project-with-thousands-of-issues) and use `--new-from-rev` + # only-new-issues: false + args: "--config=$(pwd)/../.golangci.yml --new-from-rev=${{ steps.new-from-rev.outputs.NEW_FROM_REV }} --modules-download-mode=mod" + + + tests: + needs: detect-modules + name: Unit Tests + runs-on: ubuntu-22.04 + strategy: + matrix: + modules: ${{ fromJSON(needs.detect-modules.outputs.modules) }} + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: stable + check-latest: true + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.12.0 + with: + mongodb-version: 4.0.3 + - name: Execute the tests + working-directory: ${{ matrix.modules }} + run: go test -race ./... diff --git a/cronsetup/go.mod b/cronsetup/go.mod index a560d123..b9514a9a 100644 --- a/cronsetup/go.mod +++ b/cronsetup/go.mod @@ -1,6 +1,7 @@ module github.com/Scalingo/go-utils/cronsetup -go 1.22 +go 1.23.0 + toolchain go1.23.7 require ( diff --git a/difflib/difflib_test.go b/difflib/difflib_test.go index d7251196..60fb1f9c 100644 --- a/difflib/difflib_test.go +++ b/difflib/difflib_test.go @@ -102,7 +102,7 @@ group } } -func ExampleGetUnifiedDiffCode() { +func ExampleGetUnifiedDiffString() { a := `one two three @@ -135,7 +135,7 @@ four` // -fmt.Printf("%s,%T",a,b) } -func ExampleGetContextDiffCode() { +func ExampleGetContextDiffString() { a := `one two three @@ -172,7 +172,7 @@ four` // four } -func ExampleGetContextDiffString() { +func ExampleGetContextDiffString_second() { a := `one two three diff --git a/etcd/go.mod b/etcd/go.mod index 3ab3684e..1c9309e6 100644 --- a/etcd/go.mod +++ b/etcd/go.mod @@ -1,6 +1,7 @@ module github.com/Scalingo/go-utils/etcd -go 1.22 +go 1.23.0 + toolchain go1.23.7 require ( diff --git a/fs/go.mod b/fs/go.mod index 439d91eb..a0871cb1 100644 --- a/fs/go.mod +++ b/fs/go.mod @@ -1,6 +1,8 @@ module github.com/Scalingo/go-utils/fs -go 1.20 +go 1.21 + +toolchain go1.23.5 require github.com/spf13/afero v1.12.0