forked from kentik/pkg
-
Notifications
You must be signed in to change notification settings - Fork 0
112 lines (104 loc) · 2.95 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
name: build
on:
push:
branches: "*"
tags: "v[0-9]+.[0-9]+.[0-9]+*"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin]
ar: [amd64]
outputs:
version: ${{ steps.version.outputs.version }}
binary: ${{ steps.build.outputs.binary }}
steps:
- uses: actions/setup-go@v2
with:
go-version: ^1.14
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: version
id: version
run: |
VERSION=$(git describe --tags --always)
echo version $VERSION
echo ::set-output name=version::$VERSION
- name: build
id: build
run: |
GOFLAGS="-ldflags=-X=main.BuildVersion=$VERSION"
export GOFLAGS
CGO_ENABLED=0 go build -o $BINARY $PACKAGE
echo ::set-output name=binary::$BINARY
env:
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.ar }}
BINARY: pkg-${{ matrix.os }}-${{ matrix.ar }}
VERSION: ${{ steps.version.outputs.version }}
- id: test
run: |
go test -v $PACKAGE/...
- uses: actions/upload-artifact@v2
with:
name: ${{ steps.build.outputs.binary }}
path: ${{ steps.build.outputs.binary }}
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/download-artifact@v2
with:
name: pkg-linux-amd64
- run: chmod a+x pkg-linux-amd64
- uses: docker/build-push-action@v1
with:
repository: ${{ github.repository }}
tag_with_ref: true
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
env:
DOCKER_BUILDKIT: 1
needs: build
release:
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create.outputs.upload_url }}
steps:
- id: create
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref }}
release_name: ${{ github.ref }}
draft: false
prerelease: ${{ contains(github.ref, '-rc') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: build
if: startsWith(github.ref, 'refs/tags')
assets:
runs-on: ubuntu-latest
strategy:
matrix:
os: [linux, darwin]
ar: [amd64]
steps:
- uses: actions/download-artifact@v2
with:
name: pkg-${{ matrix.os }}-${{ matrix.ar }}
- run: "shasum *"
- uses: actions/upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: pkg-${{ matrix.os }}-${{ matrix.ar }}
asset_name: pkg-${{ matrix.os }}-${{ matrix.ar }}
asset_content_type: application/binary
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
needs: release
env:
PACKAGE: github.com/kentik/pkg