Skip to content

Commit

Permalink
Add workflow and releaser
Browse files Browse the repository at this point in the history
  • Loading branch information
nobe4 committed Apr 3, 2021
1 parent 635c283 commit be3eccc
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 31 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: release

on:
push:
tags:
- '*'

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.15

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
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
@@ -1 +1,3 @@
bin/
makefile-e
dist/
52 changes: 52 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
project_name: safe

before:
hooks:
- go mod tidy

builds:
- main: ./cmd/safe/safe.go
binary: safe
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
format: tar.gz
format_overrides:
- goos: windows
format: zip
files:
- none*

checksum:
name_template: 'checksums.txt'

snapshot:
name_template: "{{ .Tag }}-snapshot"

changelog:
sort: asc
filters:
exclude:
- README
- typo

release:
github:
owner: nobe4
name: safe
prerelease: auto
name_template: '{{ .Tag }}'
12 changes: 6 additions & 6 deletions cmd/safe/safe.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
)

var (
Version string
Commit string
Build string
version string
commit string
build string
)

func main() {
Expand All @@ -26,11 +26,11 @@ func main() {
censor := flag.String("censor", "X", "censor character to use")
dict := flag.String("dict", "ascii", "dictionary for entropy filtering ("+entropy.List()+")")
threshold := flag.Float64("threshold", 3.0, "threshold to apply filtering (debug with verbosity 1)")
version := flag.Bool("version", false, "show version information")
printVersion := flag.Bool("version", false, "show version information")
flag.Parse()

if version != nil && *version {
fmt.Printf("safe: version %s, commit %s, build %s\n", Version, Commit, Build)
if printVersion != nil && *printVersion {
fmt.Printf("safe: version %s, commit %s, build %s\n", version, commit, build)
return
}

Expand Down
41 changes: 16 additions & 25 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
APP=safe
PROJECT=github.com/nobe4/${APP}

GO?=go
GOOS?=darwin
GOARCH?=amd64

# YYYY.MM.Count
RELEASE?=2021.04.2
VERSION?=2021.04.2
COMMIT?=$(shell git rev-parse --short HEAD)
BUILD_TIME?=$(shell date -u '+%Y-%m-%d_%H:%M:%S')

BUILD_PATH=./bin/${GOOS}-${GOARCH}/${APP}
MAIN_PATH=${PROJECT}/cmd/${APP}

default: | build

.PHONY: version
version:
@echo -n ${RELEASE}
@echo -n ${VERSION}

.PHONY: app-name
app-name:
@echo -n ${APP}

build:
CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} \
go build -a \
-ldflags="-s -w \
-X 'main.Version=${RELEASE}' \
-X 'main.Commit=${COMMIT}' \
-X 'main.Build=${BUILD_TIME}' "\
-o ${BUILD_PATH} ${MAIN_PATH}

.PHONY: lint
goreleaser --snapshot --rm-dist

# Used for manually releasing, normally running in github actions.
release:
ifneq ($(shell git symbolic-ref --short HEAD),master)
$(error Not on master branch)
endif

goreleaser --rm-dist

lint:
golangci-lint run

.PHONY: test
test:
go test ./...

.PHONY: bump
bump:
./build/bump.sh
./scripts/bump.sh
git add makefile
git commit -m "Bump version" --edit

.PHONY: tag
tag:
./build/tag.sh
./scripts/tag.sh

.PHONY: bump tag lint test app-name version
13 changes: 13 additions & 0 deletions scripts/bump.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e

current_version=$(make version)

# awk -F. split by '.', increase the last number, add the '.' back
next_version=$(echo "$current_version" | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')

echo "Bump version $current_version to version $next_version"

sed -i -e "s/$current_version/$next_version/" makefile

echo "Don't forget to push the new tag before you merge."
17 changes: 17 additions & 0 deletions scripts/tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
set -e

if [ "$(git symbolic-ref --short HEAD)" != "master" ]; then
echo "Not on master branch, not tagging"
exit 1
fi

release=$(make version)

if git rev-parse "$release" >/dev/null 2>&1
then
echo "Tag $release already present, run 'make bump'"
else
git tag "$release"
git push origin "$release"
fi

0 comments on commit be3eccc

Please sign in to comment.