Sync New Releases #4
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: Sync New Releases | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
sync-new-releases: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Compare Releases | |
id: compare_releases | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const upstream = await github.rest.repos.getLatestRelease({ | |
owner: 'mattermost', | |
repo: 'mattermost' | |
}); | |
core.info(`Upstream release: ${upstream.data.tag_name}`); | |
const fork = await github.rest.repos.getLatestRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo | |
}); | |
core.info(`Fork release: ${fork.data.tag_name}`); | |
if (upstream.data.tag_name !== fork.data.tag_name) { | |
core.setOutput('new_tag', upstream.data.tag_name); | |
} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
if: steps.compare_releases.outputs.new_tag | |
with: | |
token: ${{ secrets.PAT }} | |
- name: Sync Branch & Tag | |
if: steps.compare_releases.outputs.new_tag | |
run: | | |
tag="${{ steps.compare_releases.outputs.new_tag }}" | |
version="${tag:1}" | |
major_minor="${version%.*}" | |
releaseBranch="release-$major_minor" | |
git remote add mattermost https://github.com/mattermost/mattermost.git | |
git fetch mattermost ${releaseBranch} | |
git fetch mattermost tag ${tag} | |
git checkout -b ${releaseBranch} --track mattermost/${releaseBranch} | |
git reset --hard ${tag} | |
git tag ${tag} --force | |
git push origin ${releaseBranch} --force | |
git push origin ${tag} --force |