From 1315dc46387bb37a82dd82cc96fcad3ea06bb7b8 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Thu, 25 Jan 2024 16:08:33 -0600 Subject: [PATCH] Add CI/CD --- .github/workflows/audit.yml | 45 ++++++++++++++++++++ .github/workflows/cover-badge.yml | 65 +++++++++++++++++++++++++++++ .github/workflows/golangci-lint.yml | 57 +++++++++++++++++++++++++ 3 files changed, 167 insertions(+) create mode 100644 .github/workflows/audit.yml create mode 100644 .github/workflows/cover-badge.yml create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/audit.yml b/.github/workflows/audit.yml new file mode 100644 index 0000000..73c7e0b --- /dev/null +++ b/.github/workflows/audit.yml @@ -0,0 +1,45 @@ +name: Audit + +on: + push: + branches: [main, robadams-fix-ci] + pull_request: + branches: [main] + +jobs: + audit: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.20.5 + + - name: Verify dependencies + run: go verify ./... + + - name: Run gofmt + run: test -z $$(gofmt -l .) + + - name: Build + run: go build ./... + + - name: Run go vet + run: go vet ./... + + - name: Detect ineffectual assignments + run: go run github.com/gordonklaus/ineffassign@latest ./... + + - name: Run staticcheck + run: go run honnef.co/go/tools/cmd/staticcheck@latest -checks=all,-ST1000,-U1000 ./... + + - name: Run vulncheck + run: go run golang.org/x/vuln/cmd/govulncheck@latest ./... + + - name: Run golint + run: go run github.com/mgechev/revive@latest -set_exit_status ./... + + - name: Run tests + run: go test -race -buildvcs -vet=off ./... diff --git a/.github/workflows/cover-badge.yml b/.github/workflows/cover-badge.yml new file mode 100644 index 0000000..f2f2097 --- /dev/null +++ b/.github/workflows/cover-badge.yml @@ -0,0 +1,65 @@ +name: Generate code coverage badge + +on: + push: + branches: + - main + - robadams-fix-ci + pull_request: + branches: + - main + - robadams-fix-ci + +jobs: + test: + runs-on: ubuntu-latest + name: Update coverage badge + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal access token. + fetch-depth: 0 # otherwise, there would be errors pushing refs to the destination repository. + + - name: Setup go + uses: actions/setup-go@v4 + with: + go-version: '1.20.5' + + - uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run Test + run: | + go test -v ./... -covermode=count -coverprofile=coverage.out + go tool cover -func=coverage.out -o=coverage.out + + - name: Go Coverage Badge # Pass the `coverage.out` output to this action + uses: tj-actions/coverage-badge-go@v2 + with: + filename: coverage.out + + - name: Verify Changed files + uses: tj-actions/verify-changed-files@v12 + id: verify-changed-files + with: + files: README.md + + - name: Commit changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git add README.md + git commit -m "chore: Updated coverage badge." + + - name: Push changes + if: steps.verify-changed-files.outputs.files_changed == 'true' + uses: ad-m/github-push-action@master + with: + github_token: ${{ github.token }} + branch: ${{ github.head_ref }} diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..6ba84e9 --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,57 @@ +name: golangci-lint +on: + push: + branches: + - master + - main + - robadams-fix-ci + 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@v3 + - uses: actions/setup-go@v4 + with: + go-version: '1.20' + cache: false + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + 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: v1.53 + + # 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 + args: -E misspell -E revive --exclude-use-default=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"