-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (121 loc) · 4.46 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
name: build
on:
push:
branches:
tags:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
env:
build_platforms: "linux/amd64,linux/arm64"
app_name: "gpbackman"
steps:
- name: Set up go 1.20
uses: actions/setup-go@v3
with:
go-version: "1.20"
id: go
- name: Checkout
uses: actions/checkout@v3
- name: Build and test
run: |
go test -v -timeout=100s -covermode=count -coverprofile=$GITHUB_WORKSPACE/coverage.out ./...
env:
GOFLAGS: "-mod=vendor"
TZ: "Etc/UTC"
- name: Run linters
uses: golangci/golangci-lint-action@v3
with:
version: v1.53.3
env:
TZ: "Etc/UTC"
- name: Install goveralls
run: |
GO111MODULE=off go get -u github.com/mattn/goveralls
- name: Submit coverage
run: $(go env GOPATH)/bin/goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/coverage.out
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Run end-to-end tests
run: |
make test-e2e
- name: Build image and push master tag to ghcr.io and Docker Hub
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_PKG: ${{ secrets.GUTHUB_CR_PAT }}
DOCKERHUB_USER: ${{ secrets.DOCKEHUB_USER }}
DOCKERHUB_PKG: ${{ secrets.DOCKEHUB_TOKEN }}
GITHUB_SHA: ${{ github.sha}}
GITHUB_REF: ${{ github.ref}}
BUILD_PLATFORMS: ${{ env.build_platforms }}
APP_NAME: ${{ env.app_name }}
run: |
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
sha="$(echo ${GITHUB_SHA} | cut -c1-7)"
echo REPO_BUILD_TAG: ${ref}-${sha}
echo ${GITHUB_PKG} | docker login ghcr.io -u ${GITHUB_USER} --password-stdin
echo ${DOCKERHUB_PKG} | docker login -u ${DOCKERHUB_USER} --password-stdin
docker buildx build --push \
--build-arg REPO_BUILD_TAG=${ref}-${sha} \
--platform ${BUILD_PLATFORMS} \
-t ghcr.io/${GITHUB_USER}/${APP_NAME}:${ref} \
-t ${DOCKERHUB_USER}/${APP_NAME}:${ref} .
- name: Build image and push tag (latest) to ghcr.io and Docker Hub
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
env:
GITHUB_USER: ${{ github.actor }}
GITHUB_PKG: ${{ secrets.GUTHUB_CR_PAT }}
DOCKERHUB_USER: ${{ secrets.DOCKEHUB_USER }}
DOCKERHUB_PKG: ${{ secrets.DOCKEHUB_TOKEN }}
GITHUB_SHA: ${{ github.sha}}
GITHUB_REF: ${{ github.ref}}
BUILD_PLATFORMS: ${{ env.build_platforms }}
APP_NAME: ${{ env.app_name }}
run: |
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
build_ver="$(echo ${ref} | cut -c 2-)"
echo REPO_BUILD_TAG: ${build_ver}
echo ${GITHUB_PKG} | docker login ghcr.io -u ${GITHUB_USER} --password-stdin
echo ${DOCKERHUB_PKG} | docker login -u ${DOCKERHUB_USER} --password-stdin
docker buildx build --push \
--build-arg REPO_BUILD_TAG=${build_ver} \
--platform ${BUILD_PLATFORMS} \
-t ghcr.io/${GITHUB_USER}/${APP_NAME}:${ref} \
-t ghcr.io/${GITHUB_USER}/${APP_NAME}:latest \
-t ${DOCKERHUB_USER}/${APP_NAME}:${ref} \
-t ${DOCKERHUB_USER}/${APP_NAME}:latest .
goreleaser:
needs: build
runs-on: ubuntu-latest
env:
goreleaser_version: "v1.20.0"
steps:
- name: Set up go 1.20
uses: actions/setup-go@v3
with:
go-version: "1.20"
id: go
- name: Checkout
uses: actions/checkout@v3
- name: Get ref
id: vars
run: |
echo ::set-output name=ref::$(echo ${GITHUB_REF} | cut -d'/' -f3)
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
with:
distribution: goreleaser
version: ${{ env.goreleaser_version }}
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}