Skip to content

Release

Release #21992

Workflow file for this run

name: Release
on:
schedule:
- cron: "0 * * * *"
workflow_dispatch:
inputs:
forceBuild:
description: "Force image build"
required: false
default: false
type: boolean
env:
KLIPPER_REPOSITORY: https://github.com/klipper3d/klipper
MOONRAKER_REPOSITORY: https://github.com/Arksine/moonraker
IS_DEFAULT_BRANCH: ${{ endsWith(github.ref, github.event.repository.default_branch) }}
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
outputs:
klipper_sha: ${{ steps.repo.outputs.klipper_sha }}
moonraker_sha: ${{ steps.repo.outputs.moonraker_sha }}
image_sha: ${{ steps.repo.outputs.image_sha }}
build_image: ${{ steps.check.outputs.build_image }}
steps:
- name: Get Klipper and Moonraker metadata
id: repo
run: |
KLIPPER_SHA=$(git ls-remote $KLIPPER_REPOSITORY master | awk '{print $1}')
MOONRAKER_SHA=$(git ls-remote $MOONRAKER_REPOSITORY master | awk '{print $1}')
IMAGE_SHA=$(echo $KLIPPER_SHA-$MOONRAKER_SHA | sha1sum | awk '{print $1}')
echo "klipper_sha=${KLIPPER_SHA}" >> $GITHUB_OUTPUT
echo "moonraker_sha=${MOONRAKER_SHA}" >> $GITHUB_OUTPUT
echo "image_sha=${IMAGE_SHA}" >> $GITHUB_OUTPUT
- name: Check if new Docker image should be built
id: check
run: |
BUILD_IMAGE=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.forceBuild == 'true' }}
if ! "$BUILD_IMAGE"; then
docker buildx imagetools inspect ghcr.io/${{ github.repository }}:sha-${{ steps.repo.outputs.image_sha }} > /dev/null || BUILD_IMAGE=true
fi
echo "build_image=${BUILD_IMAGE}" >> $GITHUB_OUTPUT
build:
name: Build and deploy
runs-on: ubuntu-latest
needs: setup
if: ${{ needs.setup.outputs.build_image == 'true' }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Prepare GitHub metadata
id: github_meta
run: |
REPOSITORY_NAME=${GITHUB_REPOSITORY#*/}
echo "repository_name=${REPOSITORY_NAME}" >> $GITHUB_OUTPUT
- name: Prepare Docker image metadata
id: docker_meta
uses: docker/metadata-action@v4
with:
images: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.github_meta.outputs.repository_name }}
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=klipper-sha-${{ needs.setup.outputs.klipper_sha }}
type=raw,value=moonraker-sha-${{ needs.setup.outputs.moonraker_sha }}
type=raw,value=sha-${{ needs.setup.outputs.image_sha }}
type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
build-args: |
KLIPPER_REPOSITORY: ${{ env.KLIPPER_REPOSITORY }}
KLIPPER_SHA=${{ needs.setup.outputs.klipper_sha }}
MOONRAKER_REPOSITORY: ${{ env.MOONRAKER_REPOSITORY }}
MOONRAKER_SHA=${{ needs.setup.outputs.moonraker_sha }}
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}