-
Notifications
You must be signed in to change notification settings - Fork 1
176 lines (152 loc) · 5.27 KB
/
main.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
name: CI
on:
push:
tags:
- "v*.*.*"
- "!v0.1.*"
jobs:
base:
runs-on: ubuntu-latest
outputs:
go_version: ${{ steps.get_versions.outputs.go_version }}
build_version: ${{ steps.get_versions.outputs.build_version }}
chart_version: ${{ steps.get_versions.outputs.chart_version }}
go_updated: ${{ steps.file_updates.outputs.go }}
yaml_updated: ${{ steps.file_updates.outputs.yaml }}
steps:
- name: Check out repo
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get versions
id: get_versions
run: |
echo ::set-output name=go_version::$(go mod edit -json | grep -Po '"Go":\s+"([0-9.]+)"' | sed -E 's/.+"([0-9.]+)"/\1/')
echo ::set-output name=build_version::${GITHUB_REF#refs/tags/v}
echo ::set-output name=chart_version::${GITHUB_REF#refs/tags/}
- name: Get last release
id: last_release
shell: bash
run: |
tag=$(gh release list | sed -n '1 p' | awk '{print $(NF -1);}')
sha=$(git show-ref --tags | grep $tag | awk '{print $1;}')
echo ::set-output name=sha::$sha
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check updated files
id: file_updates
uses: dorny/paths-filter@v2
with:
base: ${{ steps.last_release.outputs.sha }}
filters: |
go:
- '*.go'
- 'go.*'
yaml:
- 'deploy/cert-manager-webhook-gandi/*.yaml'
- 'deploy/cert-manager-webhook-gandi/templates/*.yaml'
build:
needs: base
if: ${{ needs.base.outputs.go_updated == 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
outputs:
tag_commit: ${{ steps.update_image.outputs.commit }}
steps:
- name: Check out repo
uses: actions/checkout@v2
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Set up Docker buildx
uses: docker/setup-buildx-action@v1
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
target: image
push: true
build-args: GO_VERSION=${{ needs.base.outputs.go_version }}
tags: quay.io/molnett/cert-manager-webhook-gandi:latest,quay.io/molnett/cert-manager-webhook-gandi:${{ needs.base.outputs.build_version }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Update Helm image tag
id: update_image
uses: fjogeleit/yaml-update-action@master
with:
valueFile: "deploy/cert-manager-webhook-gandi/values.yaml"
propertyPath: "image.tag"
value: ${{ needs.base.outputs.build_version }}
message: "Update image tag to ${{ needs.base.outputs.build_version }}"
token: ${{ secrets.GITHUB_TOKEN }}
branch: main
release:
needs:
- base
- build
if: |
needs.base.result == 'success' && (needs.build.result == 'success' || needs.base.outputs.yaml_updated == 'true')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Retrieve commit ref
id: commit_ref
run: |
if [[ '${{ needs.build.outputs.tag_commit }}' = '' ]]; then
sha=${{ github.sha }}
else
sha=${{ needs.build.outputs.tag_commit }}
fi
echo ::set-output name=sha::$sha
- name: Check out repo
uses: actions/checkout@v2
with:
fetch-depth: 0
ref: ${{ steps.commit_ref.outputs.sha }}
- name: Configure Git
run: |
git config user.name github-actions
git config user.email [email protected]
- name: Update Helm chart version
uses: fjogeleit/yaml-update-action@master
with:
valueFile: "deploy/cert-manager-webhook-gandi/Chart.yaml"
propertyPath: "version"
value: ${{ needs.base.outputs.chart_version }}
message: "Update chart version to ${{ needs.base.outputs.chart_version }}"
token: ${{ secrets.GITHUB_TOKEN }}
updateFile: true
branch: main
- name: Install Helm
uses: azure/setup-helm@v1
with:
version: v3.4.0
- name: Run chart-releaser
uses: helm/[email protected]
with:
charts_dir: deploy
env:
CR_RELEASE_NAME_TEMPLATE: "{{ .Version }}"
CR_TOKEN: ${{ secrets.GITHUB_TOKEN }}