Skip to content

CI

CI #153

Workflow file for this run

name: CI
on:
push:
release:
types: [published]
workflow_dispatch:
inputs:
upload:
description: 'Upload the docker container'
required: false
default: false
type: boolean
env:
DOCKER_NAME: tpkg_registry
jobs:
build:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # Fetch the whole history.
# Use Go 1.17
- name: Switch to Go 1.17
uses: actions/setup-go@v5
with:
go-version: '^1.17.0'
# Get values for cache paths to be used in later steps
- name: Get Go paths
id: go-cache-paths
run: |
echo "go-build=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "go-mod=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
# Cache go build cache, used to speedup go test
- name: Go Build Cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-build-
# Cache go mod cache, used to speedup builds
- name: Go Mod Cache
uses: actions/cache@v4
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-mod-
- name: Go dependencies
run: |
make go_dependencies
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install protobuf-compiler
- name: Build protobuf
run: |
make protobuf
- name: Build binary
run: |
make registry
- name: Test
run: |
make test
- name: Fetch dependencies
run: |
make image-dependencies
- name: Print known-hosts
run: |
ssh-keyscan github.com >> known_hosts
echo "You can use the following known_hosts file to add to your secrets"
cat known_hosts
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_NAME }}
# Generate Docker tags based on the following events/attributes.
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Print configuration
run: |
echo "DOCKER_NAME=${{ env.DOCKER_NAME }}"
echo "BUILD_ARGS=${{ env.BUILD_ARGS }}"
echo "TAGS=${{ steps.meta.outputs.tags }}"
echo "LABELS=${{ steps.meta.outputs.labels }}"
- name: Login to GHCR
if: |
github.event.inputs.upload == 'true' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event_name == 'release'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
push: ${{
github.event.inputs.upload == 'true' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main') ||
github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
context: .