Skip to content

Check for new Mattermost Releases #109

Check for new Mattermost Releases

Check for new Mattermost Releases #109

name: Check for new Mattermost Releases
on:
schedule:
- cron: '0 0 * * *' # Vérifie toutes les jours à minuit
jobs:
check-releases:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get latest release from the monitored repo
id: get_release
run: |
latest_release=$(curl -s https://api.github.com/repos/mattermost/mattermost/releases/latest | jq -r .tag_name)
echo "LATEST_RELEASE=$latest_release" >> $GITHUB_ENV
- name: Compare with last known release
id: compare_release
run: |
set -o allexport
source mattermost-release.txt
set +o allexport
echo "Last known release: $MATTERMOST_VERSION"
echo "Latest release: ${{ env.LATEST_RELEASE }}"
if [ "${{ env.LATEST_RELEASE }}" != "$MATTERMOST_VERSION" ]; then
if [[ "${{ env.LATEST_RELEASE }}" =~ v([0-9]+)\.([0-9]+)\.([0-9]+) ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
echo "New release detected"
# If branch exists, do nothing
if git ls-remote --heads origin | grep -q "upgrade-$major.$minor"; then
echo "Branch upgrade-$major.$minor already exists"
echo "NEW_RELEASE=false" >> $GITHUB_ENV
exit 0
fi
# Branch DNE, update MATTERMOST_VERSION
sed -i "s/MATTERMOST_VERSION=\(.*\)/MATTERMOST_VERSION=${{ env.LATEST_RELEASE }}/" mattermost-release.txt
echo "BRANCH_NAME=upgrade-$major.$minor" >> $GITHUB_ENV
echo "NEW_RELEASE=true" >> $GITHUB_ENV
fi
else
echo "No new release"
echo "NEW_RELEASE=false" >> $GITHUB_ENV
fi
- name: Create or update mattermost-release.txt
id: set_branch_for_upgrade
if: env.NEW_RELEASE == 'true'
run: |
git config --global user.name 'github-actions'
git config --global user.email '[email protected]'
git checkout -b ${{ env.BRANCH_NAME }} || git checkout ${{ env.BRANCH_NAME }}
git add mattermost-release.txt
git commit -m "chore: Upgrade to ${{ env.LATEST_RELEASE }}"
git push origin ${{ env.BRANCH_NAME }}
- name: Create pull request via GitHub CLI
if: env.NEW_RELEASE == 'true'
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
gh label list | grep -q auto-upgrade || gh label create auto-upgrade \
-c FABC7B \
-d "Pull requests that upgrade mattermost version automatically"
gh pr create \
--assignee @me \
--base main \
--body "" \
--head ${{ env.BRANCH_NAME }} \
--label auto-upgrade \
--reviewer remiheens \
--title "Update files for new mattermost release ${{ env.LATEST_RELEASE }}"