From 466fed6f358d2c44d19cb4d4e0476bf13cbe8887 Mon Sep 17 00:00:00 2001 From: Jamie Tanna Date: Mon, 28 Aug 2023 17:01:49 +0100 Subject: [PATCH] Add GitHub Actions Workflows + Dependabot configuration From oapi-codegen@3650493c4657605703acbcd5d6461a448939cbd1. Plus removal of the `go build` for the CLI, and the required `Makefile`. --- .github/dependabot.yml | 7 +++++++ .github/workflows/ci.yml | 17 +++++++++++++++++ .github/workflows/generate.yml | 20 ++++++++++++++++++++ .github/workflows/lint.yml | 17 +++++++++++++++++ .github/workflows/tidy.yml | 20 ++++++++++++++++++++ Makefile | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 113 insertions(+) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/generate.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/tidy.yml create mode 100644 Makefile diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..61bacceb --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..b077c999 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,17 @@ +name: Build project +on: [ push, pull_request ] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + + - name: Test + run: make test diff --git a/.github/workflows/generate.yml b/.github/workflows/generate.yml new file mode 100644 index 00000000..e6d92b67 --- /dev/null +++ b/.github/workflows/generate.yml @@ -0,0 +1,20 @@ +name: Ensure generated files are up-to-date +on: [ push, pull_request ] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + + - name: Run `make generate` + run: make generate + + - name: Check for no untracked files + run: git status && git diff-index --quiet HEAD -- diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..95b5166c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,17 @@ +name: Lint project +on: [push, pull_request] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + + - name: Run `make lint-ci` + run: make lint-ci diff --git a/.github/workflows/tidy.yml b/.github/workflows/tidy.yml new file mode 100644 index 00000000..8863c542 --- /dev/null +++ b/.github/workflows/tidy.yml @@ -0,0 +1,20 @@ +name: Ensure `go mod tidy` has been run +on: [ push, pull_request ] +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version-file: 'go.mod' + + - name: Install `tidied` + run: go install gitlab.com/jamietanna/tidied@latest + + - name: Check for no untracked files + run: tidied -verbose diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..05871ef1 --- /dev/null +++ b/Makefile @@ -0,0 +1,32 @@ +GOBASE=$(shell pwd) +GOBIN=$(GOBASE)/bin + +help: + @echo "This is a helper makefile for oapi-codegen" + @echo "Targets:" + @echo " generate: regenerate all generated files" + @echo " test: run all tests" + @echo " gin_example generate gin example server code" + @echo " tidy tidy go mod" + +$(GOBIN)/golangci-lint: + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.54.0 + +.PHONY: tools +tools: $(GOBIN)/golangci-lint + +lint: tools + $(GOBIN)/golangci-lint run ./... + +lint-ci: tools + $(GOBIN)/golangci-lint run ./... --out-format=github-actions --timeout=5m + +generate: + go generate ./... + +test: + go test -cover ./... + +tidy: + @echo "tidy..." + go mod tidy