From 52c033f4a87abe178bfb2d9e72fa70945e906714 Mon Sep 17 00:00:00 2001 From: Marin Nozhchev Date: Mon, 28 Apr 2025 21:31:12 +0300 Subject: [PATCH] Initial commit for template --- .github/workflows/ci.yml | 45 +++++++++++++++++++++++ .github/workflows/golangci-lint.yml | 55 +++++++++++++++++++++++++++++ .gitignore | 1 + .golangci.yml | 1 + Makefile | 28 +++++++++++++++ go.go | 5 +++ go.mod | 11 ++++++ go.sum | 10 ++++++ go_test.go | 11 ++++++ 9 files changed, 167 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .golangci.yml create mode 100644 Makefile create mode 100644 go.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 go_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2369f4e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,45 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: tests + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + + e2e: + # Only ubuntu allows for docker support - https://docs.github.com/en/actions/using-containerized-services/about-service-containers + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4.2.2 + + - name: Set up Go + uses: actions/setup-go@v5.3.0 + with: + go-version: '1.24' + + - name: Build + run: go build -v ./... + - name: Test + run: | + sudo apt-get install moreutils -y + make test + + # platforms: + # runs-on: ${{ matrix.os }} + # strategy: + # matrix: + # os: + # - "windows-latest" + # - "macos-latest" + # steps: + # - uses: actions/checkout@v4.2.2 + # - uses: actions/setup-go@v5.3.0 + # with: + # go-version: '1.24' + # - name: Test + # run: make short-test \ No newline at end of file diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..9242964 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,55 @@ +name: golangci-lint +on: + push: + branches: + - master + - main + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '1.24' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v7 + with: + # Require: The version of golangci-lint to use. + # When `install-mode` is `binary` (default) the value can be v1.2 or v1.2.3 or `latest` to use the latest version. + # When `install-mode` is `goinstall` the value can be v1.2.3, `latest`, or the hash of a commit. + version: v2.1.1 + + # Optional: working directory, useful for monorepos + # working-directory: somedir + + # Optional: golangci-lint command line arguments. + # + # Note: By default, the `.golangci.yml` file should be at the root of the repository. + # The location of the configuration file can be changed by using `--config=` + # args: --timeout=30m --config=/my/path/.golangci.yml --issues-exit-code=0 + + # Optional: show only new issues if it's a pull request. The default value is `false`. + # only-new-issues: true + + # Optional: if set to true, then all caching functionality will be completely disabled, + # takes precedence over all other caching options. + # skip-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/go/pkg. + # skip-pkg-cache: true + + # Optional: if set to true, then the action won't cache or restore ~/.cache/go-build. + # skip-build-cache: true + + # Optional: The mode to install golangci-lint. It can be 'binary' or 'goinstall'. + # install-mode: "goinstall" \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6f72f89..05ca3b9 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,4 @@ go.work.sum # env file .env +/coverage \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..26b4afd --- /dev/null +++ b/.golangci.yml @@ -0,0 +1 @@ +version: "2" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef147ca --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +.PHONY: build +build: + go build . + +test: + mkdir -p coverage/covdata +# Use the new binary format to ensure integration tests and cross-package calls are counted towards coverage +# https://go.dev/blog/integration-test-coverage +# -p 1 disable parallel testing in favor of streaming log output - https://github.com/golang/go/issues/24929#issuecomment-384484654 + go test -race -cover -covermode atomic -v -vet=all -timeout 15m -p 1\ + ./... \ + -args -test.gocoverdir="${PWD}/coverage/covdata" \ + | ts -s +# NB: ts command requires moreutils package; awk trick from https://stackoverflow.com/a/25764579 doesn't stream output + go tool covdata percent -i=./coverage/covdata + # Convert to old text format for coveralls upload + go tool covdata textfmt -i=./coverage/covdata -o ./coverage/covprofile + go tool cover -html=./coverage/covprofile -o ./coverage/coverage.html + +.PHONY: short-test +short-test: + go test -v -short ./... + +.PHONY: lint +lint: + golangci-lint run -v + + diff --git a/go.go b/go.go new file mode 100644 index 0000000..643f397 --- /dev/null +++ b/go.go @@ -0,0 +1,5 @@ +package template + +func hello() string { + return "hello world" +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..627d7a6 --- /dev/null +++ b/go.mod @@ -0,0 +1,11 @@ +module github.com/sclgo/template + +go 1.24.1 + +require github.com/stretchr/testify v1.10.0 + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..713a0b4 --- /dev/null +++ b/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/go_test.go b/go_test.go new file mode 100644 index 0000000..e29f9c7 --- /dev/null +++ b/go_test.go @@ -0,0 +1,11 @@ +package template + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestHello(t *testing.T) { + require.Equal(t, "hello world", hello()) +}