Skip to content

Commit

Permalink
refactor(build): various changes to build workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
l3uddz committed Jul 31, 2020
1 parent 1051eda commit 1c8944e
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 58 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: l3uddz
18 changes: 18 additions & 0 deletions .github/workflows/artifact.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Remove old artifacts

on:
schedule:
# Every day at 1am
- cron: '0 1 * * *'

jobs:
remove-old-artifacts:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- name: Remove old artifacts
uses: c-hive/gha-remove-artifacts@v1
with:
age: '1 days'
skip-tags: true
80 changes: 80 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build

on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
types:
- opened
- reopened
- edited

jobs:
build:
runs-on: ubuntu-latest
steps:
# checkout
- name: checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

# setup go
- name: go
uses: actions/setup-go@v1
with:
go-version: 1.14
- run: go version
- run: go env

# cache
- name: cache
uses: actions/cache@v1
with:
path: vendor
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# vendor
- name: vendor
run: |
make vendor
# build
- name: build
if: startsWith(github.ref, 'refs/tags/') == false
run: |
make snapshot
# get tag name
- name: tag_name
if: startsWith(github.ref, 'refs/tags/')
uses: olegtarasov/get-tag@v2
with:
tagRegex: "v?(.+)"

# publish
- name: publish
if: startsWith(github.ref, 'refs/tags/')
env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
make publish
# artifacts
- name: artifact_linux
uses: actions/upload-artifact@v2-preview
with:
name: build_linux
path: dist/*linux*

- name: artifact_darwin
uses: actions/upload-artifact@v2-preview
with:
name: build_darwin
path: dist/*darwin*
14 changes: 14 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: golangci-lint

on: [push, pull_request]

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v1
with:
version: v1.27
22 changes: 22 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
run:
timeout: 10m

linters:
enable:
- bodyclose
# - goimports
- unconvert
# - unparam
- scopelint
- dupl
- interfacer
- stylecheck

issues:
exclude-rules:
- linters:
- stylecheck
text: "ST1003:"
- linters:
- scopelint
text: 'Using the variable on range scope `tc` in function literal'
63 changes: 63 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# https://goreleaser.com
project_name: wantarr
env:
- GO111MODULE=on
- CGO_ENABLED=1

# Build
builds:
- id: build_darwin
env:
- CC=o64-clang
- CXX=o64-clang++
goos:
- darwin
goarch:
- amd64
ldflags:
- -s -w
- -X "github.com/l3uddz/wantarr/build.Version={{ .Version }}"
- -X "github.com/l3uddz/wantarr/build.GitCommit={{ .ShortCommit }}"
- -X "github.com/l3uddz/wantarr/build.Timestamp={{ .Timestamp }}"
flags:
- -trimpath

- id: build_linux
goos:
- linux
goarch:
- amd64
ldflags:
- -linkmode external
- -extldflags -static
- -s -w
- -X "github.com/l3uddz/wantarr/build.Version={{ .Version }}"
- -X "github.com/l3uddz/wantarr/build.GitCommit={{ .ShortCommit }}"
- -X "github.com/l3uddz/wantarr/build.Timestamp={{ .Timestamp }}"
flags:
- -trimpath
- -tags=netgo
- -v

# Archive
archives:
-
name_template: "{{ .ProjectName }}_v{{ .Version }}_{{ .Os }}_{{ .Arch }}"
format: "binary"

# Checksum
checksum:
name_template: "checksums.txt"
algorithm: sha512

# Snapshot
snapshot:
name_template: "{{ .Major }}.{{ .Minor }}.{{ .Patch }}-dev+{{ .ShortCommit }}"

# Changelog
changelog:
filters:
exclude:
- "^docs:"
- "^test:"
- "^Merge branch"
23 changes: 19 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,27 @@ release: check_goreleaser fetch ## Generate a release, but don't publish
goreleaser --skip-validate --skip-publish --rm-dist

.PHONY: publish
publish: check_goreleaser fetch ## Generate a release, and publish
goreleaser --rm-dist
publish: fetch ## Generate a release, and publish
docker run --rm --privileged \
-e GITHUB_TOKEN="${TOKEN}" \
-e VERSION="${GIT_TAG_NAME}" \
-e GIT_COMMIT="${GIT_COMMIT}" \
-e TIMESTAMP="${TIMESTAMP}" \
-v `pwd`:/go/src/github.com/l3uddz/wantarr \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/l3uddz/wantarr \
neilotoole/xcgo:latest goreleaser --rm-dist

.PHONY: snapshot
snapshot: check_goreleaser fetch ## Generate a snapshot release
goreleaser --snapshot --skip-validate --skip-publish --rm-dist
snapshot: fetch ## Generate a snapshot release
docker run --rm --privileged \
-e VERSION="${VERSION}" \
-e GIT_COMMIT="${GIT_COMMIT}" \
-e TIMESTAMP="${TIMESTAMP}" \
-v `pwd`:/go/src/github.com/l3uddz/wantarr \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/l3uddz/wantarr \
neilotoole/xcgo:latest goreleaser --snapshot --skip-validate --skip-publish --rm-dist

.PHONY: help
help:
Expand Down
34 changes: 14 additions & 20 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,33 @@ go 1.13

require (
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/golang/protobuf v1.3.2 // indirect
github.com/imroc/req v0.3.0
github.com/jinzhu/gorm v1.9.12
github.com/jinzhu/gorm v1.9.15
github.com/jpillora/backoff v1.0.0
github.com/json-iterator/go v1.1.9
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/json-iterator/go v1.1.10
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/onsi/ginkgo v1.11.0 // indirect
github.com/onsi/gomega v1.8.1 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/afero v1.2.2 // indirect
github.com/sirupsen/logrus v1.6.0
github.com/spf13/afero v1.3.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v0.0.6
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.2
github.com/stretchr/testify v1.4.0 // indirect
github.com/spf13/viper v1.7.0
github.com/tommysolsen/capitalise v0.0.0-20171110170156-1df6e863d8ab
github.com/x-cray/logrus-prefixed-formatter v0.5.2
go.uber.org/atomic v1.6.0
golang.org/x/crypto v0.0.0-20200311171314-f7b00557c8c4 // indirect
golang.org/x/net v0.0.0-20191105084925-a882066a44e0 // indirect
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de // indirect
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1 // indirect
golang.org/x/text v0.3.3 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/ini.v1 v1.54.0 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
)
Loading

0 comments on commit 1c8944e

Please sign in to comment.