7
7
paths-ignore :
8
8
- ' **.md'
9
9
- ' LICENSE'
10
+ tags :
11
+ - ' v[0-9]+.[0-9]+.[0-9]+'
10
12
pull_request :
11
13
branches :
12
14
- master
17
19
- opened
18
20
- reopened
19
21
- synchronize
20
- create :
21
- tags :
22
- - ' v[0-9]+.[0-9]+.[0-9]+*'
22
+ schedule :
23
+ - cron : ' 0 3 * * *'
23
24
24
25
env :
25
- DOCKER_BUILDKIT : 1
26
+ DOCKER_PLATFORMS : " linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386"
27
+
26
28
27
29
jobs :
28
30
@@ -41,66 +43,17 @@ jobs:
41
43
- name : Run Tests
42
44
run : make test
43
45
44
- build :
45
- name : Build Image
46
+ build-docker :
47
+ name : Build Docker Image
46
48
runs-on : ubuntu-20.04
49
+ needs : [unit-tests]
47
50
steps :
48
51
- name : Checkout Repository
49
52
uses : actions/checkout@v2
50
53
with :
51
54
fetch-depth : 0
52
55
- name : Determine Go version from go.mod
53
56
run : echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
54
- - name : Setup QEMU
55
- uses : docker/setup-qemu-action@v1
56
- with :
57
- platforms : arm,arm64,ppc64le,s390x,mips64le,386
58
- - name : Docker Buildx
59
- uses : docker/setup-buildx-action@v1
60
- - name : Determine GOPATH
61
- run : echo "GOPATH=$(go env GOPATH)" >> $GITHUB_ENV
62
- - name : Setup Golang Environment
63
- uses : actions/setup-go@v2
64
- with :
65
- go-version : ${{ env.GO_VERSION }}
66
- - name : Run GoReleaser
67
- uses : goreleaser/goreleaser-action@v2
68
- with :
69
- version : latest
70
- args : build --snapshot --rm-dist
71
- env :
72
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
73
- GOPATH : ${{ env.GOPATH }}
74
- - name : Build Image
75
- uses : docker/build-push-action@v2
76
- with :
77
- file : build/Dockerfile
78
- context : ' .'
79
- target : local
80
- platforms : linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386
81
- cache-from : type=gha
82
- cache-to : type=gha,mode=max
83
- tags : nginx/nginx-prometheus-exporter:${{ github.sha }}
84
- push : false
85
-
86
- release-docker :
87
- name : Release Image
88
- runs-on : ubuntu-20.04
89
- needs : [build, unit-tests]
90
- if :
91
- github.repository == 'nginxinc/nginx-prometheus-exporter' &&
92
- github.event_name == 'create' &&
93
- contains(github.ref, 'refs/tags/')
94
- steps :
95
- - name : Checkout Repository
96
- uses : actions/checkout@v2
97
- with :
98
- fetch-depth : 0
99
- - name : Retrieve Tag
100
- id : get_version
101
- run : echo ::set-output name=GIT_TAG::$(echo ${GITHUB_REF/refs\/tags\//} | tr -d v)
102
- - name : Determine Go version from go.mod
103
- run : echo "GO_VERSION=$(grep "go 1." go.mod | cut -d " " -f 2)" >> $GITHUB_ENV
104
57
- name : Setup Golang Environment
105
58
uses : actions/setup-go@v2
106
59
with :
@@ -109,24 +62,40 @@ jobs:
109
62
uses : docker/setup-qemu-action@v1
110
63
with :
111
64
platforms : arm,arm64,ppc64le,s390x,mips64le,386
65
+ if : github.event_name != 'pull_request'
112
66
- name : Docker Buildx
113
67
uses : docker/setup-buildx-action@v1
114
68
- name : DockerHub Login
115
69
uses : docker/login-action@v1
116
70
with :
117
71
username : ${{ secrets.DOCKER_USERNAME }}
118
72
password : ${{ secrets.DOCKER_PASSWORD }}
73
+ if : github.event_name != 'pull_request'
74
+ - name : Docker meta
75
+ id : meta
76
+ uses : docker/metadata-action@v3
77
+ with :
78
+ images : nginx/nginx-prometheus-exporter
79
+ tags : |
80
+ type=edge
81
+ type=ref,event=pr
82
+ type=schedule
83
+ type=semver,pattern={{version}}
84
+ type=semver,pattern={{major}}.{{minor}}
85
+ labels : |
86
+ org.opencontainers.image.vendor=NGINX Inc <[email protected] >
119
87
- name : Publish Release Notes
120
88
uses : release-drafter/release-drafter@v5
121
89
with :
122
90
publish : true
123
91
env :
124
92
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
93
+ if : ${{ startsWith(github.ref, 'refs/tags/') }}
125
94
- name : Run GoReleaser
126
95
uses : goreleaser/goreleaser-action@v2
127
96
with :
128
97
version : latest
129
- args : release --rm-dist
98
+ args : --rm-dist ${{ github.event_name == 'pull_request' && '--single-target' || '' }} ${{ !startsWith(github.ref, 'refs/tags/') && 'build --snapshot' || 'release' }}
130
99
env :
131
100
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
132
101
GOPATH : ${{ env.GOPATH }}
@@ -136,19 +105,21 @@ jobs:
136
105
file : build/Dockerfile
137
106
context : ' .'
138
107
target : local
139
- platforms : linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386
140
- tags : |
141
- nginx/nginx-prometheus-exporter:latest
142
- nginx/nginx-prometheus-exporter:${{ steps.get_version.outputs.GIT_TAG }}
143
- push : true
108
+ platforms : ${{ github.event_name != 'pull_request' && env.DOCKER_PLATFORMS || '' }}
109
+ tags : ${{ steps.meta.outputs.tags }}
110
+ labels : ${{ steps.meta.outputs.labels }}
111
+ load : ${{ github.event_name == 'pull_request' }}
112
+ push : ${{ github.event_name != 'pull_request' }}
113
+ cache-from : type=gha
114
+ cache-to : type=gha,mode=max
144
115
build-args : |
145
- VERSION=${{ steps.get_version .outputs.GIT_TAG }}
116
+ VERSION=${{ steps.meta .outputs.version }}
146
117
GIT_COMMIT=${{ github.sha }}
147
118
148
119
notify :
149
120
name : Notify
150
121
runs-on : ubuntu-20.04
151
- needs : release -docker
122
+ needs : build -docker
152
123
if : always() && github.ref == 'refs/heads/master'
153
124
steps :
154
125
- name : Workflow Status
0 commit comments