Files
apocapoc-api/.github/workflows/docker-publish.yml
T
david ac521c38a8 Improve Docker image tagging strategy and remove Swagger version
- Replace 'stable' tag with semver-based tags (1.2.3, 1.2, 1)
- Use 'edge' tag for main branch instead of 'latest'
- Reserve 'latest' tag only for tagged releases
- Remove version from Swagger docs (tracked via git tags instead)
- Document available image tags in README
2025-11-27 23:59:27 +01:00

97 lines
2.3 KiB
YAML

name: CI/CD Pipeline
on:
push:
branches: [ main ]
tags: [ 'v*' ]
pull_request:
branches: [ main ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
if: github.server_url == 'https://github.com'
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Run tests
run: go test ./... -v -race -coverprofile=coverage.txt -covermode=atomic
- name: Check code coverage
run: |
total=$(go tool cover -func=coverage.txt | grep total | awk '{print $3}' | sed 's/%//')
echo "Total coverage: $total%"
if (( $(echo "$total < 50" | bc -l) )); then
echo "Error: Code coverage is below 50%"
exit 1
fi
lint:
name: Lint
runs-on: ubuntu-latest
if: github.server_url == 'https://github.com'
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Run go vet
run: go vet ./...
- name: Run go fmt
run: |
if [ -n "$(gofmt -s -l .)" ]; then
echo "Go code is not formatted:"
gofmt -s -d .
exit 1
fi
build:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [test, lint]
if: github.event_name == 'push' && github.server_url == 'https://github.com'
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix=sha-
type=raw,value=edge,enable={{is_default_branch}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}