53 lines
1.5 KiB
YAML
53 lines
1.5 KiB
YAML
name: CI
|
|
on:
|
|
push: { branches: ["*"] }
|
|
pull_request: { branches: ["*"] }
|
|
jobs:
|
|
build:
|
|
name: Build & Test
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-go@v5
|
|
with: { go-version-file: "go.mod" }
|
|
- run: go mod download
|
|
- run: go build ./...
|
|
- run: go vet ./...
|
|
- run: go test -race -count=1 ./...
|
|
tidy:
|
|
name: Tidy
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- uses: actions/setup-go@v5
|
|
with: { go-version-file: "go.mod" }
|
|
- run: |
|
|
go mod tidy
|
|
git diff --exit-code go.mod go.sum
|
|
publish:
|
|
name: Publish Docker Image
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push'
|
|
needs: [build, tidy]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
- name: Log in to Gitea container registry
|
|
run: echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login gitea.stevedudenhoeffer.com --username "${{ secrets.REGISTRY_USER }}" --password-stdin
|
|
- name: Build and push Docker image
|
|
run: |
|
|
BRANCH="${{ github.ref_name }}"
|
|
SAFE_BRANCH="${BRANCH//\//-}"
|
|
REGISTRY="gitea.stevedudenhoeffer.com/steve/foreman"
|
|
|
|
docker build -t "${REGISTRY}:${SAFE_BRANCH}" .
|
|
|
|
if [ "${BRANCH}" = "main" ]; then
|
|
docker tag "${REGISTRY}:${SAFE_BRANCH}" "${REGISTRY}:latest"
|
|
fi
|
|
|
|
docker push "${REGISTRY}:${SAFE_BRANCH}"
|
|
|
|
if [ "${BRANCH}" = "main" ]; then
|
|
docker push "${REGISTRY}:latest"
|
|
fi
|