diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dbd102e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,91 @@ +name: CI Pipeline + +on: + push: + branches: [ "cd" ] + pull_request: + branches: [ main, master ] + +jobs: + test: + name: Run Tests + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: '1.21' + cache: true + + - name: Install dependencies + run: | + cd gin-api + go mod download + + - name: Run tests + run: | + cd gin-api + go test ./... + + - name: Run test coverage + run: | + cd gin-api + go test -cover ./... + + build: + name: Build and Push Docker Images + runs-on: ubuntu-latest + needs: test + permissions: + contents: read + packages: write + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to GitHub Container Registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract backend metadata + id: meta-backend + uses: docker/metadata-action@v4 + with: + images: ghcr.io/${{ github.repository_owner }}/backend + tags: | + type=ref,event=branch + type=ref,event=pr + type=sha,format=short + + - name: Build and push backend image + uses: docker/build-push-action@v4 + with: + context: ./gin-api + file: ./gin-api/Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta-backend.outputs.tags }} + labels: ${{ steps.meta-backend.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build seeder image + uses: docker/build-push-action@v4 + with: + context: ./gin-api + file: ./gin-api/Dockerfile.seeder + push: false + tags: sviper-seeder:latest + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/gin-api/config/stub b/gin-api/config/stub new file mode 100644 index 0000000..e69de29