Skip to content

Commit 664de97

Browse files
committed
Add dependency bump workflow
1 parent 38af1a0 commit 664de97

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

.github/workflows/bump.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: 'Bump Dependencies'
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *'
6+
workflow_dispatch:
7+
8+
jobs:
9+
update-deps:
10+
if: github.ref == 'refs/heads/main'
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: 🗂 Checkout Code
15+
uses: actions/checkout@v4
16+
17+
- name: 🧩 Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '24.x'
21+
22+
- name: 📦 Install PNPM
23+
run: npm i pnpm -g
24+
25+
- name: 🗃 Setup Cache Environment
26+
id: extcache
27+
uses: shivammathur/cache-extensions@v1
28+
with:
29+
php-version: 8.3
30+
extensions: bcmath
31+
key: php_extensions_cache
32+
33+
- name: 🗃 Cache Extensions
34+
uses: actions/cache@v4
35+
with:
36+
path: ${{ steps.extcache.outputs.dir }}
37+
key: ${{ steps.extcache.outputs.key }}
38+
restore-keys: ${{ steps.extcache.outputs.key }}
39+
40+
- name: 🐘 Install PHP
41+
uses: shivammathur/setup-php@v2
42+
with:
43+
php-version: '8.3'
44+
extensions: bcmath
45+
46+
- name: 🗄 Get Composer Cache Directory
47+
id: composer-cache
48+
run: |
49+
echo "::set-output name=dir::$(composer config cache-files-dir)"
50+
51+
- name: 🗃 Cache Composer Dependencies
52+
uses: actions/cache@v4
53+
id: actions-cache
54+
with:
55+
path: ${{ steps.composer-cache.outputs.dir }}
56+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
57+
restore-keys: |
58+
${{ runner.os }}-composer-
59+
60+
- name: 🗂 Cache PHP Dependencies
61+
uses: actions/cache@v4
62+
id: vendor-cache
63+
with:
64+
path: vendor
65+
key: ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }}
66+
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+
87+
- name: 🚀 Bump and Install Dependencies
88+
run: |
89+
chmod +x ./.scripts/local/bump.sh
90+
./.scripts/local/bump.sh
91+
shell: bash
92+
93+
- name: 🏗 Build Frontend with Vite
94+
run: pnpm build
95+
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+
101+
- name: 👤 Set up Git user
102+
if: steps.check_changes.outputs.changes == 'true'
103+
run: |
104+
git config --global user.name "${{ github.actor }}-ci-automation"
105+
git config --global user.email "${{ env.GITHUB_GIT_EMAIL }}"
106+
107+
- name: 🛠️ Add changes to commit
108+
if: steps.check_changes.outputs.changes == 'true'
109+
id: update-branch
110+
run: |
111+
DATE=$(date +'%Y-%m-%d')
112+
BRANCH_NAME="update/update-deps-$DATE"
113+
114+
# Add changes to commit
115+
git add composer.lock package.json pnpm-lock.yaml
116+
git commit -m "Chore: update dependencies on $DATE" || echo "No changes to commit"
117+
118+
# Push changes to remote, force with lease for safety
119+
git push --set-upstream origin $BRANCH_NAME || exit 1
120+
121+
- name: 🔀 Create Pull Request
122+
if: steps.check_changes.outputs.changes == 'true'
123+
run: gh pr create -B main --title "Update dependencies" --body "Created by Github action"
124+
env:
125+
GITHUB_TOKEN: ${{ secrets.ACTION_WORKFLOW_GITHUB_TOKEN }}

0 commit comments

Comments
 (0)