-
Notifications
You must be signed in to change notification settings - Fork 0
70 lines (63 loc) · 2.3 KB
/
Copy pathphp-cs-fixer.yml
File metadata and controls
70 lines (63 loc) · 2.3 KB
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
name: Module PHP CS Fixer
on:
workflow_call:
inputs:
php-version:
required: false
type: string
default: '8.2'
jobs:
php-cs-fixer:
name: PHP Coding Standards Fixer
runs-on: ubuntu-latest
env:
skip_phpcs: 'false'
steps:
- name: Checkout Module
uses: actions/checkout@v4
- name: Check if branch is allowed
run: |
ALLOWED_BRANCHES=("master" "main" "develop" "bs5")
CURRENT_BRANCH="${GITHUB_REF_NAME}"
if [[ ! " ${ALLOWED_BRANCHES[@]} " =~ " ${CURRENT_BRANCH} " ]]; then
echo "skip_phpcs=true" >> $GITHUB_ENV
echo "This workflow runs only for master, main, develop and bs5 branches."
fi
shell: bash
- name: Check the commit message for skipping PHP-CS-Fixer
if: env.skip_phpcs == 'false'
run: |
if git log -1 --pretty=%B | grep -q '\[SKIP-PHPCS\]'; then
echo "skip_phpcs=true" >> $GITHUB_ENV
echo "Skip PHP-CS-Fixer because the commit message contains [SKIP-PHPCS]."
fi
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php-version }}
tools: composer
- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- name: Run Rector
run: composer fixer
- name: Create branch and Pull Request for new changes
if: env.skip_phpcs == 'false'
run: |
git config user.name "GitHub Action"
git config user.email "action@github.com"
if git diff --quiet; then
echo "No changes detected by PHP-CS-Fixer. Skipping commit and PR creation."
exit 0
fi
PHP_FIXER_DATETIME=$(date +%Y-%m-%d-%H%M%S)
git checkout -b "php-fixer/$PHP_FIXER_DATETIME"
git add -u
git commit -m "Autocommit PHP CS Fixer"
git push origin "php-fixer/$PHP_FIXER_DATETIME"
gh pr create \
--title "PHP CS Fixer $PHP_FIXER_DATETIME" \
--body "This Pull Request includes automated changes from PHP-CS-Fixer." \
--base "${{ github.ref_name }}" \
--head "php-fixer/$PHP_FIXER_DATETIME"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}