2023-09-15 15:27:42 +02:00
|
|
|
# This workflow will publish a docker image for every full release to the GitHub package repository
|
|
|
|
|
2024-04-05 17:39:06 +02:00
|
|
|
name: Create Docker Image (Release and Staging)
|
2023-09-15 15:27:42 +02:00
|
|
|
|
|
|
|
on:
|
|
|
|
release:
|
2024-02-11 14:38:41 +01:00
|
|
|
# Allow pre-releases
|
|
|
|
types: [published]
|
2024-04-05 17:39:06 +02:00
|
|
|
schedule:
|
|
|
|
# Build the staging image everyday at 00:00 UTC
|
|
|
|
- cron: "0 0 * * *"
|
2024-04-06 15:01:58 +02:00
|
|
|
push:
|
|
|
|
# Temporary workaround
|
|
|
|
branches:
|
|
|
|
- release
|
2023-09-15 15:27:42 +02:00
|
|
|
|
|
|
|
env:
|
|
|
|
# This should allow creation of docker images even in forked repositories
|
2024-04-06 14:55:06 +02:00
|
|
|
REPO: ${{ github.repository }}
|
2024-04-05 17:39:06 +02:00
|
|
|
REGISTRY: ghcr.io
|
2023-09-15 15:27:42 +02:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
build:
|
2024-04-28 04:55:49 +02:00
|
|
|
if: github.repository == 'SillyTavern/SillyTavern'
|
2023-09-15 15:27:42 +02:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
steps:
|
2024-04-07 16:31:48 +02:00
|
|
|
# Workaround for GitHub repo names containing uppercase characters
|
2024-04-06 15:00:42 +02:00
|
|
|
- name: Set lowercase repo name
|
2024-04-06 14:55:06 +02:00
|
|
|
run: |
|
2024-04-07 16:31:48 +02:00
|
|
|
echo "IMAGE_NAME=${REPO,,}" >> ${GITHUB_ENV}
|
2024-04-06 14:55:06 +02:00
|
|
|
|
2024-05-20 22:03:22 +02:00
|
|
|
# Using the following workaround because currently GitHub Actions
|
2024-04-05 17:39:06 +02:00
|
|
|
# does not support logical AND/OR operations on triggers
|
|
|
|
# It's currently not possible to have `branches` under the `schedule` trigger
|
2024-04-06 15:04:05 +02:00
|
|
|
- name: Checkout the release branch (on release)
|
2024-04-07 16:31:48 +02:00
|
|
|
if: ${{ github.event_name == 'release' || github.event_name == 'push' }}
|
|
|
|
uses: actions/checkout@v4.1.2
|
2024-04-06 15:04:05 +02:00
|
|
|
with:
|
|
|
|
ref: "release"
|
|
|
|
|
2024-04-05 17:39:06 +02:00
|
|
|
- name: Checkout the staging branch
|
|
|
|
if: ${{ github.event_name == 'schedule' }}
|
2024-04-07 16:31:48 +02:00
|
|
|
uses: actions/checkout@v4.1.2
|
2024-04-05 17:39:06 +02:00
|
|
|
with:
|
|
|
|
ref: "staging"
|
|
|
|
|
2024-04-07 16:31:48 +02:00
|
|
|
# Get current branch name
|
|
|
|
# This is also part of the workaround for Actions not allowing logical
|
|
|
|
# AND/OR operators on triggers
|
|
|
|
# Otherwise the action triggered by schedule always has ref_name = release
|
|
|
|
- name: Get the current branch name
|
|
|
|
run: |
|
|
|
|
echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> ${GITHUB_ENV}
|
|
|
|
|
2024-04-05 17:39:06 +02:00
|
|
|
# Setting up QEMU for multi-arch image build
|
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v3
|
|
|
|
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
|
|
|
|
- name: Extract metadata (tags, labels) for the image
|
|
|
|
uses: docker/metadata-action@v5.5.1
|
|
|
|
id: metadata
|
|
|
|
with:
|
|
|
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
2024-05-20 22:20:28 +02:00
|
|
|
# Release version tag if the workflow is triggered by a release
|
|
|
|
# Branch name tag if the workflow is triggered by a push
|
2024-05-28 14:24:36 +02:00
|
|
|
# Latest tag if the branch is release and the workflow is triggered by a push
|
2024-05-20 22:20:28 +02:00
|
|
|
tags: |
|
2024-05-20 22:35:36 +02:00
|
|
|
${{ github.event_name == 'release' && github.ref_name || env.BRANCH_NAME }}
|
2024-05-28 14:24:36 +02:00
|
|
|
${{ github.event_name == 'push' && env.BRANCH_NAME == 'release' && 'latest' || '' }}
|
2023-09-15 15:27:42 +02:00
|
|
|
|
|
|
|
# Login into package repository as the person who created the release
|
2024-04-05 17:39:06 +02:00
|
|
|
- name: Log in to the Container registry
|
|
|
|
uses: docker/login-action@v3
|
2023-09-15 15:27:42 +02:00
|
|
|
with:
|
2024-04-05 17:39:06 +02:00
|
|
|
registry: ${{ env.REGISTRY }}
|
2023-09-15 15:27:42 +02:00
|
|
|
username: ${{ github.actor }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
|
2024-04-05 17:39:06 +02:00
|
|
|
# Build docker image using dockerfile for amd64 and arm64
|
|
|
|
# Tag it with branch name
|
|
|
|
# Assumes branch name is the version number
|
|
|
|
- name: Build and push
|
|
|
|
uses: docker/build-push-action@v5.3.0
|
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
platforms: linux/amd64,linux/arm64
|
|
|
|
file: Dockerfile
|
|
|
|
push: true
|
|
|
|
tags: ${{ steps.metadata.outputs.tags }}
|
|
|
|
labels: ${{ steps.metadata.outputs.labels }}
|