Feature: Prometheus Remote Write Support #75
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: 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 == '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 == '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 |