Skip to content

Commit 495eebb

Browse files
authored
ci: add releaser and linter (#101)
* ci: add releaser and linter * chore: fix dockerfile * chore: update binary location * fix: fix fullcompatability check * build: add codeql linter * fix: update fullcompatibility rules * chore: remove dead code * lint: fix lint issues * chore: add lint in makefile
1 parent 5fb937f commit 495eebb

23 files changed

Lines changed: 226 additions & 129 deletions

.github/workflows/lint.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: "Lint"
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
golangci:
7+
name: "Lint Go"
8+
runs-on: "ubuntu-latest"
9+
steps:
10+
- uses: actions/setup-go@v2
11+
with:
12+
go-version: "1.17"
13+
- uses: actions/checkout@v2
14+
- name: golangci-lint
15+
uses: golangci/golangci-lint-action@v2
16+
with:
17+
skip-go-installation: true
18+
19+
codeql:
20+
name: "Analyze with CodeQL"
21+
runs-on: "ubuntu-latest"
22+
permissions:
23+
actions: "read"
24+
contents: "read"
25+
security-events: "write"
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
language: ["go"]
30+
steps:
31+
- uses: "actions/checkout@v2"
32+
- uses: "github/codeql-action/init@v1"
33+
with:
34+
languages: "${{ matrix.language }}"
35+
- uses: "github/codeql-action/autobuild@v1"
36+
- uses: "github/codeql-action/analyze@v1"

.github/workflows/release.yml

Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,6 @@ on:
55
- "v*.*.*"
66

77
jobs:
8-
create-release:
9-
name: create release
10-
runs-on: ubuntu-latest
11-
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
- name: Release
15-
uses: softprops/action-gh-release@v1
16-
with:
17-
body_path: CHANGELOG.md
18-
env:
19-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20-
add-stencil-server-artifacts:
21-
name: release linux/amd64
22-
runs-on: ubuntu-latest
23-
needs: create-release
24-
strategy:
25-
matrix:
26-
goos: [linux, windows, darwin]
27-
goarch: [amd64, arm64]
28-
exclude:
29-
- goarch: arm64
30-
goos: windows
31-
steps:
32-
- uses: actions/checkout@v2
33-
- uses: wangyoucao577/go-release-action@v1.17
34-
with:
35-
github_token: ${{ secrets.GITHUB_TOKEN }}
36-
goos: ${{ matrix.goos }}
37-
goarch: ${{ matrix.goarch }}
38-
project_path: ./
398
publish-java-client:
409
runs-on: ubuntu-latest
4110
needs: create-release
@@ -57,47 +26,47 @@ jobs:
5726
GPG_SIGNING_KEY: ${{ secrets.GPG_SIGNING_KEY }}
5827
GPG_SIGNING_KEY_ID: ${{ secrets.GPG_SIGNING_KEY_ID }}
5928
GPG_SIGNING_PASSWORD: ${{ secrets.GPG_SIGNING_PASSWORD }}
29+
6030
publish-js-client:
6131
runs-on: ubuntu-latest
6232
needs: create-release
6333
steps:
64-
- uses: actions/checkout@v2
65-
- uses: actions/setup-node@v2
66-
with:
67-
node-version: '12.x'
68-
registry-url: 'https://registry.npmjs.org'
69-
scope: '@odpf'
70-
- run: npm install
71-
working-directory: clients/js
72-
- run: npm publish --access public
73-
working-directory: clients/js
74-
env:
75-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
34+
- uses: actions/checkout@v2
35+
- uses: actions/setup-node@v2
36+
with:
37+
node-version: "12.x"
38+
registry-url: "https://registry.npmjs.org"
39+
scope: "@odpf"
40+
- run: npm install
41+
working-directory: clients/js
42+
- run: npm publish --access public
43+
working-directory: clients/js
44+
env:
45+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
46+
7647
publish-server:
7748
runs-on: ubuntu-latest
7849
needs: create-release
7950
steps:
80-
- uses: actions/checkout@v2
81-
- name: Get release tag
82-
id: get_version
83-
uses: battila7/get-version-action@v2
84-
- name: Login to GitHub Packages Docker Registry
85-
uses: docker/login-action@v1
51+
- name: Checkout
52+
uses: actions/checkout@v2
8653
with:
87-
registry: docker.pkg.github.com
88-
username: ${{ github.actor }}
89-
password: ${{ secrets.GITHUB_TOKEN }}
54+
fetch-depth: 0
55+
- name: Set up Go
56+
uses: actions/setup-go@v2
57+
with:
58+
go-version: "1.17"
9059
- name: Login to DockerHub
9160
uses: docker/login-action@v1
9261
with:
62+
registry: docker.io
9363
username: ${{ secrets.DOCKERHUB_USERNAME }}
9464
password: ${{ secrets.DOCKERHUB_TOKEN }}
95-
- name: Build and Push
96-
uses: docker/build-push-action@v2
65+
- name: Run GoReleaser
66+
uses: goreleaser/goreleaser-action@v2.6.1
9767
with:
98-
push: true
99-
tags: |
100-
docker.pkg.github.com/${{ github.repository }}/stencil:latest
101-
docker.pkg.github.com/${{ github.repository }}/stencil:${{ steps.get_version.outputs.version-without-v }}
102-
odpf/stencil:latest
103-
odpf/stencil:${{ steps.get_version.outputs.version-without-v }}
68+
distribution: goreleaser
69+
version: latest
70+
args: --rm-dist
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GO_RELEASER_TOKEN }}
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
on:
1+
name: Test
2+
3+
on:
24
push:
35
branches:
46
- master
57
pull_request:
68
workflow_dispatch:
7-
name: Test
9+
810
jobs:
911
test:
1012
runs-on: ubuntu-latest
@@ -32,7 +34,7 @@ jobs:
3234
- name: Install Protoc
3335
uses: arduino/setup-protoc@v1
3436
with:
35-
version: '3.x'
37+
version: "3.x"
3638
- name: Check out code into the Go module directory
3739
uses: actions/checkout@v2
3840
- name: Test

