-
Notifications
You must be signed in to change notification settings - Fork 1
197 lines (176 loc) · 5.54 KB
/
go.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Go
on:
push:
paths:
- '**.go'
- '.github/workflows/**'
pull_request:
paths:
- '**.go'
- '.github/workflows/**'
jobs:
linter:
name: "golang-linter"
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.17
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.43
skip-go-installation: true
test:
name: Unit Test
needs: [linter]
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v2
- name: before cache
run: |
mkdir -p ~/go/pkg/mod
- uses: actions/cache@v2.1.2
id: cache-go
with:
key: ${{ matrix.os }}-go-${{ hashFiles('**/go.sum') }}
path: ~/go/pkg/mod
restore-keys: |
go-${{ matrix.os }}-
- name: Setup GoLang
uses: actions/setup-go@v3
with:
go-version: ^1.17
- name: Get Dependencies
if: steps.cache-go.outputs.cache-hit != 'true'
run: go get -v -t -d ./...
- name: Test
run: |
go test -v ./...
build:
name: Build release binary
runs-on: ${{ matrix.os }}
needs: [linter, test]
if: contains(github.ref, 'tags/v')
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v2.3.3
- name: before cache
run: |
mkdir -p ~/go/pkg/mod
- uses: actions/cache@v2.1.2
id: cache-go
with:
key: ${{ matrix.os }}-go-${{ hashFiles('**/go.sum') }}
path: ~/go/pkg/mod
restore-keys: |
go-${{ matrix.os }}-
- name: Setup GoLang
uses: actions/setup-go@v2.1.3
with:
go-version: ^1.17
- name: Get Dependencies
if: steps.cache-go.outputs.cache-hit != 'true'
run: go get -v -t -d ./...
- name: vars
id: vars
shell: bash
run: |
echo ::set-output name=os::"$(echo ${{ matrix.os }} | sed 's/-latest//g;s/ubuntu/linux/g')"
echo ::set-output name=version::${TAG_REF_NAME##*/v}
env:
TAG_REF_NAME: ${{ github.ref }}
- name: Build
run: |
mkdir ./${{ steps.vars.outputs.os }}
go build -v -o ${{ steps.vars.outputs.os }}/go-cdx
- name: Create completion script
shell: bash
working-directory: ${{ steps.vars.outputs.os }}
run: |
mkdir -p $HOME/.config/go-cdx
touch $HOME/.config/go-cdx/go-cdx.yaml
[[ "${{ matrix.os }}" != "windows-latest" ]] && {
./go-cdx --completion zsh - > ./cdx-completion.zsh
./go-cdx --completion bash - > ./cdx-completion.bash
./go-cdx --completion fish - > ./cdx-completion.fish
}
./go-cdx --completion PowerShell - > ./cdx-completion.ps1
- name: Upload artifact
uses: actions/upload-artifact@v2.2.0
with:
name: ${{ steps.vars.outputs.os }}
path: ./${{ steps.vars.outputs.os }}
create-release:
needs: [linter, test, build]
if: contains(github.ref, 'tags/v')
runs-on: ubuntu-latest
steps:
- name: vars
id: vars
run: |
echo ::set-output name=version::${TAG_REF_NAME##*/v}
env:
TAG_REF_NAME: ${{ github.ref }}
- name: Create Release
uses: actions/create-release@v1.1.4
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.vars.outputs.version }}
release_name: Release ${{ steps.vars.outputs.version }}
draft: false
prerelease: false
- name: Output release url
run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt
- name: Save Release URL File for publish
uses: actions/upload-artifact@v2.2.0
with:
name: release_url
path: release_url.txt
upload-release:
runs-on: ubuntu-latest
if: contains(github.ref, 'tags/v')
needs: [linter, create-release, test, build]
strategy:
matrix:
os: [linux, windows, macOS]
steps:
- uses: actions/download-artifact@v4.1.7
with:
name: ${{ matrix.os }}
path: ${{ matrix.os }}
- uses: actions/download-artifact@v4.1.7
with:
name: release_url
- name: Get Release Info
id: get_release_info
shell: bash
run: |
echo ::set-output name=file_name::${REPOSITORY_NAME##*/}-${TAG_REF_NAME##*/v}
echo ::set-output name=upload_url::"$(cat release_url.txt)"
echo ::set-output name=version::${TAG_REF_NAME##*/v}
env:
TAG_REF_NAME: ${{ github.ref }}
REPOSITORY_NAME: ${{ github.repository }}
- name: Create Zip
shell: bash
run: |
zip -r ${{ matrix.os }} ${{ matrix.os }}
- name: Upload assets to GitHub Release
id: upload-release-asset
uses: actions/upload-release-asset@v1.0.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_release_info.outputs.upload_url }}
asset_path: ./${{ matrix.os }}.zip
asset_name: ${{ steps.get_release_info.outputs.file_name }}-${{ matrix.os }}.zip
asset_content_type: application/zip