-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomposer-workflow.yml
137 lines (116 loc) · 4.96 KB
/
composer-workflow.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
name: Composer Workflow
on:
workflow_dispatch: # Manual trigger
push:
paths:
- '**/*.yml' # Triggers on any YAML file changes
- 'composer.json' # Triggers on changes to composer.json
- 'composer.lock' # Triggers on changes to composer.lock
pull_request:
paths:
- '**/*.yml' # Triggers on any YAML file changes
- 'composer.json' # Triggers on changes to composer.json
- 'composer.lock' # Triggers on changes to composer.lock
jobs:
generate-composer-lock:
name: Generate composer.lock
if: github.event_name == 'push' && (
contains(github.event.head_commit.message, 'composer.json') ||
contains(github.event.head_commit.message, 'composer.lock') ||
startsWith(github.event.head_commit.message, 'Update dependencies')
)
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Ensures full history is fetched
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1' # Ensure PHP 8.1 is used
extensions: mbstring, intl, xml
coverage: none
- name: Install Composer
run: |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
- name: Remove existing composer.lock
run: rm -f composer.lock
- name: Generate composer.lock
run: composer install --prefer-dist --no-progress
- name: Commit composer.lock
run: |
git config --global user.name 'GitHub Actions Bot'
git config --global user.email 'actions@github.com'
git add composer.lock
git commit -m "🔄 Generate composer.lock file" || echo "No changes to commit"
git push
composer-compatibility-check:
name: Composer Compatibility Check
runs-on: ubuntu-latest
strategy:
matrix:
php-version: ['8.1', '8.2'] # Only PHP 8.1 and 8.2
fail-fast: false # Continue running other jobs even if one fails
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
- name: Cache Composer Dependencies
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-${{ matrix.php-version }}
restore-keys: |
${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}-
${{ runner.os }}-composer-
- name: Install Composer
run: |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
php -r "unlink('composer-setup.php');"
- name: Install Dependencies
run: composer install --prefer-dist --no-progress
- name: Validate composer.json
run: composer validate --strict
- name: Run Composer Compatibility Check
run: |
# Attempt to install dependencies
if ! composer install --no-interaction --prefer-dist; then
echo "Dependency installation failed for PHP ${{ matrix.php-version }}."
exit 1
fi
- name: Run Tests
run: vendor/bin/phpunit tests/ # Specify the tests directory
- name: Create Pull Request for Compatibility Fix
if: failure() && github.event_name != 'pull_request'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "🔄 Update composer dependencies for PHP ${{ matrix.php-version }}"
title: "Composer Dependencies Update for PHP ${{ matrix.php-version }}"
body: |
This PR updates composer dependencies to be compatible with PHP ${{ matrix.php-version }}.
Changes were automatically generated due to compatibility issues detected in the workflow.
Please review the changes and merge if appropriate.
branch: fix/composer-compatibility-php-${{ matrix.php-version }}
delete-branch: true
base: main
- name: Comment on Failed Installation in PR
if: failure() && github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.name,
body: '❌ Dependency installation failed for PHP ${{ matrix.php-version }}. Please check the workflow logs for details.'
})