-
Notifications
You must be signed in to change notification settings - Fork 2
102 lines (97 loc) · 3.12 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
name: Build
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/golang@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
command: monitor
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Download deps
run: |
wget --output-document=gotestsum.tgz https://github.com/gotestyourself/gotestsum/releases/download/v0.3.5/gotestsum_0.3.5_linux_amd64.tar.gz
tar xzf gotestsum.tgz
rm -f gotestsum.tgz
- name: Test
uses: docker://golang:1-stretch
with:
args: ./gotestsum --jsonfile tests-reports.json -- -count=1 -coverprofile coverage-sonar.out -coverpkg=./... ./...
env:
XDG_CACHE_HOME: /tmp/.cache
HOME: /tmp/buildhome
- name: SonarCloud Scan
uses: sonarsource/[email protected]
# Do this only on push commit do not need to be re-analyzed on PR
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
build:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: [tests, security]
strategy:
matrix:
os: [linux, darwin, windows]
arch: [386, amd64]
steps:
- uses: actions/checkout@v1
- name: prepare env for ${{ matrix.os }}_${{ matrix.arch }}
run: mkdir -p ./build/${{ matrix.os }}_${{ matrix.arch }}
- name: Build
uses: docker://golang:1-stretch
with:
args: go build -o ./build/${{ matrix.os }}_${{ matrix.arch }}/ ./cmd/tdt2go
env:
XDG_CACHE_HOME: /tmp/.cache
HOME: /tmp/buildhome
CGO_ENABLED: 0
GOOS: ${{ matrix.os }}
GOARCH: ${{ matrix.arch }}
- name: zip files
run: |
for PLATFORM in $(find ./build -mindepth 1 -maxdepth 1 -type d); do
OSARCH=$(basename ${PLATFORM})
echo "--> ${OSARCH}"
pushd $PLATFORM >/dev/null 2>&1
zip ../tdt2go_${OSARCH}.zip ./*
tar czvf ../tdt2go_${OSARCH}.tgz ./*
popd >/dev/null 2>&1
rm -fr $PLATFORM
done
- name: Upload tgz artifact
uses: actions/[email protected]
if: matrix.os != 'windows'
with:
name: tdt2go-bins
path: ./build/tdt2go_${{ matrix.os }}_${{ matrix.arch }}.tgz
- name: Upload zip artifact
uses: actions/[email protected]
with:
name: tdt2go-bins
path: ./build/tdt2go_${{ matrix.os }}_${{ matrix.arch }}.zip
release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
needs: [build]
steps:
- name: Download artifact
uses: actions/[email protected]
with:
name: tdt2go-bins
path: build
- name: GH Release
uses: softprops/action-gh-release@v1
id: make-release
with:
files: ./build/tdt2go_*_*.*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}