Skip to content

Commit 9f021e8

Browse files
authored
Simplify CI workflow, add edge and nightly (#217)
1 parent 802acbe commit 9f021e8

File tree

1 file changed

+35
-64
lines changed

1 file changed

+35
-64
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ on:
77
paths-ignore:
88
- '**.md'
99
- 'LICENSE'
10+
tags:
11+
- 'v[0-9]+.[0-9]+.[0-9]+'
1012
pull_request:
1113
branches:
1214
- master
@@ -17,12 +19,12 @@ on:
1719
- opened
1820
- reopened
1921
- synchronize
20-
create:
21-
tags:
22-
- 'v[0-9]+.[0-9]+.[0-9]+*'
22+
schedule:
23+
- cron: '0 3 * * *'
2324

2425
env:
25-
DOCKER_BUILDKIT: 1
26+
DOCKER_PLATFORMS: "linux/arm,linux/arm64,linux/amd64,linux/ppc64le,linux/s390x,linux/mips64le,linux/386"
27+
2628

2729
jobs:
2830

@@ -41,66 +43,17 @@ jobs:
4143
- name: Run Tests
4244
run: make test
4345

44-
build:
45-
name: Build Image
46+
build-docker:
47+
name: Build Docker Image
4648
runs-on: ubuntu-20.04
49+
needs: [unit-tests]
4750
steps:
4851
- name: Checkout Repository
4952
uses: actions/checkout@v2
5053
with:
5154
fetch-depth: 0
5255
- name: Determine Go version from go.mod
5356
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
10457
- name: Setup Golang Environment
10558
uses: actions/setup-go@v2
10659
with:
@@ -109,24 +62,40 @@ jobs:
10962
uses: docker/setup-qemu-action@v1
11063
with:
11164
platforms: arm,arm64,ppc64le,s390x,mips64le,386
65+
if: github.event_name != 'pull_request'
11266
- name: Docker Buildx
11367
uses: docker/setup-buildx-action@v1
11468
- name: DockerHub Login
11569
uses: docker/login-action@v1
11670
with:
11771
username: ${{ secrets.DOCKER_USERNAME }}
11872
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]>
11987
- name: Publish Release Notes
12088
uses: release-drafter/release-drafter@v5
12189
with:
12290
publish: true
12391
env:
12492
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
12594
- name: Run GoReleaser
12695
uses: goreleaser/goreleaser-action@v2
12796
with:
12897
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' }}
13099
env:
131100
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132101
GOPATH: ${{ env.GOPATH }}
@@ -136,19 +105,21 @@ jobs:
136105
file: build/Dockerfile
137106
context: '.'
138107
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
144115
build-args: |
145-
VERSION=${{ steps.get_version.outputs.GIT_TAG }}
116+
VERSION=${{ steps.meta.outputs.version }}
146117
GIT_COMMIT=${{ github.sha }}
147118
148119
notify:
149120
name: Notify
150121
runs-on: ubuntu-20.04
151-
needs: release-docker
122+
needs: build-docker
152123
if: always() && github.ref == 'refs/heads/master'
153124
steps:
154125
- name: Workflow Status

0 commit comments

Comments
 (0)