Check for new CumulusMX release #816
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: Check for new CumulusMX release | |
# This script runs on a schedule to check for new releases from the upstream repo. If it finds a new release writes the latest release number to a file. | |
# Credit to peterevans on stackoverflow for the script: https://stackoverflow.com/a/58468828 | |
on: | |
schedule: | |
- cron: '21 19 * * *' | |
workflow_dispatch: | |
jobs: | |
get-version: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.PAT }} | |
- name: Get current version number | |
run: | | |
CURRENT_VERSION=$(cat upstream-releases/cumulusmx-latest.txt) | |
echo "CURRENT_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV | |
- name: Get latest version number | |
run: | | |
RELEASE_DATA=$(curl -sL "https://api.github.com/repos/cumulusmx/CumulusMX/releases/latest" 2>/dev/null) | |
NEW_VERSION=$(echo "$RELEASE_DATA" | jq -r '.tag_name') | |
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
- name: Compare version numbers | |
run: | | |
if [ -n "${{ env.CURRENT_VERSION }}" ]; then | |
if [ "${{ env.CURRENT_VERSION }}" = "${{ env.NEW_VERSION }}" ]; then | |
echo "Releases match. No change detected." | |
echo "MODIFIED=false" >> $GITHUB_ENV | |
else | |
echo "Releases differ. There has been a new release." | |
echo "${{ env.NEW_VERSION }}" > upstream-releases/cumulusmx-latest.txt | |
# Trigger the build-and-push workflow | |
curl -X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token ${{ secrets.PAT }}" \ | |
https://api.github.com/repos/hucknz/cumulusmx/actions/workflows/v4-container-build-push.yml/dispatches \ | |
-d '{"ref":"main"}' | |
echo "MODIFIED=true" >> $GITHUB_ENV | |
fi | |
fi | |
- name: Commit latest hash | |
if: env.MODIFIED == 'true' | |
run: | | |
git config --global user.name 'hucknz' | |
git config --global user.email '[email protected]' | |
git commit -am "New release version found" | |
git push | |
- name: Notify new image found to Slack | |
id: notify_new_release | |
if: env.MODIFIED == 'true' | |
uses: sarisia/actions-status-discord@v1 | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
noprefix: true | |
status: ${{ job.status }} | |
title: ${{ github.workflow}} ${{ job.status }} | |
description: "A new CumulusMX version was found. The build and push workflow has been triggered." | |
- name: Notify failure to Slack | |
id: notify_failure | |
if: failure() | |
uses: sarisia/actions-status-discord@v1 | |
with: | |
webhook: ${{ secrets.DISCORD_WEBHOOK }} | |
noprefix: true | |
status: ${{ job.status }} | |
title: "CumulusMX release check ${{ job.status }}" |