-
Notifications
You must be signed in to change notification settings - Fork 79
109 lines (109 loc) · 3.79 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
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@v3
if: github.event_name == 'pull_request'
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: actions/checkout@v3
if: github.event_name != 'pull_request'
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Create temporary directory for yq install
run: |
mkdir ${{ runner.temp }}/yq
- name: Install yq
working-directory: ${{ runner.temp }}/yq
run: |
sudo rm /bin/yq
wget https://github.com/mikefarah/yq/releases/download/v4.11.2/yq_linux_amd64.tar.gz
tar -xzf yq_linux_amd64.tar.gz
sudo mv ./yq_linux_amd64 /usr/bin/yq
- 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: 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@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,arm'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- 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@v2
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 }}