89 lines
2.7 KiB
YAML
89 lines
2.7 KiB
YAML
name: Build and Push Container
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
tags:
|
|
- v*
|
|
workflow_dispatch: null
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
|
|
env:
|
|
REGISTRY: gitea.wayfinderak.com
|
|
IMAGE_NAME: wayfinderak/prepbot
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number
|
|
|| github.run_id }}
|
|
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
|
|
|
jobs:
|
|
docker:
|
|
runs-on: butler-ci
|
|
steps:
|
|
- name: Checkout
|
|
uses: https://github.com/actions/checkout@v4
|
|
|
|
- name: Select relevant delivery work
|
|
id: delivery
|
|
env:
|
|
DELIVERY_EVENT: ${{ github.event_name }}
|
|
DELIVERY_REF: ${{ github.ref }}
|
|
DELIVERY_SHA: ${{ github.sha }}
|
|
DELIVERY_BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
|
|
run: |
|
|
cd .
|
|
bash scripts/ci-select.sh
|
|
- name: Set up QEMU
|
|
if: ${{ steps.delivery.outputs.run == 'true' }}
|
|
uses: https://github.com/docker/setup-qemu-action@v3
|
|
|
|
- name: Set up Docker Buildx
|
|
if: ${{ steps.delivery.outputs.run == 'true' }}
|
|
uses: https://github.com/docker/setup-buildx-action@v3
|
|
|
|
- name: Log in to Gitea registry
|
|
if: ${{ (steps.delivery.outputs.run == 'true') && github.event_name != 'pull_request' }}
|
|
uses: https://github.com/docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USERNAME }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Prepare image tags
|
|
if: ${{ steps.delivery.outputs.run == 'true' }}
|
|
id: prep
|
|
shell: bash
|
|
run: |
|
|
short_sha="${GITHUB_SHA::7}"
|
|
tags="${REGISTRY}/${IMAGE_NAME}:sha-${short_sha}"
|
|
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:sha-${GITHUB_SHA}"
|
|
|
|
if [[ "${GITHUB_REF_TYPE}" == "branch" && ("${GITHUB_REF_NAME}" == "master" || "${GITHUB_REF_NAME}" == "main") ]]; then
|
|
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:latest"
|
|
fi
|
|
|
|
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
|
|
version="${GITHUB_REF_NAME#v}"
|
|
tags+=$'\n'"${REGISTRY}/${IMAGE_NAME}:${version}"
|
|
fi
|
|
|
|
{
|
|
echo 'tags<<EOF'
|
|
echo "$tags"
|
|
echo 'EOF'
|
|
} >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Build and push image
|
|
if: ${{ steps.delivery.outputs.run == 'true' }}
|
|
uses: https://github.com/docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
platforms: linux/amd64,linux/arm64
|
|
tags: ${{ steps.prep.outputs.tags }}
|
|
labels: org.opencontainers.image.revision=${{ github.sha }}
|