58 lines
1.7 KiB
YAML
58 lines
1.7 KiB
YAML
name: CI
|
|
on:
|
|
push:
|
|
branches: [ develop ]
|
|
pull_request:
|
|
branches: [ develop ]
|
|
jobs:
|
|
build-test:
|
|
runs-on: docker
|
|
container:
|
|
image: golang:1.26
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
- name: Run tests with coverage
|
|
run: |
|
|
go test -v -coverprofile=coverage.out -coverpkg=./... ./...
|
|
go tool cover -func=coverage.out | tee coverage.txt
|
|
cov=$(go tool cover -func=coverage.out | grep total: | awk '{print substr($3, 1, length($3)-1)}')
|
|
cov=${cov%.*}
|
|
if [ "$cov" -lt 80 ]; then
|
|
echo "::warning::Test coverage is below 80% ($cov%)"
|
|
fi
|
|
- name: Build binary
|
|
run: go build ./...
|
|
|
|
docker:
|
|
runs-on: dind
|
|
needs: build-test
|
|
if: gitea.event_name == 'push'
|
|
container:
|
|
image: docker:cli
|
|
services:
|
|
dind:
|
|
image: docker:dind
|
|
options: --privileged
|
|
env:
|
|
DOCKER_TLS_CERTDIR: ""
|
|
env:
|
|
DOCKER_HOST: tcp://dind:2375
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v6
|
|
- name: Log in to Gitea registry
|
|
run: |
|
|
REGISTRY="${{ gitea.server_url }}"
|
|
REGISTRY="${REGISTRY#https://}"
|
|
REGISTRY="${REGISTRY#http://}"
|
|
echo "${{ secrets.GITEA_TOKEN }}" | docker login "$REGISTRY" -u "${{ gitea.actor }}" --password-stdin
|
|
- name: Build and push
|
|
run: |
|
|
REGISTRY="${{ gitea.server_url }}"
|
|
REGISTRY="${REGISTRY#https://}"
|
|
REGISTRY="${REGISTRY#http://}"
|
|
IMAGE="$REGISTRY/${{ gitea.repository }}"
|
|
docker build -t "$IMAGE:${{ gitea.sha }}" -t "$IMAGE:latest" .
|
|
docker push "$IMAGE:${{ gitea.sha }}"
|
|
docker push "$IMAGE:latest" |