Skip to content

Commit

Permalink
Merge pull request #26 from ccremer/polishing
Browse files Browse the repository at this point in the history
Update project plumbing
  • Loading branch information
ccremer authored May 22, 2021
2 parents 4866dfc + 20c7c94 commit 791ad26
Show file tree
Hide file tree
Showing 19 changed files with 242 additions and 149 deletions.
19 changes: 19 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Summary



## Checklist

- [ ] Keep pull requests small so they can be easily reviewed.
- [ ] Categorize the PR by setting a good title and adding one of the labels:
`fix`, `enhancement`, `documentation`, `change`, `breaking`, `dependency`
as they show up in the changelog
- [ ] Update documentation.
- [ ] Update tests.
- [ ] Link this PR to related issues.

<!--
Remove items that do not apply. For completed items, change [ ] to [x].
These things are not required to open a PR and can be done afterwards,
while the PR is open.
-->
30 changes: 30 additions & 0 deletions .github/changelog-configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"pr_template": "- ${{TITLE}} (#${{NUMBER}})",
"categories": [
{
"title": "## 🚀 Features",
"labels": ["enhancement", "feature"]
},
{
"title": "## 🛠️ Minor Changes",
"labels": ["change"]
},
{
"title": "## 🔎 Breaking Changes",
"labels": ["breaking"]
},
{
"title": "## 🐛 Fixes",
"labels": ["bug", "fix"]
},
{
"title": "## 📄 Documentation",
"labels": ["documentation"]
},
{
"title": "## 🔗 Dependency Updates",
"labels": ["dependency"]
}
],
"template": "${{CATEGORIZED_COUNT}} changes since ${{FROM_TAG}}\n\n${{CHANGELOG}}"
}
61 changes: 8 additions & 53 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,17 @@
name: Build

on:
push:
branches:
- "*"
tags-ignore:
- "*"
pull_request:
types: [opened, reopened]

env:
GO_VERSION: "^1.14.3"
branches:
- master

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: goreleaser/goreleaser-action@v2
with:
args: release --snapshot --skip-sign

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Test & Publish Code Coverage
uses: paambaati/codeclimate-action@v2.6.0
env:
CC_TEST_REPORTER_ID: 38a41dde51e26878e774848c2654bba1082ad39703571505e877575b2a9695e3
with:
coverageCommand: make test
prefix: ${{ github.event.repository.name }}
coverageLocations:
"${{github.workspace}}/c.out:gocov"

formatting:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
Expand All @@ -66,5 +21,5 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Verify if Code needs formatting
run: make fmt
- name: Run docker build
run: make build:docker
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint

on:
pull_request: {}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run linters
run: make lint
40 changes: 31 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ on:
tags:
- "*"