.golangci.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
run:
2+
timeout: 5m
3+
skip-dirs:
4+
- api/proto
5+
- clients/java
6+
- clients/js
7+
- docs
8+
- scripts
9+
output:
10+
format: line-number
11+
linters:
12+
enable-all: false
13+
disable-all: true
14+
enable:
15+
- vet
16+
- goimports
17+
- thelper
18+
- tparallel
19+
- unconvert
20+
- wastedassign
21+
- revive
22+
- unused
23+
- gofmt
24+
- whitespace
25+
- misspell
26+
linters-settings:
27+
revive:
28+
ignore-generated-header: true
29+
severity: warning
30+
issues:
31+
fix: true
32+
severity:
33+
default-severity: error

.goreleaser.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
project_name: stencil
2+
3+
release:
4+
draft: true
5+
prerelease: auto
6+
7+
before:
8+
hooks:
9+
- go mod tidy
10+
- make clean
11+
12+
builds:
13+
- main: ./main.go
14+
id: "stencil"
15+
binary: stencil
16+
flags:
17+
- -a
18+
ldflags:
19+
- -X github.com/odpf/stencil/config.Version={{.Tag}}
20+
- -X github.com/odpf/stencil/config.BuildCommit={{.FullCommit}}
21+
- -X github.com/odpf/stencil/config.BuildDate={{.Date}}
22+
goos: [darwin, linux, windows]
23+
goarch: [amd64, 386, arm, arm64]
24+
env:
25+
- CGO_ENABLED=0
26+
27+
archives:
28+
- replacements:
29+
darwin: macos
30+
linux: linux
31+
windows: windows
32+
386: i386
33+
amd64: x86_64
34+
format_overrides:
35+
- goos: windows
36+
format: zip
37+
38+
changelog:
39+
use: "github-native"
40+
sort: asc
41+
filters:
42+
exclude:
43+
- "^docs:"
44+
- "^test:"
45+
- "^build:"
46+
47+
checksum:
48+
name_template: "checksums.txt"
49+
50+
snapshot:
51+
name_template: "{{ .Tag }}-next"
52+
53+
dockers:
54+
- goos: linux
55+
goarch: amd64
56+
ids:
57+
- stencil
58+
dockerfile: Dockerfile
59+
image_templates:
60+
- "docker.io/odpf/{{.ProjectName}}:latest"
61+
- "docker.io/odpf/{{.ProjectName}}:{{ .Version }}"
62+
- "docker.io/odpf/{{.ProjectName}}:{{ .Tag }}-amd64"
63+
64+
brews:
65+
- name: stencil
66+
homepage: "https://github.com/odpf/stencil"
67+
description: "Schema registry"
68+
tap:
69+
owner: odpf
70+
name: homebrew-taps
71+
license: "Apache 2.0"
72+
folder: Formula
73+
dependencies:
74+
- name: git
75+
install: |-
76+
bin.install "stencil"
77+
commit_author:
78+
name: Ravi Suhag
79+
email: suhag.ravi@gmail.com

