-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomatic-composer-update.yml
174 lines (149 loc) · 5.55 KB
/
automatic-composer-update.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Composer Workflow
on:
workflow_dispatch:
push:
paths:
- '**/*.yml'
- 'composer.json'
- 'composer.lock'
pull_request:
paths:
- '**/*.yml'
- 'composer.json'
- 'composer.lock'
# Prevent concurrent workflow runs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
generate-composer-lock:
name: Generate composer.lock
if: |
github.event_name == 'push' && (
contains(github.event.head_commit.modified, 'composer.json') ||
contains(github.event.head_commit.modified, 'composer.lock') ||
startsWith(github.event.head_commit.message, 'Update dependencies')
)
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
extensions: mbstring, intl, xml
coverage: none
tools: composer:v2
- name: Get Composer Cache Directory
id: composer-cache-dir
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer Dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Generate composer.lock
run: |
rm -f composer.lock
composer install --prefer-dist --no-progress --no-interaction
- name: Check for Changes
id: check-changes
run: |
git diff --exit-code composer.lock || echo "changes=true" >> $GITHUB_OUTPUT
- name: Commit composer.lock
if: steps.check-changes.outputs.changes == 'true'
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add composer.lock
git commit -m "🔄 Update composer.lock [skip ci]"
git push
composer-compatibility-check:
name: Composer Compatibility Check
runs-on: ubuntu-latest
needs: generate-composer-lock
permissions:
contents: write
pull-requests: write
issues: write
strategy:
matrix:
php-version: ['8.1', '8.2']
fail-fast: false
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mbstring, intl, xml
coverage: none
tools: composer:v2
- name: Get Composer Cache Directory
id: composer-cache-dir
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer Dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-
${{ runner.os }}-composer-
- name: Validate composer.json
run: composer validate --strict
- name: Install Dependencies
id: install
continue-on-error: true
run: composer install --no-interaction --prefer-dist --no-progress
- name: Run Tests
if: steps.install.outcome == 'success'
run: |
if [ -d "tests/" ]; then
vendor/bin/phpunit tests/
else
echo "No tests directory found, skipping tests"
fi
- name: Create Pull Request for Compatibility Fix
if: |
steps.install.outcome == 'failure' &&
github.event_name != 'pull_request' &&
github.ref == 'refs/heads/main'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "🔧 Fix composer compatibility for PHP ${{ matrix.php-version }}"
title: "Fix: Composer Compatibility for PHP ${{ matrix.php-version }}"
body: |
# Composer Compatibility Fix
This PR addresses compatibility issues detected with PHP ${{ matrix.php-version }}.
## Changes
- Automated dependency updates for PHP ${{ matrix.php-version }} compatibility
- Generated by GitHub Actions workflow
Please review the changes carefully before merging.
branch: fix/composer-php-${{ matrix.php-version }}-${{ github.sha }}
delete-branch: true
base: main
- name: Comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const outcome = '${{ steps.install.outcome }}';
const message = outcome === 'success'
? '✅ Dependency installation successful for PHP ${{ matrix.php-version }}'
: '❌ Dependency installation failed for PHP ${{ matrix.php-version }}. Check the workflow logs for details.';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.name,
body: message
});