Deploy Images to GHCR when a new version is detected #6476
This file contains 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: Deploy Images to GHCR when a new version is detected | |
on: | |
schedule: | |
- cron: "0 * * * *" | |
workflow_dispatch: | |
jobs: | |
check-version: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Compare versions | |
id: compare_versions | |
run: | | |
PREVIOUS_VERSION_JSON=`cat version.json` | |
CURRENT_VERSION_JSON=`curl -s https://plexamp.plex.tv/headless/version.json` | |
if [ "$PREVIOUS_VERSION_JSON" != "$CURRENT_VERSION_JSON" ]; then | |
echo "::set-output name=trigger_workflow::true" | |
else | |
echo "::set-output name=trigger_workflow::false" | |
fi | |
- name: "Login to GitHub Container Registry" | |
if: steps.compare_versions.outputs.trigger_workflow == 'true' | |
uses: docker/login-action@v1 | |
with: | |
registry: ghcr.io | |
username: ${{github.actor}} | |
password: ${{secrets.GITHUB_TOKEN}} | |
- name: Building images if the remote version has changed | |
if: steps.compare_versions.outputs.trigger_workflow == 'true' | |
run: | | |
echo "Triggering Docker Build" | |
echo "Building ARM64v8 image" | |
CURRENT_VERSION_JSON=`curl -s https://plexamp.plex.tv/headless/version.json` | |
CURRENT_VERSION=`echo $CURRENT_VERSION_JSON | jq -r .latestVersion` | |
docker buildx create --use | |
docker buildx build --platform linux/arm64 -t ghcr.io/${{github.actor}}/plexamp:arm64v8 --load . | |
docker push ghcr.io/${{github.actor}}/plexamp:arm64v8 | |
docker buildx build --platform linux/arm64 -t ghcr.io/${{github.actor}}/plexamp:arm64v8-${CURRENT_VERSION} --load . | |
docker push ghcr.io/${{github.actor}}/plexamp:arm64v8-${CURRENT_VERSION} | |
echo "Building ARM32v7 image" | |
docker buildx build --platform linux/arm/v7 -t ghcr.io/${{github.actor}}/plexamp:arm32v7 --load . | |
docker push ghcr.io/${{github.actor}}/plexamp:arm32v7 | |
docker buildx build --platform linux/arm/v7 -t ghcr.io/${{github.actor}}/plexamp:arm32v7-${CURRENT_VERSION} --load . | |
docker push ghcr.io/${{github.actor}}/plexamp:arm32v7-${CURRENT_VERSION} | |
echo "Building AMD64 image" | |
docker buildx build --platform linux/amd64 -t ghcr.io/${{github.actor}}/plexamp:amd64 --load . | |
docker push ghcr.io/${{github.actor}}/plexamp:amd64 | |
docker buildx build --platform linux/amd64 -t ghcr.io/${{github.actor}}/plexamp:amd64-${CURRENT_VERSION} --load . | |
docker push ghcr.io/${{github.actor}}/plexamp:amd64-${CURRENT_VERSION} | |
- name: Update local version if the remote version has changed | |
if: steps.compare_versions.outputs.trigger_workflow == 'true' | |
run: | | |
echo "Versions are different. Updating version.json..." | |
CURRENT_VERSION_JSON=`curl -s https://plexamp.plex.tv/headless/version.json` | |
CURRENT_VERSION=`echo $CURRENT_VERSION_JSON | jq -r .latestVersion` | |
echo $CURRENT_VERSION_JSON > version.json | |
git config --global user.name "Version updater" | |
git config --global user.email "[email protected]" | |
git commit -am "upd: version bump to ${CURRENT_VERSION}" | |
git push |