Files
ombi-mcp/.gitea/workflows/build.yml
T
gronod 05e62048d8
Build and publish / Test and build (windows) (push) Failing after 14s
Build and publish / Test and build (darwin) (push) Successful in 3m34s
Build and publish / Test and build (linux) (push) Canceled after 0s
Build and publish / Build and publish Docker image (push) Canceled after 0s
Add Gitea CI builds and container publishing
2026-09-18 21:04:38 +01:00

138 lines
4.5 KiB
YAML

name: Build and publish
on:
push:
branches: ['**']
tags: ['v*']
pull_request:
workflow_dispatch:
env:
CGO_ENABLED: '0'
# CI uses the mock Ombi; never inherit a runner's live instance config.
OMBI_URL: ''
jobs:
binaries:
name: Test and build (${{ matrix.goos }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- runner: macos
goos: darwin
- runner: linux
goos: linux
- runner: windows
goos: windows
defaults:
run:
shell: bash
steps:
- uses: https://github.com/actions/checkout@v4
with:
persist-credentials: false
- uses: https://github.com/actions/setup-go@v5
with:
go-version-file: go.mod
cache: false
- name: Check formatting
run: |
files=$(gofmt -l .)
if [ -n "$files" ]; then
printf 'Run gofmt on:\n%s\n' "$files"
exit 1
fi
- name: Vet
run: go vet ./...
- name: Unit tests
run: go test ./...
- name: Mock integration tests
if: matrix.goos == 'linux'
run: go test -tags integration ./internal/integration_test/
- name: Build and package
env:
GOOS: ${{ matrix.goos }}
run: |
for arch in amd64 arm64; do
package="ombi-mcp-${GOOS}-${arch}"
binary=ombi-mcp
if [ "$GOOS" = windows ]; then binary=ombi-mcp.exe; fi
mkdir -p "dist/$package"
GOARCH="$arch" go build -trimpath -ldflags='-s -w' -o "dist/$package/$binary" ./cmd/ombi-mcp
cp README.md "dist/$package/"
tar -czf "dist/$package.tar.gz" -C dist "$package"
done
# v3 uses the artifact API supported by older Gitea installations too.
- uses: https://github.com/actions/upload-artifact@v3
with:
name: ombi-mcp-${{ matrix.goos }}
path: dist/*.tar.gz
if-no-files-found: error
docker:
name: Build and publish Docker image
needs: binaries
runs-on: linux
defaults:
run:
shell: bash
steps:
- uses: https://github.com/actions/checkout@v4
with:
persist-credentials: false
- name: Image metadata
id: image
env:
REPOSITORY: ${{ gitea.repository }}
COMMIT_SHA: ${{ gitea.sha }}
REF: ${{ gitea.ref }}
EVENT_NAME: ${{ gitea.event_name }}
DEFAULT_BRANCH: ${{ gitea.event.repository.default_branch }}
run: |
image="git.i3omb.com/$(printf '%s' "$REPOSITORY" | tr '[:upper:]' '[:lower:]')"
publish=false
tags="$image:sha-$COMMIT_SHA"
if [ "$EVENT_NAME" = push ]; then
if [ "$REF" = "refs/heads/$DEFAULT_BRANCH" ]; then
publish=true
tags="$tags,$image:latest"
elif [[ "$REF" == refs/tags/v* ]]; then
tag="${REF#refs/tags/}"
if [[ ! "$tag" =~ ^[a-zA-Z0-9_][a-zA-Z0-9_.-]{0,127}$ ]]; then
echo 'Version tag is not a valid Docker tag'
exit 1
fi
publish=true
tags="$tags,$image:$tag"
fi
fi
echo "publish=$publish" >> "$GITHUB_OUTPUT"
echo "tags=$tags" >> "$GITHUB_OUTPUT"
echo "go_version=$(awk '$1 == "go" { print $2 }' go.mod)" >> "$GITHUB_OUTPUT"
- uses: https://github.com/docker/setup-buildx-action@v3
- name: Log in to Gitea registry
if: steps.image.outputs.publish == 'true'
uses: https://github.com/docker/login-action@v3
with:
registry: git.i3omb.com
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Build image (push only for default branch and version tags)
uses: https://github.com/docker/build-push-action@v6
env:
# Build records use GitHub's v4 artifact API, not Gitea's API.
DOCKER_BUILD_RECORD_UPLOAD: 'false'
DOCKER_BUILD_SUMMARY: 'false'
with:
context: .
platforms: linux/amd64,linux/arm64
build-args: |
GO_VERSION=${{ steps.image.outputs.go_version }}
push: ${{ steps.image.outputs.publish == 'true' }}
tags: ${{ steps.image.outputs.tags }}
labels: |
org.opencontainers.image.source=${{ gitea.server_url }}/${{ gitea.repository }}
org.opencontainers.image.revision=${{ gitea.sha }}