forked from kro-run/kro
-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (67 loc) · 2.38 KB
/
build-push-image.yaml
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
name: Build and Publish
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
env:
KO_DOCKER_REPO: ghcr.io/${{ github.repository }}/controller
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Install Dependencies
run: |
go mod download
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.2
go install sigs.k8s.io/kustomize/kustomize/v5@v5.2.1
go install github.com/google/ko@latest
- name: Run tests
run: make test WHAT=unit
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set Release Version
run: |
if [[ $GITHUB_REF == refs/tags/v* ]]; then
# Trim the 'v' prefix from the tag
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
else
echo "RELEASE_VERSION=dev-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
fi
# Build and push image on push to main
- name: Build and Push Image
if: github.event_name != 'pull_request'
run: |
make publish-image
# Build image only on PR
- name: Build Image (PR)
if: github.event_name == 'pull_request'
run: |
make build-image
# Push helm chart only on tag
- name: Package and Push Helm Chart
if: github.ref_type == 'tag'
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | helm registry login ghcr.io -u ${{ github.actor }} --password-stdin
# Use sed compatible with Linux (GitHub Actions runners)
cp ./config/crd/bases/* helm/crds/
sed -i "s/tag: .*/tag: \"${RELEASE_VERSION}\"/" helm/values.yaml
sed -i "s/version: .*/version: ${RELEASE_VERSION}/" helm/Chart.yaml
sed -i "s/appVersion: .*/appVersion: \"${RELEASE_VERSION}\"/" helm/Chart.yaml
helm package helm
HELM_IMAGE=ghcr.io/${{ github.repository }} make publish-helm