Updater #243
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Updater | |
| on: | |
| schedule: | |
| - cron: '45 1 * * *' | |
| workflow_dispatch: | |
| env: | |
| REPO: "m3uplayer" | |
| 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 Frontend/Backend for updates" | |
| FRONTEND_COMMIT=$(curl -sfX GET "https://api.github.com/repos/4gray/iptvnator/commits" \ | |
| | jq -r '.[0].sha' | cut -c -8) | |
| BACKEND_COMMIT=$(curl -sfX GET "https://api.github.com/repos/4gray/iptvnator-backend/commits" \ | |
| | jq -r '.[0].sha' | cut -c -8) | |
| APP_VERSIONS="${FRONTEND_COMMIT}-${BACKEND_COMMIT}" | |
| if [ -z "${FRONTEND_COMMIT}" ] || [ "${FRONTEND_COMMIT}" = "null" ] || [ -z "${BACKEND_COMMIT}" ] || [ "${BACKEND_COMMIT}" = "null" ]; then | |
| echo "Unable to retrieve Frontend/Backend versions. Skipping." | |
| echo "Unable to retrieve Frontend/Backend versions. Skipping." >> $GITHUB_STEP_SUMMARY | |
| APP_VERSIONS=$(cat app_versions.txt) | |
| else | |
| echo "Frontend/Backend versions retrieved: ${APP_VERSIONS}" | |
| echo "Frontend/Backend versions retrieved: ${APP_VERSIONS}" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| APP_LAST_VERSIONS=$(cat app_versions.txt) | |
| if [ "${APP_VERSIONS}" != "${APP_LAST_VERSIONS}" ]; then | |
| echo "Last Frontend/Backend versions: ${APP_LAST_VERSIONS}" | |
| echo "Frontend/Backend seem to have been updated. Updating versions." | |
| echo "Last Frontend/Backend versions: ${APP_LAST_VERSIONS}" >> $GITHUB_STEP_SUMMARY | |
| echo "Frontend/Backend 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 Frontend/Backend versions' || : | |
| git push || : | |
| else | |
| echo "Frontend/Backend 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/dev\"}" \ | |
| https://api.github.com/repos/aptalca/${REPO}/actions/workflows/BuildImage.yml/dispatches | |
| else | |
| echo "No changes to either baseimage or Frontend/Backend versions." | |
| echo "No changes to either baseimage or Frontend/Backend versions." >> $GITHUB_STEP_SUMMARY | |
| fi |