Skip to content

Get latest release version #695

Get latest release version

Get latest release version #695

# Found at https://stackoverflow.com/questions/58465057/trigger-a-github-actions-when-another-repository-creates-a-release
# and modified for our purposes. Simple premise: fetch release and prerelease information from github api url's, parse
# into variables and check against committed files to verify the current build version numbers. If any changes, commit
# new version files which will then fire off the docker build workflow. The magic which allows this to happen is in the
# REPO_SCOPED_TOKEN which literally is a github token with full 'repo' scope privileges.
name: Get latest release version
on:
schedule:
# Set time to run to 18:00, which is I think UTC time? About 5 hours ahead of my time. Should be around 1 pm.
- cron: '0 18 * * *'
workflow_dispatch:
jobs:
get-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
- name: Fetch release version
id: release_version
run: |
curl -sL https://api.github.com/repos/element-hq/synapse/releases/latest | \
echo "release_version=$( jq -r '.tag_name')" >> $GITHUB_OUTPUT
- name: Fetch pre-release version
id: prerelease_version
run: |
curl -sL https://api.github.com/repos/element-hq/synapse/releases | \
echo "prerelease_version=$(jq -r 'map(select(.tag_name)) | first | .tag_name')" >> $GITHUB_OUTPUT
- name: Check recorded versions
id: version_check
shell: bash
run: |
if [ "${{ steps.release_version.outputs.release_version }}" != "$(cat release-versions/synapse-latest.txt)" ]; then
echo "Updating synapse-latest.txt"
echo "${{ steps.release_version.outputs.release_version }}" > release-versions/synapse-latest.txt
fi
if [ "${{ steps.prerelease_version.outputs.prerelease_version }}" != "$(cat release-versions/synapse-prerelease.txt)" ]; then
echo "Updating synapse-prerelease.txt"
echo "${{ steps.prerelease_version.outputs.prerelease_version }}" > release-versions/synapse-prerelease.txt
fi
- name: Check for modified files
id: git-check
run: |
echo "modified=$([ -z `git status --porcelain` ] && echo 'false' || echo 'true')" >> $GITHUB_OUTPUT
- name: Commit latest versions
if: ${{ steps.git-check.outputs.modified == 'true' }}
run: |
git config --global user.name 'Jason Little'
git config --global user.email '[email protected]'
git commit -am "Update Synapse versions(automated)"
git push