Skip to content

Updater

Updater #5

Workflow file for this run

name: Updater
on:
schedule:
- cron: '30 1 * * *'
workflow_dispatch:
env:
REPO: "autorestic"
jobs:
base-updater:
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/[email protected]
- name: Check for updates and trigger
run: |
git config --local user.email "[email protected]"
git config --local user.name "AptalcaBot"
DISTRO=$(cat Dockerfile | grep 'FROM' | sed 's|.*baseimage-\(.*\):.*|\1|')
TAG=$(cat Dockerfile | grep 'FROM' | sed 's|.*:\(.*\)|\1|')
token=$(curl -sX GET \
"https://ghcr.io/token?scope=repository%3Alinuxserver%2Fbaseimage-${DISTRO}%3Apull" \
| jq -r '.token')
multidigest=$(curl -s \
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Accept: application/vnd.oci.image.index.v1+json" \
--header "Authorization: Bearer ${token}" \
"https://ghcr.io/v2/linuxserver/baseimage-${DISTRO}/manifests/${TAG}")
multidigest=$(jq -r ".manifests[] | select(.platform.architecture == \"amd64\").digest?" <<< "${multidigest}")
EXTDIGEST=$(curl -s \
--header "Accept: application/vnd.docker.distribution.manifest.v2+json" \
--header "Accept: application/vnd.oci.image.manifest.v1+json" \
--header "Authorization: Bearer ${token}" \
"https://ghcr.io/v2/linuxserver/baseimage-${DISTRO}/manifests/${multidigest}" \
| jq -r '.config.digest')
if [ -z "${EXTDIGEST}" ]; then
echo "Unable to retrieve external digest. Skipping."
echo "Unable to retrieve external digest. Skipping." >> $GITHUB_STEP_SUMMARY
EXTDIGEST=$(cat baseimage-digest.txt)
else
echo "External digest retrieved: ${EXTDIGEST}"
echo "External digest retrieved: ${EXTDIGEST}" >> $GITHUB_STEP_SUMMARY
fi
LASTDIGEST=$(cat baseimage-digest.txt)
if [ "${LASTDIGEST}" != "${EXTDIGEST}" ]; then
echo "Last used baseimage digest: ${LASTDIGEST}"
echo "Baseimage seems to have been updated. Updating baseimage digest."
echo "Last used baseimage digest: ${LASTDIGEST}" >> $GITHUB_STEP_SUMMARY
echo "Baseimage seems to have been updated. Updating baseimage digest." >> $GITHUB_STEP_SUMMARY
echo -n "${EXTDIGEST}" > baseimage-digest.txt
BUILD_IMAGE="yes"
git add . || :
git commit -m '[bot] Updating baseimage digest' || :
git push || :
else
echo "Baseimage seems to be the same. Skipping."
fi
echo "Checking Restic/Autorestic for updates"
RESTIC_RELEASE=$(curl -sX GET "https://api.github.com/repos/restic/restic/releases/latest" \
| jq -r '.tag_name' | sed 's|^v||')
AUTORESTIC_RELEASE=$(curl -sX GET "https://api.github.com/repos/cupcakearmy/autorestic/releases/latest" \
| jq -r '.tag_name' | sed 's|^v||')
APP_VERSIONS="${RESTIC_RELEASE}-${AUTORESTIC_RELEASE}"
if [ -z "${APP_VERSIONS}" ] || [ "${APP_VERSIONS}" = "null" ]; then
echo "Unable to retrieve Restic/Autorestic versions. Skipping."
echo "Unable to retrieve Restic/Autorestic versions. Skipping." >> $GITHUB_STEP_SUMMARY
APP_VERSIONS=$(cat app_versions.txt)
else
echo "Restic/Autorestic versions retrieved: ${APP_VERSIONS}"
echo "Restic/Autorestic versions retrieved: ${APP_VERSIONS}" >> $GITHUB_STEP_SUMMARY
fi
APP_LAST_VERSIONS=$(cat app_versions.txt)
if [ "${APP_VERSIONS}" != "${APP_LAST_VERSIONS}" ]; then
echo "Last Restic/Autorestic versions: ${APP_LAST_VERSIONS}"
echo "Restic/Autorestic seem to have been updated. Updating versions."
echo "Last Restic/Autorestic versions: ${APP_LAST_VERSIONS}" >> $GITHUB_STEP_SUMMARY
echo "Restic/Autorestic seem to have been updated. Updating versions." >> $GITHUB_STEP_SUMMARY
echo -n "${APP_VERSIONS}" > app_versions.txt
BUILD_IMAGE="yes"
git add . || :
git commit -m '[bot] Updating Restic/Autorestic versions' || :
git push || :
else
echo "Restic/Autorestic versions seem to be the same. Skipping."
fi
if [ "${BUILD_IMAGE}" = "yes" ]; then
echo "Triggering new build!!"
echo "Triggering new build!!" >> $GITHUB_STEP_SUMMARY
curl -iX POST \
-H "Authorization: token ${{ secrets.CR_PAT }}" \
-H "Accept: application/vnd.github.v3+json" \
-d "{\"ref\":\"refs/heads/main\"}" \
https://api.github.com/repos/aptalca/${REPO}/actions/workflows/BuildImage.yml/dispatches
else
echo "No changes to either baseimage or Restic/Autorestic versions."
echo "No changes to either baseimage or Restic/Autorestic versions." >> $GITHUB_STEP_SUMMARY
fi