Skip to content

Commit

Permalink
add versioning (#64)
Browse files Browse the repository at this point in the history
* add versioning
  • Loading branch information
abice authored Sep 5, 2021
1 parent 1012a12 commit 2b856fe
Show file tree
Hide file tree
Showing 27 changed files with 281 additions and 90 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ jobs:
if [[ -n "$COVERALLS_TOKEN" ]]; then
make coveralls
fi
- name: Upload coverage
uses: actions/upload-artifact@v2
with:
name: coverage
path: coverage.*
46 changes: 46 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: goreleaser

on:
release:
types:
- "created"

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

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.16

- name: Cache Go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
install-only: true
- name: Show GoReleaser version
run: goreleaser -v

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
if: success() && startsWith(github.ref, 'refs/tags/')
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@
vendor/
coverage.out
coverage.html

dist/
33 changes: 33 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./generator
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
22 changes: 16 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,23 @@ else
endif

GO ?= GO111MODULE=on go
COVERAGEDIR = coverage
COVERAGEDIR= coverage
SERVICE=local
ifdef CIRCLE_WORKING_DIRECTORY
COVERAGEDIR = $(CIRCLE_WORKING_DIRECTORY)/coverage
SERVICE=circle-ci

ifdef GITHUB_ACTIONS
SERVICE=github-actions
endif

DATE := $(shell date -u '+%FT%T%z')
GITHUB_SHA ?= $(shell git rev-parse HEAD)
GITHUB_REF ?= local

LDFLAGS += -X "main.version=$(GITHUB_REF)"
LDFLAGS += -X "main.commit=$(GITHUB_SHA)"
LDFLAGS += -X "main.date=$(DATE)"
LDFLAGS += -X "main.builtBy=$(USER)"
LDFLAGS += -extldflags '-static'

define goinstall
mkdir -p $(shell pwd)/bin
echo "Installing $(1)"
Expand All @@ -26,7 +36,6 @@ MOCKGEN=bin/mockgen
deps: $(MOCKGEN)
deps: $(GOBINDATA)
deps: $(GOIMPORTS)
deps: $(GOVERALLS)

PACKAGES='./generator' './example'

Expand All @@ -36,7 +45,7 @@ all: build fmt test example cover install
build: deps
$(GO) generate ./generator
if [ ! -d bin ]; then mkdir bin; fi
$(GO) build -v -o bin/go-enum .
$(GO) build -v -o bin/go-enum -ldflags='-X "main.version=example" -X "main.commit=example" -X "main.date=example" -X "main.builtBy=example"' .

fmt:
gofmt -l -w -s $$(find . -type f -name '*.go' -not -path "./vendor/*")
Expand All @@ -56,6 +65,7 @@ clean:
rm -f bin/go-enum
rm -rf coverage/
rm -rf bin/
rm -rf dist/

.PHONY: generate
generate:
Expand Down
4 changes: 4 additions & 0 deletions example/animal_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/color_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/commented_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/custom_prefix_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/example_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/globs/letter_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions example/globs/number_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/sql_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/sql_int_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2b856fe

Please sign in to comment.