-
Notifications
You must be signed in to change notification settings - Fork 11
204 lines (184 loc) · 7.96 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
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
198
199
200
201
202
203
204
name: build
on:
push:
branches:
tags:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
env:
backrest_version: "2.53"
docker_backrest_version: "v0.27"
build_platforms: "linux/amd64,linux/arm64"
steps:
- name: Set up go 1.21
uses: actions/setup-go@v3
with:
go-version: "1.21"
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.56.2
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 }}
BACKREST_VERSION: ${{ env.backrest_version }}
DOCKER_BACKREST_VERSION: ${{ env.docker_backrest_version }}
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} \
--build-arg BACKREST_VERSION=${BACKREST_VERSION} \
--build-arg DOCKER_BACKREST_VERSION=${DOCKER_BACKREST_VERSION} \
--platform ${BUILD_PLATFORMS} \
-t ghcr.io/${GITHUB_USER}/pgbackrest_exporter:${ref} \
-t ${DOCKERHUB_USER}/pgbackrest_exporter:${ref} .
- name: Build alpine 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 }}
BACKREST_VERSION: ${{ env.backrest_version }}
DOCKER_BACKREST_VERSION: ${{ env.docker_backrest_version }}
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} \
--build-arg BACKREST_VERSION=${BACKREST_VERSION}-alpine \
--build-arg DOCKER_BACKREST_VERSION=${DOCKER_BACKREST_VERSION} \
--platform ${BUILD_PLATFORMS} \
-t ghcr.io/${GITHUB_USER}/pgbackrest_exporter:${ref}-alpine \
-t ${DOCKERHUB_USER}/pgbackrest_exporter:${ref}-alpine .
- 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 }}
BACKREST_VERSION: ${{ env.backrest_version }}
DOCKER_BACKREST_VERSION: ${{ env.docker_backrest_version }}
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} \
--build-arg BACKREST_VERSION=${BACKREST_VERSION} \
--build-arg DOCKER_BACKREST_VERSION=${DOCKER_BACKREST_VERSION} \
--platform ${BUILD_PLATFORMS} \
-t ghcr.io/${GITHUB_USER}/pgbackrest_exporter:${ref} \
-t ghcr.io/${GITHUB_USER}/pgbackrest_exporter:latest \
-t ${DOCKERHUB_USER}/pgbackrest_exporter:${ref} \
-t ${DOCKERHUB_USER}/pgbackrest_exporter:latest .
- name: Build alpine image and push tag 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 }}
BACKREST_VERSION: ${{ env.backrest_version }}
DOCKER_BACKREST_VERSION: ${{ env.docker_backrest_version }}
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} \
--build-arg BACKREST_VERSION=${BACKREST_VERSION}-alpine \
--build-arg DOCKER_BACKREST_VERSION=${DOCKER_BACKREST_VERSION} \
--platform ${BUILD_PLATFORMS} \
-t ghcr.io/${GITHUB_USER}/pgbackrest_exporter:${ref}-alpine \
-t ${DOCKERHUB_USER}/pgbackrest_exporter:${ref}-alpine .
goreleaser:
needs: build
runs-on: ubuntu-latest
env:
goreleaser_version: "v1.24.0"
steps:
- name: Set up go 1.21
uses: actions/setup-go@v3
with:
go-version: "1.21"
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: Check GoReleaser config
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: ${{ env.goreleaser_version }}
args: check .goreleaser.yml
- 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 }}