-
-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (127 loc) · 3.62 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
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
name: Build
on:
push:
branches:
- '*'
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# dependencies
- name: Install GoReleaser
uses: goreleaser/goreleaser-action@v6
with:
install-only: true
- name: qemu
uses: docker/setup-qemu-action@v3
- name: buildx
uses: docker/setup-buildx-action@v3
# checkout
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# setup go
- name: go
uses: actions/setup-go@v5
with:
go-version: 1.16
- name: go info
run: |
go version
go env
# cache
- name: cache
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# vendor
- name: vendor
run: |
make vendor
# git status
- name: git status
run: git status
# build
- name: build
if: startsWith(github.ref, 'refs/tags/') == false
run: |
make snapshot
mv dist/crs_linux_amd64_v1 dist/crs_linux_amd64
# publish
- name: publish
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REF: ${{ github.ref }}
run: |
make publish
mv dist/crs_linux_amd64_v1 dist/crs_linux_amd64
# artifacts
- name: artifact_linux
if: ${{!github.event.repository.private}}
uses: actions/upload-artifact@v4
with:
name: build_linux
path: dist/*linux*
# docker login
- name: docker login
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
# docker build (latest & tag)
- name: release tag
if: startsWith(github.ref, 'refs/tags/') == true
uses: little-core-labs/[email protected]
id: releasetag
with:
tagRegex: "v?(.+)"
- name: docker - build release
if: startsWith(github.ref, 'refs/tags/') == true
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
push: true
tags: |
saltydk/crs:${{ steps.releasetag.outputs.tag }}
saltydk/crs:latest
# docker build (branch)
- name: branch name
if: startsWith(github.ref, 'refs/tags/') == false
id: branch-name
uses: tj-actions/branch-names@v8
- name: docker tag
if: startsWith(github.ref, 'refs/tags/') == false
uses: frabert/replace-string-action@master
id: dockertag
with:
pattern: '[:\.\/]+'
string: "${{ steps.branch-name.outputs.current_branch }}"
replace-with: '-'
flags: 'g'
- name: docker - build branch
if: startsWith(github.ref, 'refs/tags/') == false
uses: docker/build-push-action@v6
with:
context: .
file: ./docker/Dockerfile
platforms: linux/amd64,linux/arm64,linux/arm/v7
pull: true
push: true
tags: |
saltydk/crs:${{ steps.dockertag.outputs.replaced }}
# cleanup
- name: cleanup
run: |
rm -f ${HOME}/.docker/config.json