85 lines
2.8 KiB
YAML
85 lines
2.8 KiB
YAML
name: Build ElegooSlicer Container
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches:
|
|
- main
|
|
schedule:
|
|
- cron: '0 4 * * *'
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
|
|
jobs:
|
|
check-and-build:
|
|
runs-on: docker-runner
|
|
steps:
|
|
- name: Checkout Repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Determine Registry & Image Path
|
|
id: meta
|
|
run: |
|
|
if [ "${{ github.server_url }}" = "https://github.com" ]; then
|
|
REGISTRY="ghcr.io"
|
|
else
|
|
REGISTRY=$(echo "${{ github.server_url }}" | sed -e 's|^[^/]*/\+/||')
|
|
fi
|
|
|
|
IMAGE_NAME=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
FULL_IMAGE_NAME="$REGISTRY/$IMAGE_NAME"
|
|
|
|
echo "registry=$REGISTRY" >> "$GITHUB_OUTPUT"
|
|
echo "full_image_name=$FULL_IMAGE_NAME" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Login to Container Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ${{ env.REGISTRY }}
|
|
username: ${{ secrets.REGISTRY_USER }}
|
|
password: ${{ secrets.REGISTRY_PASSWORD }}
|
|
|
|
- name: Check Elegoo Upstream Release & Local Image Tag
|
|
id: check_tag
|
|
run: |
|
|
RELEASE_JSON=$(curl -s https://api.github.com/repos/ELEGOO-3D/ElegooSlicer/releases/latest)
|
|
DOWNLOAD_URL=$(echo "$RELEASE_JSON" | grep -o 'https://[^"]*Linux[^"]*\.AppImage' | head -n 1)
|
|
TAG_NAME=$(echo "$RELEASE_JSON" | grep -o '"tag_name": "[^"]*' | cut -d'"' -f4)
|
|
|
|
if [ -z "$DOWNLOAD_URL" ] || [ -z "$TAG_NAME" ]; then
|
|
echo "Error: Could not parse release data"
|
|
exit 1
|
|
fi
|
|
|
|
echo "Newest Elegoo-Tag: $TAG_NAME"
|
|
TARGET_IMAGE="${{ steps.meta.outputs.full_image_name }}:$TAG_NAME"
|
|
|
|
if docker manifest inspect "$TARGET_IMAGE" > /dev/null 2>&1; then
|
|
echo "Image $TARGET_IMAGE exists in registry"
|
|
echo "build_needed=false" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "Image $TARGET_IMAGE does not exist in registry, lets build it"
|
|
echo "build_needed=true" >> "$GITHUB_OUTPUT"
|
|
echo "url=$DOWNLOAD_URL" >> "$GITHUB_OUTPUT"
|
|
echo "tag=$TAG_NAME" >> "$GITHUB_OUTPUT"
|
|
fi
|
|
|
|
- name: Set up Docker Buildx
|
|
if: steps.check_tag.outputs.build_needed == 'true' || github.event_name == 'workflow_dispatch'
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build and Push
|
|
if: steps.check_tag.outputs.build_needed == 'true' || github.event_name == 'workflow_dispatch'
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: true
|
|
build-args: |
|
|
SLICER_URL=${{ steps.check_tag.outputs.url }}
|
|
tags: |
|
|
${{ steps.meta.outputs.full_image_name }}:latest
|
|
${{ steps.meta.outputs.full_image_name }}:${{ steps.check_tag.outputs.tag }}
|
|
|