From efb6d5edffc5c68cd7da8e0e37e3803c4d546d00 Mon Sep 17 00:00:00 2001 From: Eliah Rusin Date: Tue, 26 Sep 2023 12:22:49 +0300 Subject: [PATCH] add actions (#1) * add actions * devcontainers * fmt * go 1.20 and 1.21 --- .devcontainer/devcontainer.json | 39 ++++++++++++++++ .gitattributes | 3 ++ .github/dependabot.yml | 18 ++++++++ .github/workflows/build.yml | 80 +++++++++++++++++++++++++++++++++ .github/workflows/lint.yml | 34 ++++++++++++++ .github/workflows/test.yml | 35 +++++++++++++++ .github/workflows/vuln.yml | 36 +++++++++++++++ README.md | 2 + go.mod | 3 ++ main.go | 5 +++ main_test.go | 9 ++++ 11 files changed, 264 insertions(+) create mode 100644 .devcontainer/devcontainer.json create mode 100644 .gitattributes create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/test.yml create mode 100644 .github/workflows/vuln.yml create mode 100644 go.mod create mode 100644 main.go create mode 100644 main_test.go diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..c63a500 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,39 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/go +{ + "name": "Go", + // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile + "image": "mcr.microsoft.com/devcontainers/go:1.21-bookworm", + + // Features to add to the dev container. More info: https://containers.dev/features. + // "features": {}, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + "settings": {}, + "extensions": [ + "streetsidesoftware.code-spell-checker" + ] + } + } + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [9000], + + // Use 'portsAttributes' to set default properties for specific forwarded ports. + // More info: https://containers.dev/implementors/json_reference/#port-attributes + // "portsAttributes": { + // "9000": { + // "label": "Hello Remote World", + // "onAutoForward": "notify" + // } + //} + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "go version", + + // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "root" +} \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5dc46e6 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..2139e05 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,18 @@ +version: 2 +updates: + - package-ecosystem: "gomod" + commit-message: + prefix: "deps:" + directory: "/" + schedule: + interval: "weekly" + day: "monday" + time: "12:00" + - package-ecosystem: "github-actions" + commit-message: + prefix: "deps:" + directory: "/" + schedule: + interval: "weekly" + day: "monday" + time: "12:00" \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..5291600 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,80 @@ +name: build + +permissions: {} # no need any permissions + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 10 * * 1' # run "At 10:00 on Monday" + workflow_call: + inputs: + skipTests: + description: 'Skip tests, useful when there is a dedicated CI job for tests' + default: false + required: false + type: boolean + +jobs: + run: + name: Build + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + fail-fast: true + matrix: + go: ['stable', 'oldstable'] + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + check-latest: true + + - name: Go Format + run: gofmt -s -w . && git diff --exit-code + + - name: Go Vet + run: go vet ./... + + - name: Go Tidy + run: go mod tidy && git diff --exit-code + + - name: Go Mod + run: go mod download + + - name: Go Mod Verify + run: go mod verify + + - name: Go Generate + run: go generate ./... && git diff --exit-code + + - name: Go Build + run: go build -o /dev/null ./... + + - name: Go Compile Tests + if: ${{ inputs.skipTests }} + run: go test -exec /bin/true ./... + + - name: Go Test + if: ${{ !inputs.skipTests }} + run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./... + + - name: Go Benchmark + if: ${{ !inputs.skipTests }} + run: go test -v -shuffle=on -run=- -bench=. -benchtime=1x ./... + + - name: Upload Coverage + if: ${{ !inputs.skipTests }} + uses: codecov/codecov-action@v3 + continue-on-error: true + with: + token: ${{secrets.CODECOV_TOKEN}} + file: ./coverage.txt + fail_ci_if_error: false \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..bac34b5 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,34 @@ +name: lint + +permissions: {} # no need any permissions + +on: + push: + branches: [main] + pull_request: + branches: [main] + workflow_call: + +jobs: + run: + name: Lint + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + fail-fast: true + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 'stable' + check-latest: true + + - name: Lint + uses: golangci/golangci-lint-action@v3.7.0 + with: + version: latest + args: --timeout 5m \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..33d59b6 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,35 @@ +name: test + +on: + workflow_call: + +jobs: + run: + name: Test + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + fail-fast: true + matrix: + go: ['stable', 'oldstable'] + + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: ${{ matrix.go }} + check-latest: true + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run tests + run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./... + + - name: Upload Coverage + uses: codecov/codecov-action@v3 + continue-on-error: true + with: + token: ${{secrets.CODECOV_TOKEN}} + file: ./coverage.txt + fail_ci_if_error: false \ No newline at end of file diff --git a/.github/workflows/vuln.yml b/.github/workflows/vuln.yml new file mode 100644 index 0000000..a4d901e --- /dev/null +++ b/.github/workflows/vuln.yml @@ -0,0 +1,36 @@ +name: vuln + +permissions: {} # no need any permissions + +on: + push: + branches: [main] + pull_request: + branches: [main] + schedule: + - cron: '0 10 * * 1' # run "At 10:00 on Monday" + workflow_call: + +jobs: + run: + name: Vuln + runs-on: ubuntu-latest + timeout-minutes: 5 + strategy: + fail-fast: true + + steps: + - name: Install Go + uses: actions/setup-go@v4 + with: + go-version: 'stable' + check-latest: true + + - name: Checkout + uses: actions/checkout@v4 + + - name: Install govulncheck + run: go install golang.org/x/vuln/cmd/govulncheck@latest + + - name: Run govulncheck + run: govulncheck -test ./... \ No newline at end of file diff --git a/README.md b/README.md index 77c6c3d..861fc6a 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # .github-go GitHub actions for Go projects + +See [Reusing Workflows](https://docs.github.com/en/actions/using-workflows/reusing-workflows) diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8154671 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/franchb/.github-go + +go 1.20 diff --git a/main.go b/main.go new file mode 100644 index 0000000..4dfbbf7 --- /dev/null +++ b/main.go @@ -0,0 +1,5 @@ +package main + +func main() { + println("github.com/franchb/.github-go ready") +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..c139e53 --- /dev/null +++ b/main_test.go @@ -0,0 +1,9 @@ +package main + +import "testing" + +func TestSimple(t *testing.T) { + if 0 == 1 { + t.Fatal("impossible") + } +}