Skip to content

Check Scarb Version #136

Check Scarb Version

Check Scarb Version #136

name: Check Scarb Version
on:
schedule:
- cron: '0 0 * * *' # Runs at midnight every day
workflow_dispatch: # Allows for manual triggering
permissions:
contents: write
pull-requests: write
jobs:
check-scarb-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get the latest version of Scarb
id: get_latest_version
run: |
SCARB_VERSION=$(curl -s https://api.github.com/repos/software-mansion/scarb/releases/latest | jq -r '.tag_name')
echo "SCARB_VERSION=${SCARB_VERSION}" >> $GITHUB_ENV
- name: Load previous Scarb version
id: load_previous_version
run: |
if [ -f .scarb-version ]; then
PREVIOUS_VERSION=$(cat .scarb-version)
else
PREVIOUS_VERSION="none"
fi
echo "PREVIOUS_VERSION=${PREVIOUS_VERSION}" >> $GITHUB_ENV
- name: Compare versions
id: compare_versions
run: |
if [ "$SCARB_VERSION" != "$PREVIOUS_VERSION" ]; then
echo "New version found: $SCARB_VERSION"
echo "update_required=true" >> $GITHUB_ENV
else
echo "No update required"
echo "update_required=false" >> $GITHUB_ENV
fi
- name: Check if PR already exists
id: check_pr_exists
if: env.update_required == 'true'
run: |
PR_EXIST=$(gh pr list --state=open --head update-scarb-${{ env.SCARB_VERSION }} | wc -l)
if [ "$PR_EXIST" -gt 0 ]; then
echo "PR already exists."
echo "pr_exists=true" >> $GITHUB_ENV
else
echo "No PR exists."
echo "pr_exists=false" >> $GITHUB_ENV
fi
- name: Check if branch already exists
id: check_branch_exists
if: env.update_required == 'true'
run: |
BRANCH_EXIST=$(git ls-remote --heads origin update-scarb-${{ env.SCARB_VERSION }} | wc -l)
if [ "$BRANCH_EXIST" -gt 0 ]; then
echo "Branch already exists."
echo "branch_exists=true" >> $GITHUB_ENV
else
echo "Branch does not exist."
echo "branch_exists=false" >> $GITHUB_ENV
fi
- name: Create a new branch for the update
if: env.update_required == 'true' && env.pr_exists == 'false' && env.branch_exists == 'false'
run: |
git checkout -b update-scarb-${{ env.SCARB_VERSION }}
echo "${{ env.SCARB_VERSION }}" > .scarb-version
- name: Commit changes
if: env.update_required == 'true' && env.pr_exists == 'false' && env.branch_exists == 'false'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add .scarb-version
git commit -m "Update Scarb version to ${{ env.SCARB_VERSION }}"
- name: Push changes to new branch
if: env.update_required == 'true' && env.pr_exists == 'false' && env.branch_exists == 'false'
run: |
git push origin update-scarb-${{ env.SCARB_VERSION }}
- name: Create Pull Request
if: env.update_required == 'true' && env.pr_exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh pr create \
--head update-scarb-${{ env.SCARB_VERSION }} \
--base develop \
--title "Update Scarb to version ${{ env.SCARB_VERSION }}" \
--body "A new version of Scarb has been released: **${{ env.SCARB_VERSION }}**.\nThis PR updates the project with the latest version." \
--label "scarb,update"