Skip to content

Commit dd4e126

Browse files
committed
CI & Release
1 parent e266dfb commit dd4e126

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@master
13+
- name: Setup Go
14+
uses: actions/setup-go@v1
15+
with:
16+
go-version: 1.x
17+
- name: Build
18+
run: go build -v .

.github/workflows/release.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@master
15+
- name: Setup Go
16+
uses: actions/setup-go@v1
17+
with:
18+
go-version: 1.x
19+
- name: Add $GOPATH/bin to $PATH
20+
run: echo "::add-path::$(go env GOPATH)/bin"
21+
- name: Cross build
22+
run: make cross
23+
- name: Create Release
24+
id: create_release
25+
uses: actions/create-release@master
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
with:
29+
tag_name: ${{ github.ref }}
30+
release_name: Release ${{ github.ref }}
31+
- name: Upload
32+
run: make upload
33+
env:
34+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Makefile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
BIN := memo
2+
VERSION := $$(make -s show-version)
3+
CURRENT_REVISION := $(shell git rev-parse --short HEAD)
4+
BUILD_LDFLAGS := "-s -w -X main.revision=$(CURRENT_REVISION)"
5+
GOBIN ?= $(shell go env GOPATH)/bin
6+
export GO111MODULE=on
7+
8+
.PHONY: all
9+
all: clean build
10+
11+
.PHONY: build
12+
build:
13+
go build -ldflags=$(BUILD_LDFLAGS) -o $(BIN) .
14+
15+
.PHONY: install
16+
install:
17+
go install -ldflags=$(BUILD_LDFLAGS) .
18+
19+
.PHONY: show-version
20+
show-version: $(GOBIN)/gobump
21+
@gobump show -r .
22+
23+
$(GOBIN)/gobump:
24+
@cd && go get github.com/x-motemen/gobump/cmd/gobump
25+
26+
.PHONY: cross
27+
cross: $(GOBIN)/goxz
28+
goxz -n $(BIN) -pv=v$(VERSION) -build-ldflags=$(BUILD_LDFLAGS) .
29+
30+
$(GOBIN)/goxz:
31+
cd && go get github.com/Songmu/goxz/cmd/goxz
32+
33+
.PHONY: test
34+
test: build
35+
go test -v ./...
36+
37+
.PHONY: clean
38+
clean:
39+
rm -rf $(BIN) goxz
40+
go clean
41+
42+
.PHONY: bump
43+
bump: $(GOBIN)/gobump
44+
ifneq ($(shell git status --porcelain),)
45+
$(error git workspace is dirty)
46+
endif
47+
ifneq ($(shell git rev-parse --abbrev-ref HEAD),master)
48+
$(error current branch is not master)
49+
endif
50+
@gobump up -w .
51+
git commit -am "bump up version to $(VERSION)"
52+
git tag "v$(VERSION)"
53+
git push origin master
54+
git push origin "refs/tags/v$(VERSION)"
55+
56+
.PHONY: upload
57+
upload: $(GOBIN)/ghr
58+
ghr "v$(VERSION)" goxz
59+
60+
$(GOBIN)/ghr:
61+
cd && go get github.com/tcnksm/ghr

0 commit comments

Comments
 (0)