From 33b4df319d69d55f39254115d533e7a1825edaac Mon Sep 17 00:00:00 2001 From: Johannes Eiglsperger Date: Wed, 10 Apr 2024 12:09:44 +0200 Subject: [PATCH] Refactor workflows --- .github/workflows/build.yml | 22 +++++++++++++++ .github/workflows/golangci-lint.yml | 24 ++++++++++++++++ .github/workflows/lint.yml | 24 ++++++++++++++++ .github/workflows/staticcheck.yml | 23 +++++++++++++++ .github/workflows/test.yml | 23 +++++++++++++++ .github/workflows/tests.yml | 43 ----------------------------- .gitignore | 2 +- Makefile | 4 +-- README.md | 1 - 9 files changed, 119 insertions(+), 47 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/golangci-lint.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/staticcheck.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..6aa9110 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +--- +name: build +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: +concurrency: + group: "${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}" + cancel-in-progress: true +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - run: go build ./cmd/dyndns-pdns diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..2f5aade --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,24 @@ +--- +name: golangci-lint +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: +concurrency: + group: "${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}" + cancel-in-progress: true +jobs: + golangci-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - uses: golangci/golangci-lint-action@v4 + with: + version: v1.57.2 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..b29c647 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,24 @@ +--- +name: lint +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: +concurrency: + group: "${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}" + cancel-in-progress: true +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - run: | + gofmt -d . + test -z $(gofmt -l .) diff --git a/.github/workflows/staticcheck.yml b/.github/workflows/staticcheck.yml new file mode 100644 index 0000000..e74b133 --- /dev/null +++ b/.github/workflows/staticcheck.yml @@ -0,0 +1,23 @@ +--- +name: staticcheck +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: +concurrency: + group: "${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}" + cancel-in-progress: true +jobs: + staticcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - run: go install honnef.co/go/tools/cmd/staticcheck@latest + - run: $(go env GOPATH)/bin/staticcheck ./... diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..23d6048 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,23 @@ +--- +name: test +on: + push: + branches: + - main + pull_request: + branches: + - main + workflow_dispatch: +concurrency: + group: "${{ github.workflow }}-$${{ github.pull_request.number || github.run_id }}" + cancel-in-progress: true +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: "go.mod" + - run: go test -v -coverprofile="coverage.out" ./... + - run: go tool cover -func="coverage.out" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml deleted file mode 100644 index 680e241..0000000 --- a/.github/workflows/tests.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -name: Tests -on: - pull_request: - branches: - - main - push: - branches: - - main -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - name: Set up Go ${{ matrix.goVer }} - uses: actions/setup-go@v5 - with: - go-version: "1.21" - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: golangci-lint - uses: golangci/golangci-lint-action@v4 - with: - version: v1.55.2 - - name: Staticcheck - run: | - go install honnef.co/go/tools/cmd/staticcheck@latest - $(go env GOPATH)/bin/staticcheck ./... - test: - name: Test - runs-on: ubuntu-latest - strategy: - matrix: - goVer: ["1.21"] - steps: - - name: Set up Go ${{ matrix.goVer }} - uses: actions/setup-go@v5 - with: - go-version: ${{ matrix.goVer }} - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - name: Make - run: make diff --git a/.gitignore b/.gitignore index b982541..b86dfe7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ /configs/server.crt /configs/server.csr /configs/server.key -/c.out +/coverage.out /dyndns-pdns /dyndns-pdns_linux_amd64 /vendor/ diff --git a/Makefile b/Makefile index df3b1d3..43f03e7 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,10 @@ build-linux-amd64: GOOS=linux GOARCH=amd64 $(GOBUILD) -o $(BINARY_NAME)_linux_amd64 -v ./cmd/dyndns-pdns test: - $(GOTEST) -v ./... -covermode=count -coverprofile=c.out + $(GOTEST) -v ./... -covermode=count -coverprofile=coverage.out coverage: - $(GOCOVER) -func=c.out + $(GOCOVER) -func=coverage.out check-fmt: $(GOFMT) -d ${GOFILES} diff --git a/README.md b/README.md index 538f790..c485ea4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ Collects IPv4/IPv6 addresses of network devices (routers, firewalls etc.) and writes the corresponding PowerDNS resource records. -[![Tests](https://github.com/joeig/dyndns-pdns/actions/workflows/tests.yml/badge.svg)](https://github.com/joeig/dyndns-pdns/actions/workflows/tests.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/joeig/dyndns-pdns)](https://goreportcard.com/report/github.com/joeig/dyndns-pdns) ## Setup