chore: Adding E2e tests #12
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Pipeline | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
tags: | |
- 'v*.*.*' | |
release: | |
types: | |
- created | |
jobs: | |
test: | |
name: 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 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: 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 |