Skip to content

Commit cba2fda

Browse files
committed
feat: Add CI and CD
1 parent 1da104c commit cba2fda

7 files changed

Lines changed: 174 additions & 17 deletions

File tree

.github/workflows/cd.yaml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: CD
2+
on:
3+
push:
4+
branches:
5+
- master
6+
7+
jobs:
8+
prebuild:
9+
name: Prebuild
10+
runs-on: ubuntu-latest
11+
outputs:
12+
newversion: ${{ env.NEW_VERSION }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
with:
17+
ref: ${{ github.ref }}
18+
fetch-depth: 0 # Include all history as we need that to determine the next version
19+
- name: Determine New Version
20+
run: echo "::set-env name=NEW_VERSION::$(make local-version)"
21+
22+
build:
23+
name: Build
24+
runs-on: ubuntu-latest
25+
needs:
26+
prebuild
27+
strategy:
28+
matrix:
29+
os: [darwin, linux]
30+
arch: [amd64]
31+
outputs:
32+
newversion: ${{ needs.prebuild.outputs.newversion }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v2
36+
with:
37+
ref: ${{ github.ref }}
38+
- name: Bootstrap
39+
run: make bootstrap
40+
- name: Build
41+
run: make NEW_VERSION=${{ needs.prebuild.outputs.newversion }}
42+
env:
43+
TARGET_OS: ${{ matrix.os }}
44+
TARGET_ARCH: ${{ matrix.arch }}
45+
- name: Save Artifacts
46+
uses: actions/upload-artifact@v2
47+
with:
48+
name: ccp-${{ matrix.os }}-${{ matrix.arch }}
49+
path: bin/ccp
50+
51+
release:
52+
name: Release
53+
runs-on: ubuntu-latest
54+
needs:
55+
build
56+
outputs:
57+
uploadurl: ${{ steps.create-release.outputs.upload_url }}
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v2
61+
with:
62+
ref: ${{ github.ref }}
63+
fetch-depth: 0
64+
- name: Tag
65+
run: |
66+
git config user.name github-actions
67+
git config user.email github-actions@github.com
68+
git tag -a ${{ needs.build.outputs.newversion }} -m ${{ needs.build.outputs.newversion }}
69+
git push --tags
70+
- name: Create Release
71+
id: create-release
72+
uses: actions/create-release@v1
73+
env:
74+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75+
with:
76+
tag_name: ${{ needs.build.outputs.newversion }}
77+
release_name: v${{ needs.build.outputs.newversion }}
78+
draft: false
79+
prerelease: false
80+
81+
upload-artifacts:
82+
name: Upload Artifacts
83+
runs-on: ubuntu-latest
84+
needs:
85+
release
86+
strategy:
87+
matrix:
88+
os: [darwin, linux]
89+
arch: [amd64]
90+
steps:
91+
- name: Download Artifact
92+
uses: actions/download-artifact@v2
93+
with:
94+
name: ccp-${{ matrix.os }}-${{ matrix.arch }}
95+
- name: Make Artifact Executable # See https://github.com/actions/upload-artifact/issues/38
96+
run: chmod +x ./ccp
97+
- name: Upload Asset
98+
id: upload-asset
99+
uses: actions/upload-release-asset@v1
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
with:
103+
upload_url: ${{ needs.release.outputs.uploadurl }}
104+
asset_path: ./ccp
105+
asset_name: ccp-${{ matrix.os }}-${{ matrix.arch }}
106+
asset_content_type: "application"

.github/workflows/ci.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
branches:
5+
- master
6+
7+
jobs:
8+
validate:
9+
name: Validate
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
ref: ${{ github.ref }}
16+
- name: Build
17+
run: make alpha # No need to bootstrap
18+
- name: Upload
19+
uses: actions/upload-artifact@v2
20+
with:
21+
name: ccp
22+
path: bin/ccp

Makefile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
1-
newversion := $(shell go run . version)
2-
newversion ?= 0.1.0
1+
GOBIN ?= ${PWD}
2+
NEW_VERSION ?= 0.1.0
3+
TARGET_OS ?= $(shell go env GOOS)
4+
TARGET_ARCH ?= $(shell go env GOARCH)
35

46
.DEFAULT_GOAL := build
57

8+
.PHONY: bootstrap
9+
bootstrap:
10+
@GOBIN=${GOBIN} go get github.com/mitchellh/gox
11+
@go mod download
12+
613
.PHONY: clean
714
clean:
815
@rm -rf bin
916

1017
.PHONY: alpha
1118
alpha: clean
1219
@mkdir -p bin
13-
@go build -o bin -ldflags="-X main.applicationVersion=${newversion}-alpha"
20+
@go build -o bin -ldflags="-X main.applicationVersion=$(shell date +%s)-alpha"
1421

1522
.PHONY: build
1623
build: clean
1724
@mkdir -p bin
18-
@go build -o bin -ldflags="-X main.applicationVersion=${newversion}"
25+
@${GOBIN}/gox -os=${TARGET_OS} -arch=${TARGET_ARCH} -output bin/ccp -ldflags="-X main.applicationVersion=${NEW_VERSION}"
26+
27+
.PHONY: local-version
28+
local-version:
29+
@go run . version

git/git.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ func getCommits(r *git.Repository, from, to string) ([]string, error) {
5151
for {
5252
c, err := iter.Next()
5353
if err != nil {
54-
return nil, err
54+
xlog.Debug("No more messages to parse")
55+
break
5556
}
5657

5758
if c.Hash.String() == fromHash.String() {
@@ -60,6 +61,7 @@ func getCommits(r *git.Repository, from, to string) ([]string, error) {
6061

6162
messages = append(messages, c.Message)
6263
}
64+
xlog.Debugf("Got messages: %v", messages)
6365
return messages, nil
6466
}
6567

git/git_internal_test.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ func createTag(t *testing.T, r *git.Repository, tag string) {
109109
func TestGetCommits(t *testing.T) {
110110
const (
111111
b1 = "b1"
112+
b2 = "b2"
113+
b3 = "b3"
112114

113115
c1 = "first commit"
114116
c2 = "second commit"
@@ -201,6 +203,21 @@ func TestGetCommits(t *testing.T) {
201203
c3,
202204
},
203205
},
206+
"to before from": {
207+
setup: func(t *testing.T) *git.Repository {
208+
r := createRepository(t)
209+
createBranch(t, r, b1)
210+
createCommit(t, r, c1)
211+
createCommit(t, r, c2)
212+
createCommit(t, r, c3)
213+
return r
214+
},
215+
from: head,
216+
to: head2,
217+
expected: []string{
218+
c1,
219+
},
220+
},
204221
}
205222

206223
for name, data := range cases {
@@ -255,18 +272,6 @@ func TestGetCommitsError(t *testing.T) {
255272
from: head1,
256273
to: "bad",
257274
},
258-
"to before from": {
259-
setup: func(t *testing.T) *git.Repository {
260-
r := createRepository(t)
261-
createBranch(t, r, b1)
262-
createCommit(t, r, c1)
263-
createCommit(t, r, c2)
264-
createCommit(t, r, c3)
265-
return r
266-
},
267-
from: head,
268-
to: head2,
269-
},
270275
}
271276

272277
for name, data := range cases {

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ go 1.13
44

55
require (
66
github.com/Masterminds/semver v1.5.0
7+
github.com/hashicorp/go-version v1.2.1 // indirect
78
github.com/jmcvetta/randutil v0.0.0-20150817122601-2bb1b664bcff
9+
github.com/mitchellh/gox v1.0.1 // indirect
810
github.com/spf13/cobra v1.0.0
911
github.com/stretchr/testify v1.6.1
1012
github.com/xfxdev/xlog v0.0.0-20190115101715-8752a0193860

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,13 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
5151
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
5252
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
5353
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
54+
github.com/hashicorp/go-version v1.0.0 h1:21MVWPKDphxa7ineQQTrCU5brh7OuVVAzGOCnnCPtE8=
55+
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
56+
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
57+
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
5458
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
5559
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
60+
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
5661
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
5762
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
5863
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo=
@@ -78,6 +83,10 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
7883
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
7984
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
8085
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
86+
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
87+
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
88+
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
89+
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
8190
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
8291
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
8392
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=

0 commit comments

Comments
 (0)