Skip to content

📦 [younsl/backup-utils] Release backup-utils image (amd64) #6

📦 [younsl/backup-utils] Release backup-utils image (amd64)

📦 [younsl/backup-utils] Release backup-utils image (amd64) #6

name: Release backup-utils image
run-name: 📦 [younsl/backup-utils] Release backup-utils image (amd64)
on:
workflow_dispatch:
inputs:
BACKUP_UTILS_VERSION:
description: 'Version of github-backup-utils to use'
required: true
default: 3.14.0
env:
IMAGE_NAME: younsl/backup-utils
BACKUP_UTILS_VERSION: ${{ github.event.inputs.BACKUP_UTILS_VERSION }}
permissions:
contents: read
packages: write
jobs:
check:
runs-on: ubuntu-latest
outputs:
image_exists: ${{ steps.image_check.outputs.image_exists }}
steps:
- name: Check if image exists on GitHub Container Registry
id: image_check
run: |
ENCODED_TOKEN=$(echo -n "${{ secrets.GITHUB_TOKEN }}" | base64)
TAGS=$(curl -s -H "Authorization: Bearer ${ENCODED_TOKEN}" \
https://ghcr.io/v2/${{ env.IMAGE_NAME }}/tags/list)
echo "TAGS: $TAGS"
## Check if TAGS is empty or null
if [[ -z "$TAGS" || "$TAGS" == "null" ]]; then
echo "No tags found, treating as image not existing."
echo "image_exists=false" >> $GITHUB_OUTPUT
else
## Check if the specific tag already exists
if echo "$TAGS" | jq -e --arg TAG "${{ env.BACKUP_UTILS_VERSION }}" '.tags | index($TAG)'; then
echo "Image with tag ${{ env.BACKUP_UTILS_VERSION }} already exists."
echo "image_exists=true" >> $GITHUB_OUTPUT
else
echo "Image with tag ${{ env.BACKUP_UTILS_VERSION }} not found."
echo "image_exists=false" >> $GITHUB_OUTPUT
fi
fi
release:
runs-on: ubuntu-latest
needs: check
if: ${{ needs.check.outputs.image_exists == 'false' }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Download and extract github-backup-utils
id: prepare
run: |
echo "Downloading github-backup-utils version ${{ env.BACKUP_UTILS_VERSION }} ..."
curl -L -o github-backup-utils-${{ env.BACKUP_UTILS_VERSION }}.tar.gz \
https://github.com/github/backup-utils/releases/download/v${{ env.BACKUP_UTILS_VERSION }}/github-backup-utils-v${{ env.BACKUP_UTILS_VERSION }}.tar.gz
echo "Extracting github-backup-utils tarball ..."
tar -xzf github-backup-utils-${{ env.BACKUP_UTILS_VERSION }}.tar.gz
- name: Login to GitHub Container Registry (ghcr.io)
id: login
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build
id: build
run: |
docker build \
--platform linux/amd64 \
-t ghcr.io/${{ env.IMAGE_NAME }}:${{ env.BACKUP_UTILS_VERSION }} github-backup-utils-v${{ env.BACKUP_UTILS_VERSION }}
- name: Push
id: push
run: |
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ env.BACKUP_UTILS_VERSION }}