-
Notifications
You must be signed in to change notification settings - Fork 3
125 lines (103 loc) · 4.52 KB
/
bump.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: 'Bump Dependencies'
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
update-deps:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: 🗂 Checkout Code
uses: actions/checkout@v4
- name: 🧩 Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
- name: 📦 Install PNPM
run: npm i pnpm -g
- name: 🗃 Setup Cache Environment
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: 8.2
extensions: bcmath
key: php_extensions_cache
- name: 🗃 Cache Extensions
uses: actions/cache@v4
with:
path: ${{ steps.extcache.outputs.dir }}
key: ${{ steps.extcache.outputs.key }}
restore-keys: ${{ steps.extcache.outputs.key }}
- name: 🐘 Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
extensions: bcmath
- name: 🗄 Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: 🗃 Cache Composer Dependencies
uses: actions/cache@v4
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: 🗂 Cache PHP Dependencies
uses: actions/cache@v4
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }}
- name: 🛠️ Create branch
id: create_branch
run: |
DATE=$(date +'%Y-%m-%d')
BRANCH_NAME="update/update-deps-$DATE"
# Check if branch exists and create or switch to it
if git ls-remote --exit-code --heads origin $BRANCH_NAME; then
echo "Branch $BRANCH_NAME already exists on remote."
git fetch origin $BRANCH_NAME
git checkout $BRANCH_NAME
git reset --hard origin/$BRANCH_NAME
else
echo "Creating branch $BRANCH_NAME."
git checkout -b $BRANCH_NAME
fi
# Output the branch name for use in the next steps
echo "new_branch=$BRANCH_NAME" >> $GITHUB_ENV
- name: 🚀 Bump and Install Dependencies
run: |
chmod +x ./.scripts/local/bump.sh
./.scripts/local/bump.sh
shell: bash
- name: 🏗 Build Frontend with Vite
run: pnpm build
- name: 🧪 Check Changes
id: check_changes
run: |
git diff --exit-code && echo "changes=false" >> $GITHUB_OUTPUT || echo "changes=true" >> $GITHUB_OUTPUT
- name: 👤 Set up Git user
if: steps.check_changes.outputs.changes == 'true'
run: |
git config --global user.name "${{ github.actor }}-ci-automation"
git config --global user.email "${{ env.GITHUB_GIT_EMAIL }}"
- name: 🛠️ Add changes to commit
if: steps.check_changes.outputs.changes == 'true'
id: update-branch
run: |
DATE=$(date +'%Y-%m-%d')
BRANCH_NAME="update/update-deps-$DATE"
# Add changes to commit
git add composer.lock package.json pnpm-lock.yaml
git commit -m "Chore: update dependencies on $DATE" || echo "No changes to commit"
# Push changes to remote, force with lease for safety
git push --set-upstream origin $BRANCH_NAME || exit 1
- name: 🔀 Create Pull Request
if: steps.check_changes.outputs.changes == 'true'
run: gh pr create -B main --title "Update dependencies" --body "Created by Github action"
env:
GITHUB_TOKEN: ${{ secrets.ACTION_WORKFLOW_GITHUB_TOKEN }}