-
Notifications
You must be signed in to change notification settings - Fork 5
140 lines (116 loc) · 3.54 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
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.20 # 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.20 \
bash -c "go mod tidy && go test ./pkg/... ./cmd/kafka-lag-go/... -v -cover"
e2e-test:
name: E2E test Stage
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main' || github.event_name == 'release'
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Docker Compose
run: sudo apt-get update && sudo apt-get install -y docker-compose
- name: Run E2E tests in Go container
run: ./e2e_tests.sh
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