-
Notifications
You must be signed in to change notification settings - Fork 5
165 lines (139 loc) · 4.57 KB
/
ci-cd.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: CI/CD Pipeline
on:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- 'v*.*.*'
release:
types:
- created
jobs:
test:
name: Unit test Stage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Ensure go.mod exists with correct Go version
run: |
if [ ! -f go.mod ]; then
go mod init github.com/sciclon2/kafka-lag-go
go mod edit -go=1.21 # Set the Go version here
fi
go mod tidy
- name: Run Unit tests in Go container
run: |
docker run --rm \
-v "${{ github.workspace }}:/app" \
-w /app \
golang:1.21 \
bash -c "go mod tidy && go test ./pkg/... ./cmd/kafka-lag-go/... -v -cover"
discover-e2e-tests:
name: Discover E2E Test Folders
needs: [test]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release'
outputs:
e2e-folders: ${{ steps.set-outputs.outputs.e2e-folders }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Discover test folders
id: set-outputs
run: |
folders=$(find test/e2e/tests/* -maxdepth 0 -type d)
echo "e2e-folders=$(echo "$folders" | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT
e2e-test:
name: E2E Test Stage
needs: [discover-e2e-tests]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request' || (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release'
strategy:
matrix:
folder: ${{ fromJson(needs.discover-e2e-tests.outputs.e2e-folders) }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Docker Compose v2
run: |
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
chmod +x ~/.docker/cli-plugins/docker-compose
- name: Run E2E tests
run: |
echo "Running E2E tests for folder: ${{ matrix.folder }}"
./test/e2e/run.sh ${{ matrix.folder }}
build-and-push-dev:
name: Build and Push DEV Stage
runs-on: ubuntu-latest
needs: e2e-test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
use: true
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract short SHA
id: vars
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: Build and Push Multi-Arch Docker Image for DEV
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/kafka-lag-go:dev-${{ env.SHORT_SHA }}
- name: Check the Created Manifest
run: |
docker buildx imagetools inspect ${{ secrets.DOCKER_USERNAME }}/kafka-lag-go:dev-${{ env.SHORT_SHA }}
build-and-push-release:
name: Build and Push Release Stage
runs-on: ubuntu-latest
needs: e2e-test
if: github.event_name == 'release'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
use: true
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and Push Multi-Arch Docker Image for Release
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/kafka-lag-go:${{ github.event.release.tag_name }}
${{ secrets.DOCKER_USERNAME }}/kafka-lag-go:latest
- name: Check the Created Manifest
run: |
docker buildx imagetools inspect ${{ secrets.DOCKER_USERNAME }}/kafka-lag-go:latest