Skip to content

CI

CI #206

Workflow file for this run

name: CI
on:
push:
branches: ['**']
tags: ['**']
pull_request:
branches: ['**']
workflow_dispatch:
schedule:
- cron: '0 0 * * 0'
release:
types: [published]
env:
REGISTRY: ghcr.io
IMAGE_NAME: "${{ github.repository_owner }}/ofelia"
jobs:
unit:
name: unit tests
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
go-version: [1.24.x]
platform: [ubuntu-latest]
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Vet
run: go vet ./...
- name: Format check
run: |
unformatted=$(gofmt -l $(git ls-files '*.go'))
if [ -n "$unformatted" ]; then
echo "The following files are not formatted:" >&2
echo "$unformatted" >&2
exit 1
fi
- name: Unit tests
run: go test ./...
integration:
name: integration tests
needs: unit
runs-on: ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
go-version: [1.24.x]
platform: [ubuntu-latest]
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Install Docker
uses: docker/setup-buildx-action@v3
- name: Start Docker service
run: sudo systemctl start docker
- name: Confirm Docker
run: docker info
- name: Integration tests
run: go test -tags=integration ./...
codeql:
# skip merge queue branches as they disappear before the upload step
if: (github.event_name != 'push') || (!startsWith(github.ref, 'refs/heads/gh-readonly-queue/'))
name: CodeQL Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.24.x
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: go
- name: Download dependencies
run: go mod download
- name: Build
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
build_image:
name: Build and push container image
# push container image only for commits on the main branch to keep
# ghcr.io from accumulating untagged images on every branch push
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
env:
IMAGE_NAME: "${{ github.repository_owner }}/ofelia:edge"
permissions:
contents: read
packages: write
id-token: write
attestations: write
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
id: push
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
platforms: linux/amd64,linux/arm/v7,linux/arm64
release_binaries:
if: github.event_name == 'release'
strategy:
fail-fast: false
matrix:
goos: [linux, darwin]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Release binaries
uses: wangyoucao577/go-release-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: amd64
release_docker:
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set release version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.RELEASE_VERSION }}
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64