-
Notifications
You must be signed in to change notification settings - Fork 14
132 lines (116 loc) · 3.19 KB
/
ci.yaml
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: ci
on:
push:
branches:
- main
- release/**
tags:
- v[0-9]+.[0-9]+.[0-9]+-?**
defaults:
run:
shell: bash
jobs:
unit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Check docs up to date
run: |
set -euo pipefail
go run cmd/docs/main.go
if [[ `git status --porcelain` ]]; then
echo "Docs are not up-to-date"
exit 1
fi
- name: Run tests
run: go test -v ./pkg/...
- name: Report coverage
uses: codecov/[email protected]
build:
runs-on: ubuntu-latest
outputs:
digest: ${{ steps.build.outputs.digest }}
image: ${{ steps.build.outputs.image }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: Extract version
shell: bash
run: |
[[ $GITHUB_REF =~ ^refs\/tags\/v(.*)$ ]] && version=${BASH_REMATCH[1]} || version=${{ github.sha }}
echo "VERSION=${version}" >> $GITHUB_ENV
- name: Build
id: build
run: |
mkdir kp-binaries
build() {
OS=$1
ARCH=$2
echo "Building for $OS-$ARCH"
GOOS=$OS CGO_ENABLED=0 GOARCH=$ARCH go build \
-ldflags "-X 'github.com/vmware-tanzu/kpack-cli/pkg/rootcommand.Version=${{ env.VERSION }}' -X 'github.com/vmware-tanzu/kpack-cli/pkg/rootcommand.CommitSHA=$(git rev-parse --short HEAD)'" \
-o kp-binaries/kp-$OS-$ARCH-${{ env.VERSION }} \
./cmd/kp
}
build darwin amd64
build darwin arm64
build linux amd64
build linux arm64
build windows amd64
- name: Upload binaries
uses: actions/upload-artifact@v3
with:
name: kp-binaries
path: kp-binaries/
release:
needs:
- unit
- build
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Validate release version
run: |
echo "GITHUB_REF=${GITHUB_REF}"
[[ $GITHUB_REF =~ ^refs\/tags\/v(.*)$ ]] && version=${BASH_REMATCH[1]}
if [[ -z "${version}" ]]; then
echo "ERROR: version not detected."
exit 1
fi
echo "VERSION=${version}" >> $GITHUB_ENV
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Generate sha256sum
id: sha256
run: |
mkdir checksums
for binary in kp-binaries/*; do
name=$(basename $binary)
shasum -a 256 $binary > "checksums/${name}.sha256"
done
- name: Create Draft Release
uses: softprops/action-gh-release@v1
with:
name: kp v${{ env.VERSION }}
tag_name: v${{ env.VERSION }}
target_commitish: ${{ github.sha }}
token: ${{ secrets.RELEASE_TOKEN }}
draft: true
prerelease: true
generate_release_notes: true
files: |
kp-binaries/*
checksums/*