-
Notifications
You must be signed in to change notification settings - Fork 3
151 lines (142 loc) · 4.38 KB
/
image.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
name: Container Image
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GHCR_REGISTRY: ghcr.io
GAR_REGISTRY: europe-north1-docker.pkg.dev/nais-io/nais/images
ARTIFACT_REGISTRY: europe-north1-docker.pkg.dev
ARTIFACT_REPO: nais-io/nais/images
SERVICE_ACCOUNT: gh-bifrost@nais-io.iam.gserviceaccount.com
jobs:
meta:
name: Metadata
runs-on: ubuntu-latest
outputs:
"version": ${{ steps.version.outputs.version }}
"name": ${{ steps.name.outputs.name }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: version
run: echo "version=$(date +'%Y%m%d')-$(git rev-parse --short HEAD)" >> ${GITHUB_OUTPUT}
- id: name
run: echo "name=${{ github.event.repository.name }}" >> ${GITHUB_OUTPUT}
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go environment
uses: actions/setup-go@v5
with:
go-version: "1.23"
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
args: --timeout=5m
build:
name: Build and Test code
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Restore cached binaries
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}/bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile', 'go.mod') }}
- name: Set up Go environment
uses: actions/setup-go@v5
with:
go-version: "1.23"
- name: Install make
run: sudo apt-get update && sudo apt-get install make
- name: Generate code
run: |
make generate proto
if git diff --quiet HEAD --; then
echo "Code generated successfully."
else
echo "Code has generation issues."
echo $(git diff HEAD --)
echo "Please run 'make generate proto' and commit the changes."
exit 1
fi
- name: Generate manifests
run: |
make manifests
if git diff --quiet HEAD --; then
echo "Manifests generated successfully."
else
echo "Manifests have generation issues."
echo "Please run 'make manifests' and commit the changes."
exit 1
fi
- name: Generate helm chart
run: |
make helm
if git diff --quiet HEAD --; then
echo "Helm chart generated successfully."
else
echo "Helm chart has generation issues."
echo "Please run 'make helm' and commit the changes."
exit 1
fi
- name: Vet code
run: make vet
- name: Test code
run: make test
- name: Build binary
run: make build
- name: Cache installed binaries
uses: actions/cache@v4
with:
path: ${{ github.workspace }}/bin
key: ${{ runner.os }}-bin-${{ hashFiles('Makefile', 'go.mod') }}
docker:
name: Build and Push Docker image
runs-on: ubuntu-latest-16-cores
needs: [meta, lint, build]
steps:
- uses: actions/checkout@v4
- uses: docker/login-action@v3
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-buildx-action@v3
- uses: docker/metadata-action@v5
id: metadata
with:
images: |
${{ env.GHCR_REGISTRY }}/${{ github.repository }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=sha
type=raw,value=${{ needs.meta.outputs.version }}
- uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64