Files
Civ/.github/workflows/publish_container.yaml
AngrySoundTech 8bcdca1831 _ENV -> _OUTPUT
2024-03-13 15:47:05 -04:00

89 lines
3.0 KiB
YAML

# Publish a container
name: 🐋 Container | Publish
on:
workflow_dispatch:
inputs:
project:
required: true
description: 'The container to publish'
type: string
version:
required: true
description: 'The version to release'
type: string
category:
required: true
description: 'The category of project'
type: choice
options:
- containers
push:
tags:
- 'containers/*/v*.*.*'
jobs:
# This job either uses the inputs from the workflow_dispatch event,
# or will split values out of the pushed tag.
# This allows the release manager to either create a release themselves and have this job pick it up,
# Or run this job to create a release.
determine_values:
name: 🔎 Determine Values
runs-on: ubuntu-latest
outputs:
category: ${{ steps.determine_values.outputs.category }}
version: ${{ steps.determine_values.outputs.version }}
project: ${{ steps.determine_values.outputs.project }}
steps:
- name: 🔎 Determine Project Values
id: determine_values
env:
CATEGORY_OVERRIDE: ${{ inputs.category }}
PROJECT_OVERRIDE: ${{ inputs.project }}
VERSION_OVERRIDE: ${{ inputs.version }}
TAG: ${{ github.ref_name }}
run: |
echo "category=${CATEGORY_OVERRIDE:-${TAG%%/*}}" >> $GITHUB_OUTPUT
echo "version=${VERSION_OVERRIDE:-${TAG##*/}}" >> $GITHUB_OUTPUT
dirname "project=${PROJECT_OVERRIDE:-${TAG#*/}}" >> $GITHUB_OUTPUT
publish_container:
name: 🐋 Publish Container
needs: determine_values
runs-on: ubuntu-latest
steps:
- name: 🚩 Checkout Repo
uses: actions/checkout@v4
- name: 🔎 Introspect metadata
id: metadata
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/civmc/civ/${{needs.determine_values.outputs.project}}
tags: |
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
type=ref,event=branch
type=semver,pattern={{version}},value=${{needs.determine_values.outputs.version}}
type=semver,pattern={{major}}.{{minor}},value=${{needs.determine_values.outputs.version}}
type=semver,pattern={{major}},value=${{needs.determine_values.outputs.version}}
- name: 🪵 Login to Github Packages
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🐳 Build and push
uses: docker/build-push-action@v5
with:
context: containers/${{needs.determine_values.outputs.project}}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}