Dockerfile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
FROM golang:1.16-alpine3.13 AS builder
2-
WORKDIR /go/src/github.com/odpf/stencil
3-
COPY . .
4-
RUN apk add make bash
5-
RUN make dist
6-
71
FROM alpine:3.13
8-
RUN apk --no-cache add ca-certificates bash
9-
WORKDIR /root/
2+
3+
RUN apk add --no-cache ca-certificates && update-ca-certificates
4+
5+
COPY stencil /usr/bin/stencil
6+
107
EXPOSE 8080
11-
COPY --from=builder /go/src/github.com/odpf/stencil/dist/linux-amd64/stencil .
12-
ENTRYPOINT ["./stencil"]
8+
ENTRYPOINT ["stencil"]

Makefile

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
NAME="github.com/odpf/stencil"
22
VERSION=$(shell git describe --always --tags 2>/dev/null)
3-
COVERFILE="/tmp/stencil.coverprofile"
4-
DIST_PATH=out
3+
PROTON_COMMIT := "d08a4916075438ed9c3a4510989bda2273e0a4e4"
54

6-
.PHONY: all build clean
5+
.PHONY: all build test clean dist vet proto install
76

87
all: build
98

10-
build:
9+
build: ## Build the stencil binary
1110
go build -ldflags "-X config.Version=${VERSION}" ${NAME}
1211

13-
clean:
14-
rm -rf stencil dist/
12+
test: ## Run the tests
13+
go test ./... -coverprofile=coverage.out
14+
15+
coverage: ## Print code coverage
16+
go test -race -coverprofile coverage.txt -covermode=atomic ./... & go tool cover -html=coverage.out
1517

16-
lint:
18+
vet: ## Run the go vet tool
1719
go vet ./...
1820

19-
test:
20-
go test ./... -coverprofile=coverage.out
21+
lint: ## Run golang-ci lint
22+
golangci-lint run
23+
24+
proto: ## Generate the protobuf files
25+
@echo " > generating protobuf from odpf/proton"
26+
@echo " > [info] make sure correct version of dependencies are installed using 'make install'"
27+
@buf generate https://github.com/odpf/proton/archive/${PROTON_COMMIT}.zip#strip_components=1 --template buf.gen.yaml --path odpf/stencil
28+
@echo " > protobuf compilation finished"
2129

22-
test-coverage: test
23-
go tool cover -html=coverage.out
30+
clean: ## Clean the build artifacts
31+
rm -rf stencil dist/
2432

25-
dist:
26-
@bash ./scripts/build.sh
33+
help: ## Display this help message
34+
@cat $(MAKEFILE_LIST) | grep -e "^[a-zA-Z_\-]*: *.*## *" | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

0 commit comments

Comments
 (0)