Skip to content

Publish standalone Docker image #53

Publish standalone Docker image

Publish standalone Docker image #53

name: Publish standalone Docker image
on:
workflow_run:
workflows: ["Publish to npm"]
types: [completed]
branches: [master]
jobs:
check:
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
permissions:
packages: read
outputs:
should_publish: ${{ steps.check.outputs.should_publish }}
version: ${{ steps.check.outputs.version }}
is_prerelease: ${{ steps.check.outputs.is_prerelease }}
steps:
- uses: actions/checkout@v5
- name: Check if image already published
id: check
run: |
VERSION=$(node -p "require('./package.json').version")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
if [[ "$VERSION" == *-* ]]; then
echo "is_prerelease=true" >> "$GITHUB_OUTPUT"
else
echo "is_prerelease=false" >> "$GITHUB_OUTPUT"
fi
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
if docker manifest inspect "ghcr.io/${{ github.repository }}/standalone:$VERSION" > /dev/null 2>&1; then
echo "should_publish=false" >> "$GITHUB_OUTPUT"
echo "Image $VERSION already exists, skipping."
else
echo "should_publish=true" >> "$GITHUB_OUTPUT"
echo "New version detected: $VERSION"
fi
publish:
needs: check
if: needs.check.outputs.should_publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v5
- name: Log in to GitHub Container Registry
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@v6
with:
context: .
file: docker-standalone/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}/standalone:${{ needs.check.outputs.version }}
${{ needs.check.outputs.is_prerelease == 'false' && format('ghcr.io/{0}/standalone:latest', github.repository) || '' }}