forked from slok/sloth
-
Notifications
You must be signed in to change notification settings - Fork 3
159 lines (145 loc) · 5.13 KB
/
ci.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
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
name: CI
on: [push, pull_request]
jobs:
check:
name: Check
runs-on: ubuntu-latest
# Execute the checks inside the container instead the VM.
container: golangci/golangci-lint:v1.50.0-alpine
steps:
- uses: actions/checkout@v3
- run: ./scripts/check/check.sh
unit-test:
name: Unit test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- run: make ci-test
- uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_UPLOAD_TOKEN }}
file: ./.test_coverage.txt
fail_ci_if_error: false
helm-chart-test:
name: Helm chart test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Execute tests
env:
HELM_VERSION: v3.6.3
run: |
# Get dependencies.
echo "Getting dependencies..."
curl -L https://get.helm.sh/helm-${HELM_VERSION}-linux-amd64.tar.gz | tar -xz && mv ./linux-amd64/helm /usr/local/bin && chmod +x /usr/local/bin/helm
make ci-helm-test
integration-test-cli:
name: Integration test CLI
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Execute tests
run: |
# Build binary.
echo "Building binary..."
make ci-build
sudo mv ./bin/sloth /usr/local/bin/
# Execute integration tests.
echo "Executing integration tests..."
make ci-integration-cli
integration-test-k8s:
name: Integration test Kubernetes
runs-on: ubuntu-latest
strategy:
matrix:
kubernetes: [1.21.14, 1.22.15, 1.23.12, 1.24.6, 1.25.2]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Execute tests
env:
KIND_VERSION: v0.16.0
run: |
# Get dependencies.
echo "Getting dependencies..."
curl -Lo kind https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-linux-amd64 && chmod +x kind && sudo mv kind /usr/local/bin/
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v${{ matrix.kubernetes }}/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Start cluster.
echo "Starting ${{ matrix.kubernetes }} Kubernetes cluster..."
kind create cluster --image kindest/node:v${{ matrix.kubernetes }}
kind get kubeconfig > /tmp/test.kubeconfig
# Register CRDs.
kubectl apply -f ./pkg/kubernetes/gen/crd/
kubectl apply -f ./test/integration/crd
# Build binary.
echo "Building binary..."
make ci-build
sudo mv ./bin/sloth /usr/local/bin/
# Execute integration tests.
echo "Executing integration tests..."
export SLOTH_INTEGRATION_KUBE_CONFIG=/tmp/test.kubeconfig
make ci-integration-k8s
rolling-release-images:
# Only on main branch.
if: startsWith(github.ref, 'refs/heads/main')
env:
TAG_IMAGE_LATEST: "true"
PROD_IMAGE_NAME: ghcr.io/${GITHUB_REPOSITORY}
VERSION: ${GITHUB_SHA}
needs: [check, unit-test, integration-test-cli, integration-test-k8s, helm-chart-test]
name: Release images
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Docker login
run: docker login ghcr.io -u ${{ github.actor }} -p "${{ secrets.GITHUB_TOKEN }}"
- name: Build and publish docker images
run: make build-publish-image-all
tagged-release-images:
# Only on tags.
if: startsWith(github.ref, 'refs/tags/')
env:
PROD_IMAGE_NAME: ghcr.io/${GITHUB_REPOSITORY}
needs: [check, unit-test, integration-test-cli, integration-test-k8s, helm-chart-test]
name: Tagged release images
runs-on: ubuntu-latest
steps:
- run: echo "VERSION=${GITHUB_REF#refs/*/}" >> ${GITHUB_ENV} # Sets VERSION env var.
- uses: actions/checkout@v3
- name: Docker login
run: docker login ghcr.io -u ${{ github.actor }} -p "${{ secrets.GITHUB_TOKEN }}"
- name: Build and publish docker images
run: make build-publish-image-all
tagged-release-binaries:
# Only on tags.
if: startsWith(github.ref, 'refs/tags/')
needs: [check, unit-test, integration-test-cli, integration-test-k8s, helm-chart-test]
name: Tagged release binaries
runs-on: ubuntu-latest
steps:
- run: echo "VERSION=${GITHUB_REF#refs/*/}" >> ${GITHUB_ENV} # Sets VERSION env var.
- uses: actions/checkout@v3
- name: Build binaries
run: |
mkdir -p ./bin
chmod -R 0777 ./bin
make build-all
- name: Upload binaries
uses: xresloader/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
file: "bin/*"
tags: true
draft: true