This repository was archived by the owner on Jul 11, 2025. It is now read-only.
fix(CI): Update healthcheck settings and improve logging configuratio… #49
This file contains hidden or 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
| # This workflow will build a golang project | |
| # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go | |
| name: Go | |
| on: | |
| push: | |
| branches: [ "main","dev" ] | |
| jobs: | |
| lint: | |
| name: Lint | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.24.2' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Use example .env | |
| run: cp .env.test .env | |
| - name: Generate Prisma Client Go | |
| run: go run github.com/steebchen/prisma-client-go generate --schema internal/database/prisma/schema.prisma | |
| - name: Go Vet | |
| run: go vet ./... | |
| test: | |
| name: Test | |
| needs: lint | |
| runs-on: ubuntu-latest | |
| services: | |
| postgres: | |
| image: postgres:16 | |
| env: | |
| POSTGRES_USER: root | |
| POSTGRES_PASSWORD: 123456 | |
| POSTGRES_DB: testing | |
| ports: | |
| - 5432:5432 | |
| options: >- | |
| --health-cmd pg_isready | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 5 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Go | |
| uses: actions/setup-go@v4 | |
| with: | |
| go-version: '1.24.2' | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cache/go-build | |
| ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Use example .env | |
| run: cp .env.test .env | |
| - name: Generate Prisma Client Go | |
| run: go run github.com/steebchen/prisma-client-go db push --schema internal/database/prisma/schema.prisma | |
| - name: Run tests with coverage | |
| run: GIN_MODE=test go test -v -coverprofile=coverage.out ./... | |
| - name: Show coverage summary | |
| run: go tool cover -func=coverage.out | |
| build-docker: | |
| name: Build Docker Image | |
| needs: [lint, test] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| env: | |
| GIN_MODE: ${{ github.ref == 'refs/heads/main' && 'release' || 'debug' }} | |
| REGISTRY: ghcr.io | |
| IMAGE_NAME: q300z/cesizen-api | |
| concurrency: | |
| group: build-docker-${{ github.ref }} | |
| cancel-in-progress: true | |
| steps: | |
| - name: Checkout source | |
| uses: actions/checkout@v4 | |
| - name: Get short commit SHA | |
| id: vars | |
| run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| - name: Set image tags | |
| run: | | |
| if [ "${{ env.GIN_MODE }}" = "release" ]; then | |
| echo "TAG=latest" >> $GITHUB_ENV | |
| echo "VERSION=prod-${{ steps.vars.outputs.SHORT_SHA }}" >> $GITHUB_ENV | |
| else | |
| echo "TAG=dev" >> $GITHUB_ENV | |
| echo "VERSION=dev-${{ steps.vars.outputs.SHORT_SHA }}" >> $GITHUB_ENV | |
| fi | |
| - name: Log in to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| push: true | |
| tags: | | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.TAG }} | |
| ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }} | |
| build-args: | | |
| GIN_MODE=${{ env.GIN_MODE }} | |
| VERSION=${{ env.VERSION }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |