-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (58 loc) · 2.7 KB
/
fix-php-code-style-issues.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
name: Format PHP Code
on: [pull_request]
env:
PR_NUMBER: '${{ github.event.number }}'
SOURCE_BRANCH: '$GITHUB_HEAD_REF'
FIXER_BRANCH: 'auto-fixed/$GITHUB_HEAD_REF'
TITLE: 'Apply Laravel Pint Fixes'
DESCRIPTION: 'This merge request applies PHP code style fixes from an analysis carried out through GitHub Actions.'
jobs:
php-cs-fixer:
if: github.event_name == 'pull_request' && ! startsWith(github.ref, 'refs/heads/auto-fixed/')
runs-on: ubuntu-latest
name: Run Pint
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: 8.3
extensions: json, dom, curl, libxml, mbstring
coverage: none
- 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
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Prepare Git User
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "${{ env.FIXER_BRANCH }}"
- name: Apply auto-fixers
run: ./vendor/bin/pint -v
- name: Create Fixer PR
run: |
if [[ -z $(git status --porcelain) ]]; then
echo "Nothing to fix.. Exiting."
exit 0
fi
OPEN_PRS=`curl --silent -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls?state=open"`
OPEN_FIXER_PRS=`echo ${OPEN_PRS} | grep -o "\"ref\": \"${{ env.FIXER_BRANCH }}\"" | wc -l`
git commit -am "${{ env.TITLE }}"
git push origin "${{ env.FIXER_BRANCH }}" --force
if [ ${OPEN_FIXER_PRS} -eq "0" ]; then
curl -X POST \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/pulls" \
-d "{ \"head\":\"${{ env.FIXER_BRANCH }}\", \"base\":\"${{ env.SOURCE_BRANCH }}\", \"title\":\"${{ env.TITLE }}\", \"body\":\"${{ env.DESCRIPTION }}\n\nTriggered by #${{ env.PR_NUMBER }}\" }"
fi
exit 1