-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add default CI setup for Go library
Makefile and GitHub Actions pipeline with build, lint, test and releases.
- Loading branch information
Showing
21 changed files
with
272 additions
and
0 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @odsod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
version: 2 | ||
|
||
updates: | ||
- package-ecosystem: "gomod" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- "*" | ||
|
||
jobs: | ||
make: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.15 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2-beta | ||
with: | ||
node-version: 12 | ||
|
||
- name: Make | ||
run: make | ||
|
||
release: | ||
needs: [make] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: ^1.15 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2-beta | ||
with: | ||
node-version: 12 | ||
|
||
- name: Run semantic-release | ||
run: make semantic-release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea | ||
tools/*/*/ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
run: | ||
timeout: 5m | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
- dupl # allow duplication | ||
- funlen # allow long functions | ||
- gomnd # allow some magic numbers | ||
- wsl # unwanted amount of whitespace | ||
- godox # allow TODOs | ||
- interfacer # deprecated by the author for having too many false positives | ||
- gocognit # allow higher cognitive complexity | ||
- testpackage # unwanted convention | ||
- nestif # allow deep nesting | ||
- unparam # allow constant parameters | ||
- goerr113 # allow "dynamic" errors | ||
- dogsled # allow blank identifiers | ||
- gocyclo # allow complex functions | ||
- nlreturn # allow return/break without whitespace | ||
- exhaustivestruct # don't require exhaustive fields in struct initializers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
SHELL := /bin/bash | ||
|
||
all: \ | ||
commitlint \ | ||
prettier-markdown \ | ||
go-lint \ | ||
go-review \ | ||
go-test \ | ||
go-mod-tidy \ | ||
git-verify-nodiff | ||
|
||
include tools/commitlint/rules.mk | ||
include tools/git-verify-nodiff/rules.mk | ||
include tools/golangci-lint/rules.mk | ||
include tools/goreview/rules.mk | ||
include tools/prettier/rules.mk | ||
include tools/semantic-release/rules.mk | ||
|
||
.PHONY: go-mod-tidy | ||
go-mod-tidy: | ||
$(info [$@] tidying Go module files...) | ||
@go mod tidy -v | ||
|
||
.PHONY: go-test | ||
go-test: | ||
$(info [$@] running Go tests...) | ||
@go test -count 1 -cover -race ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# AIP Go | ||
|
||
Go SDK for implementing [Google API Improvement Proposals][google-aip] (AIP). | ||
|
||
[google-aip]: https://google.aip.dev/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package aip provides primitives for implementing API Improvement Proposals (AIP). | ||
package aip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
rules: { | ||
// Treat as warning until Dependabot supports commitlint. | ||
// https://github.com/dependabot/dependabot-core/issues/2445 | ||
"body-max-line-length": [1, "always", 100], | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"devDependencies": { | ||
"@commitlint/cli": "^11.0.0", | ||
"@commitlint/config-conventional": "^11.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
commitlint_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
commitlint := $(commitlint_cwd)/node_modules/.bin/commitlint | ||
|
||
$(commitlint): $(commitlint_cwd)/package.json | ||
$(info [commitlint] installing package...) | ||
@cd $(commitlint_cwd) && npm install --no-save --no-audit &> /dev/null | ||
@touch $@ | ||
|
||
.PHONY: commitlint | ||
commitlint: $(commitlint_cwd)/.commitlintrc.js $(commitlint) | ||
$(info [$@] linting commit messages...) | ||
@git fetch --tags | ||
@NODE_PATH=$(commitlint_cwd)/node_modules $(commitlint) \ | ||
--config $< \ | ||
--from origin/master \ | ||
--to HEAD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
if [[ -n $(git status --porcelain) ]]; then | ||
echo "Staging area is dirty, please add all files created by the build to .gitignore" | ||
git diff --patch | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
git_verify_nodiff_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
git_verify_nodiff := $(git_verify_nodiff_cwd)/git-verify-nodiff.bash | ||
|
||
.PHONY: git-verify-nodiff | ||
git-verify-nodiff: | ||
$(info [$@] verifying that git has no diff...) | ||
@$(git_verify_nodiff) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
golangci_lint_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
golangci_lint_version := 1.33.0 | ||
golangci_lint := $(golangci_lint_cwd)/$(golangci_lint_version)/golangci-lint | ||
|
||
ifeq ($(shell uname),Linux) | ||
golangci_lint_archive_url := https://github.com/golangci/golangci-lint/releases/download/v${golangci_lint_version}/golangci-lint-${golangci_lint_version}-linux-amd64.tar.gz | ||
else ifeq ($(shell uname),Darwin) | ||
golangci_lint_archive_url := https://github.com/golangci/golangci-lint/releases/download/v${golangci_lint_version}/golangci-lint-${golangci_lint_version}-darwin-amd64.tar.gz | ||
else | ||
$(error unsupported OS: $(shell uname)) | ||
endif | ||
|
||
$(golangci_lint): | ||
$(info [golangci-lint] fetching version $(golangci_lint) binary...) | ||
@mkdir -p $(dir $@) | ||
@curl -sSL $(golangci_lint_archive_url) -o - | \ | ||
tar -xz --directory $(dir $@) --strip-components 1 | ||
@chmod +x $@ | ||
@touch $@ | ||
|
||
.PHONY: go-lint | ||
go-lint: $(golangci_lint) | ||
$(info [$@] linting Go code...) | ||
@$(golangci_lint) run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
goreview_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
goreview_version := 0.16.0 | ||
goreview := $(goreview_cwd)/$(goreview_version)/goreview | ||
|
||
goreview_archive_url := https://github.com/einride/goreview/releases/download/v$(goreview_version)/goreview_$(goreview_version)_$(shell uname)_$(shell uname -m).tar.gz | ||
|
||
$(goreview): $(goreview_cwd)/rules.mk | ||
$(info [go-review] fetching $(goreview_version) binary...) | ||
@mkdir -p $(dir $@) | ||
@curl -sSL $(goreview_archive_url) -o - | tar -xz --directory $(dir $@) | ||
@chmod +x $@ | ||
@touch $@ | ||
|
||
# go-review: review Go code for Einride-specific conventions | ||
.PHONY: go-review | ||
go-review: $(goreview) | ||
$(info [$@] reviewing Go code for Einride-specific conventions...) | ||
@$(goreview) -c 1 ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# paths are relative to this file | ||
|
||
../ | ||
../vendor | ||
../node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"devDependencies": { | ||
"prettier": "^2.2.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
prettier_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
prettier := $(prettier_cwd)/node_modules/.bin/prettier | ||
|
||
$(prettier): $(prettier_cwd)/package.json | ||
$(info [prettier] installing...) | ||
@cd $(prettier_cwd) && npm install --no-save --no-audit &> /dev/null | ||
@touch $@ | ||
|
||
.PHONY: prettier-markdown | ||
prettier-markdown: $(prettier_cwd)/.prettierignore $(prettier) | ||
$(info [$@] formatting Markdown files...) | ||
@$(prettier) \ | ||
--loglevel warn \ | ||
--ignore-path $< \ | ||
--parser markdown \ | ||
--prose-wrap always \ | ||
--write **/*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
plugins: | ||
- - "@semantic-release/commit-analyzer" | ||
- preset: "conventionalcommits" | ||
releaseRules: | ||
# Given Go v2+ conventions we disable major releases on | ||
# breaking changes and leave it up to the developer | ||
# to make major releases | ||
- breaking: true | ||
release: "minor" | ||
- "@semantic-release/release-notes-generator" | ||
- "@semantic-release/github" | ||
|
||
branches: ["master"] | ||
# github plugin is the only one running this step and we're not interested | ||
# in its updates to PR and issues | ||
success: false | ||
# github plugin is the only one running this step and we're not interested | ||
# the issues it creates due to failed releases | ||
fail: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"devDependencies": { | ||
"semantic-release": "^17.3.0", | ||
"@semantic-release/github": "^7.2.0", | ||
"@semantic-release/release-notes-generator": "^9.0.1", | ||
"conventional-changelog-conventionalcommits": "^4.5.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
semantic_release_cwd := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))) | ||
semantic_release := $(semantic_release_cwd)/node_modules/.bin/semantic-release | ||
|
||
$(semantic_release): $(semantic_release_cwd)/package.json | ||
$(info [semantic-release] installing packages...) | ||
@cd $(semantic_release_cwd) && npm install --no-save --no-audit --ignore-scripts &> /dev/null | ||
@touch $@ | ||
|
||
.PHONY: semantic-release | ||
semantic-release: $(semantic_release_cwd)/.releaserc.yaml $(semantic_release) | ||
$(info [$@] creating release...) | ||
@cd $(semantic_release_cwd) && $(semantic_release) |