Update branching.yml #16
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: Compare Versions | |
on: | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- edited | |
jobs: | |
compare-versions: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get tags from main branch | |
id: get_tags | |
run: | | |
version=$(curl -sL https://api.github.com/repos/${GITHUB_REPOSITORY}/tags | jq -r '.[0].name') | |
echo "version=$version" >> $GITHUB_OUTPUT | |
- name: Compare versions | |
id: compare_versions | |
run: | | |
version1="${{ steps.get_tags.outputs.version }}" | |
version2="v4.3.1" # Manually provided version | |
major_version1=$(echo "$version1" | cut -d'.' -f1 | sed 's/[^0-9]//g') | |
major_version2=$(echo "$version2" | cut -d'.' -f1 | sed 's/[^0-9]//g') | |
if [ "$major_version2" -gt "$major_version1" ]; then | |
echo "major_version_upgrade=true" >> $GITHUB_OUTPUT | |
git config user.name "$(gh api /users/${GITHUB_ACTOR} | jq .name -r)" | |
git config user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" | |
git switch -c $version2 | |
git push origin $version2 | |
fi | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
- name: Checkout prod branch | |
if: steps.compare_versions.outputs.major_version_upgrade == 'false' | |
uses: actions/checkout@v4 | |
with: | |
ref: $version2 |