-
Notifications
You must be signed in to change notification settings - Fork 78
112 lines (112 loc) · 3.89 KB
/
test_and_build_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
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
name: Run unit/integration tests and build image
on:
push:
branches:
- main
- 'release/**'
pull_request:
branches:
- main
- 'release/**'
paths-ignore:
- 'docs/**'
- 'CHANGELOG/**'
jobs:
unit_integration_tests:
name: Run unit/integration tests
runs-on: ubuntu-latest
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v4
if: github.event_name != 'pull_request'
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache: true
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest
# GHA requires longer timeout
args: --timeout=10m
# Optional: show only new issues if it's a pull request. The default value is `false`.
only-new-issues: ${{ github.event_name == 'pull_request' }}
skip-pkg-cache: true
skip-build-cache: true
- name: Run unit and integration tests
run: |
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
make envtest test
- name: Check that the build did not generate additional git changes
run: |
if [ -n "$(git status --porcelain)" ]; then
git status
exit 1
fi
- name: Run Vector tests
run: |
make vector-install vector-test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
build_image:
name: Build and push image to Docker Hub
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/')
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
- name: Set git parsed values
id: vars
run: |
echo "sha_short=$(git rev-parse --short=8 ${{ github.sha }})" >> $GITHUB_OUTPUT
- name: Compute tags
id: compute_tags
run: |
echo "TAGS=k8ssandra/k8ssandra-operator:${{ steps.vars.outputs.sha_short }},k8ssandra/k8ssandra-operator:latest" >> $GITHUB_ENV
- name: Compute release tags
id: compute_release_tags
if: startsWith(github.ref, 'refs/heads/release/')
run: |
echo "head ref = ${{ github.head_ref }}"
branch_ref=${{ github.ref }}
release_prefix=${branch_ref:19}
echo "TAGS=k8ssandra/k8ssandra-operator:${{ steps.vars.outputs.sha_short }},k8ssandra/k8ssandra-operator:${release_prefix}-latest" >> $GITHUB_ENV
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
file: Dockerfile
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ env.TAGS }}
platforms: linux/amd64,linux/arm64
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
helm_release:
if: github.ref == 'refs/heads/main' && github.event_name != 'pull_request'
name: Helm release
needs: unit_integration_tests
uses: ./.github/workflows/helm_release.yaml
with:
helm_repo: stable
prerelease: true
secrets:
GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
GCP_SA_KEY: ${{ secrets.GCP_SA_KEY }}
GCP_HELM_BUCKET_NAME: ${{ secrets.GCP_HELM_BUCKET_NAME }}