-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (94 loc) · 3 KB
/
release.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
name: Release
on:
push:
tags:
- v*
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Setup golang
uses: actions/setup-go@v1
with:
go-version: "1.19"
- name: Lint code
env:
GOBIN: /home/runner/go/bin
run: |
go vet ./...
test:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Setup golang
uses: actions/setup-go@v1
with:
go-version: "1.19"
- name: Run tests
env:
GOBIN: /home/runner/go/bin
run: |
# Install cli tools
go install github.com/onsi/ginkgo/v2/ginkgo@latest
# In seconds
SLOW_SPEC_THRESHOLD="${SLOW_SPEC_THRESHOLD:-60s}"
CGO_ENABLED=1 $GOBIN/ginkgo \
-r \
-race \
-randomize-all \
-randomize-suites \
-keep-going \
-slow-spec-threshold="${SLOW_SPEC_THRESHOLD}" \
-cover \
-covermode=atomic \
-output-dir=. \
-coverprofile=coverage.out
vulnerability-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Vulnerability scan
uses: snyk/actions/golang@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high
release:
runs-on: ubuntu-latest
needs: [lint, test, vulnerability-scan]
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Setup golang
uses: actions/setup-go@v1
with:
go-version: "1.19"
- name: Create release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
- name: Login to registry
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login --username shanman190 --password-stdin
- name: Build Docker image
run: |
# Image name
IMAGE="shanman190/pivnet-product-stemcell-resource"
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
go build -ldflags "-X main.version=$VERSION" -o ./cmd/check/check ./cmd/check/main.go
go build -ldflags "-X main.version=$VERSION" -o ./cmd/in/in ./cmd/in/main.go
go build -ldflags "-X main.version=$VERSION" -o ./cmd/out/out ./cmd/out/main.go
docker build --file Dockerfile --tag $IMAGE:$VERSION --tag $IMAGE:latest-final .
docker push $IMAGE:$VERSION
docker push $IMAGE:latest-final