env:
GO_VERSION: "^1.14.3"

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
Expand All @@ -23,14 +24,35 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Import GPG signing key
uses: crazy-max/ghaction-import-gpg@v1
uses: crazy-max/ghaction-import-gpg@v3
with:
gpg-private-key: ${{ secrets.SIGNING_KEY }}
- name: Login to docker.io
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Login to quay.io
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_IO_USER }}
password: ${{ secrets.QUAY_IO_PASSWORD }}
- name: Build changelog from PRs with labels
id: build_changelog
uses: mikepenz/release-changelog-builder-action@v1
with:
configuration: ".github/changelog-configuration.json"
# PreReleases still get a changelog, but the next full release gets a diff since the last full release,
# combining possible changelogs of all previous PreReleases in between. PreReleases show a partial changelog
# since last PreRelease.
ignorePreReleases: "${{ !contains(github.ref, '-rc') }}"
outputFile: .github/release-notes.md
env:
GPG_PRIVATE_KEY: ${{ secrets.SIGNING_KEY }}
- name: Login to Docker hub
run: docker login -u ${{ secrets.DOCKER_HUB_USER }} -p ${{ secrets.DOCKER_HUB_PASSWORD }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish releases
uses: goreleaser/goreleaser-action@v2
with:
args: release
args: release --release-notes .github/release-notes.md
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Test

on:
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Determine Go version from go.mod
run: echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
- uses: actions/setup-go@v2
with:
go-version: ${{ env.GO_VERSION }}
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run tests
run: make test
- name: Upload code coverage report to Code Climate
uses: paambaati/codeclimate-action@v2.7.5
env:
CC_TEST_REPORTER_ID: 38a41dde51e26878e774848c2654bba1082ad39703571505e877575b2a9695e3
with:
coverageLocations: cover.out:gocov
prefix: github.com/${{ github.repository }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
# Binaries and dists
/fronius-exporter
/dist
/.github/release-notes.md
21 changes: 10 additions & 11 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ signs:
dockers:
- image_templates:
- "docker.io/ccremer/fronius-exporter:v{{ .Version }}"
- "docker.io/ccremer/fronius-exporter:v{{ .Major }}"
- "quay.io/ccremer/fronius-exporter:v{{ .Version }}"

# For prereleases, updating `latest` and the floating tags of the major version does not make sense.
# Only the image for the exact version should be pushed.
- "{{ if not .Prerelease }}docker.io/ccremer/fronius-exporter:v{{ .Major }}{{ end }}"
- "{{ if not .Prerelease }}quay.io/ccremer/fronius-exporter:v{{ .Major }}{{ end }}"

- "{{ if not .Prerelease }}docker.io/ccremer/fronius-exporter:latest{{ end }}"
- "{{ if not .Prerelease }}quay.io/ccremer/fronius-exporter:latest{{ end }}"

nfpms:
- vendor: ccremer
Expand All @@ -38,17 +46,8 @@ nfpms:
- deb
- rpm

changelog:
sort: asc
filters:
exclude:
- '^Docs:'
- '^Test:'
- '^Refactor:'
- '^Merge pull request'
- '^GH:'

release:
prerelease: auto
github:
owner: ccremer
name: fronius-exporter
52 changes: 41 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,50 @@
.PHONY: build fmt dist clean test run
SHELL := /usr/bin/env bash

build: fmt
# Disable built-in rules
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
.SUFFIXES:
.SECONDARY:

include Makefile.vars.mk

.DEFAULT_GOAL := help
.PHONY: help
help: ## Show this help
@grep -E -h '\s##\s' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = "(: ).*?## "}; {gsub(/\\:/,":",$$1)}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

.PHONY: build
build: export GOOS = linux
build: fmt vet ## Build the Go binary
@go build .

fmt:
@[[ -z $$(go fmt ./...) ]]
.PHONY: fmt
fmt: ## Run 'go fmt' against code
go fmt ./...

.PHONY: vet
vet: ## Run 'go vet' against code
go vet ./...

.PHONY: lint
lint: fmt vet ## Invokes the fmt and vet targets
@echo 'Check for uncommitted changes ...'
git diff --exit-code

dist: fmt
@goreleaser release --snapshot --rm-dist --skip-sign
.PHONY: build\:docker
build\:docker: export CGO_ENABLED = 0
build\:docker:
build\:docker: build ## Build the docker image
docker build . -t $(DOCKER_IMG) -t $(QUAY_IMG)

clean:
@rm -rf fronius-exporter c.out dist
.PHONY: clean
clean: ## Clean the project
@rm -rf fronius-exporter cover.out dist

test:
@go test -coverprofile c.out ./...
.PHONY: test
test: ## Run unit tests
@go test -coverprofile cover.out ./...

run:
.PHONY: run
run: ## Run locally
@go run . -v
7 changes: 7 additions & 0 deletions Makefile.vars.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# These are some common variables for Make

IMG_TAG ?= latest

# Image URL to use all building/pushing image targets
DOCKER_IMG ?= docker.io/ccremer/fronius-exporter:$(IMG_TAG)
QUAY_IMG ?= quay.io/ccremer/fronius-exporter:$(IMG_TAG)
Loading

0 comments on commit 791ad26

Please sign in to comment.