6464 path : vendor
6565 key : ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }}
6666
67+ - name : 🛠️ Create branch
68+ id : create_branch
69+ run : |
70+ DATE=$(date +'%Y-%m-%d')
71+ BRANCH_NAME="update/update-deps-$DATE"
72+
73+ # Check if branch exists and create or switch to it
74+ if git ls-remote --exit-code --heads origin $BRANCH_NAME; then
75+ echo "Branch $BRANCH_NAME already exists on remote."
76+ git fetch origin $BRANCH_NAME
77+ git checkout $BRANCH_NAME
78+ git reset --hard origin/$BRANCH_NAME
79+ else
80+ echo "Creating branch $BRANCH_NAME."
81+ git checkout -b $BRANCH_NAME
82+ fi
83+
84+ # Output the branch name for use in the next steps
85+ echo "new_branch=$BRANCH_NAME" >> $GITHUB_ENV
86+
6787 - name : 🚀 Bump and Install Dependencies
6888 run : |
6989 chmod +x ./.scripts/local/bump.sh
@@ -73,29 +93,32 @@ jobs:
7393 - name : 🏗 Build Frontend with Vite
7494 run : pnpm build
7595
96+ - name : 🧪 Check Changes
97+ id : check_changes
98+ run : |
99+ git diff --exit-code && echo "changes=false" >> $GITHUB_OUTPUT || echo "changes=true" >> $GITHUB_OUTPUT
100+
76101 - name : 👤 Set up Git user
102+ if : steps.check_changes.outputs.changes == 'true'
77103 run : |
78104 git config --global user.name "${{ github.actor }}-ci-automation"
79105 git config --global user.email "${{ env.GITHUB_GIT_EMAIL }}"
80106
81- - name : 🌿 Create a new branch
107+ - name : 🛠️ Add changes to commit
108+ if : steps.check_changes.outputs.changes == 'true'
109+ id : update-branch
82110 run : |
83- NEW_BRANCH="update/bump-dependency-versions-$(date +'%d-%m-%Y')"
84- git checkout -b "$NEW_BRANCH"
85- echo "::set-output name=new_branch::$NEW_BRANCH"
111+ DATE=$(date +'%Y-%m-%d')
86112
87- - name : 🔍 Check for changes and commit
88- run : |
89- git diff --quiet || git commit -am "Update dependencies "
113+ # Add changes to commit
114+ git add composer.lock package.json pnpm-lock.yaml
115+ git commit -m "chore: update dependencies on $DATE" || echo "No changes to commit "
90116
91- - name : 🚀 Push changes
92- if : success()
93- run : git push origin ${{ steps.create_branch.outputs.new_branch }}
117+ # Push changes to remote, force with lease for safety
118+ git push --force-with-lease origin $BRANCH_NAME || exit 1
94119
95120 - name : 🔀 Create Pull Request
96- uses : repo-sync/pull-request@v2
97- with :
98- source_branch : ${{ steps.create-branch.outputs.NEW_BRANCH }}
99- destination_branch : main
100- pr_title : ' Bump dependencies'
101- pr_body : ' This PR updates the project dependencies.'
121+ if : steps.check_changes.outputs.changes == 'true'
122+ run : gh pr create -B main --title "Update dependencies" --body "Created by Github action"
123+ env :
124+ GITHUB_TOKEN : ${{ secrets.ACTION_WORKFLOW_GITHUB_TOKEN }}
0 commit comments