forked from sebastianbergmann/phpcpd
-
Notifications
You must be signed in to change notification settings - Fork 3
152 lines (127 loc) · 5.53 KB
/
ci.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
# https://help.github.com/en/categories/automating-your-workflow-with-github-actions
on:
"pull_request": ~
"push":
branches:
- 'main'
name: "CI"
jobs:
coding-guidelines:
name: "Coding Guidelines"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v3"
- name: "Run friendsofphp/php-cs-fixer"
run: |
wget https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
php php-cs-fixer fix --dry-run --show-progress=dots --using-cache=no --verbose
type-checker:
name: "Type Checker"
runs-on: "ubuntu-latest"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
tools: composer:2.5.x, php-cs-fixer:3.17.x, psalm:5.12.x
- name: "Update dependencies with composer"
run: "composer update --no-ansi --no-interaction --no-progress"
- name: "Run vimeo/psalm"
run: "psalm --config=.psalm/config.xml --no-progress --shepherd --show-info=false --stats"
tests:
name: "Tests"
runs-on: "ubuntu-latest"
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
tools: composer, phpunit:9.5
- name: "Cache dependencies installed with composer"
uses: "actions/cache@v1"
with:
path: "~/.composer/cache"
key: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }}"
restore-keys: "php${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-"
- name: "Install dependencies with composer"
run: "composer update --no-ansi --no-interaction --no-progress"
- name: "Run tests with phpunit/phpunit"
run: "phpunit --coverage-clover=coverage.xml"
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
rector-php-cs-fixer-pr:
name: PHP-CS-Fixer / Rector
runs-on: "ubuntu-latest"
if: github.actor != 'dependabot[bot]'
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
with:
fetch-depth: 0
- name: "Install PHP with extensions"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "pcov"
tools: composer, phpunit:9.5
- name: Get PR Data
id: pr
run: |
cat "$GITHUB_EVENT_PATH" | jq .
export NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
echo "::set-output name=number::$NUMBER"
export BRANCH=$(jq --raw-output .pull_request.head.ref "$GITHUB_EVENT_PATH")
echo "::set-output name=branch::$BRANCH"
export TITLE=$(jq --raw-output .pull_request.title "$GITHUB_EVENT_PATH")
echo "::set-output name=title::$TITLE"
- name: Checkout PR
run: |
git checkout ${{ steps.pr.outputs.branch }}
# —— Composer 🧙️ —————————————————————————————————————————————————————————
- name: Validate composer.json and composer.lock
run: composer validate
- name: Install Composer dependencies
run: composer install
# —— Run php-cs-fixer and rector 🧙️———————————————————————————————————————
- name: php-cs-fixer
run: |
wget https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
php php-cs-fixer fix
- name: commit php-cs-fixer changes
run: |
git diff --quiet && git diff --staged --quiet || git -c user.name='php-cs-fixer' -c user.email='php-cs-fixer@neubaukompass.de' commit -a -m "Changes by php-cs-fixer"
- name: rector
run: |
./vendor/bin/rector process
git add -u
- name: commit rector changes
run: |
git diff --quiet && git diff --staged --quiet || git -c user.name='rector' -c user.email='rector@neubaukompass.de' commit -a -m "Ruling the world via Rector!"
# —— Create PR if there are change 🧙️—————————————————————————————————————
- name: Create PR for CS fixups
uses: peter-evans/create-pull-request@v4 # renovate: tag=v4.0.2
id: create-pull-request
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: "[rector] ${{ steps.pr.outputs.title }}"
base: ${{ steps.pr.outputs.branch }}
branch: rectified/${{ steps.pr.outputs.branch }}
assignees: ${{ github.actor }}
labels: php-cs-fixer, rector
body: Please merge these changes into the ${{ steps.pr.outputs.branch }} branch to fix coding standard violations.
commit-message: Changed by rector in ${{ steps.pr.outputs.branch }}
- name: Fail the workflow when necessary CS fixes were detected
run: echo "Failing workflow run because CS violations were detected." && exit 1
if: steps.create-pull-request.outputs.pr_number