Skip to content

Commit 20e10e5

Browse files
authored
chore(php): Add PHP linting and CI workflow (#81)
1 parent 2cdfacf commit 20e10e5

File tree

114 files changed

+2498
-2445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+2498
-2445
lines changed

.github/actions/cache/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ runs:
6767
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-java-2/target
6868
key: ${{ runner.os }}-java-client-${{ hashFiles('clients/algoliasearch-client-java-2/**') }}
6969

70+
- name: Restore built PHP search client
71+
if: ${{ inputs.job == 'cts' }}
72+
uses: actions/cache@v2
73+
with:
74+
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-php/dist
75+
key: ${{ runner.os }}-php-client-${{ hashFiles('clients/algoliasearch-client-php/**') }}
76+
7077
# setup yarn
7178
- name: Get yarn cache directory path
7279
shell: bash

.github/actions/setup/action.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ runs:
4040
echo "::set-output name=JAVA_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-java-2 | wc -l)"
4141
echo "::set-output name=JAVA_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/java | wc -l)"
4242
43+
echo "::set-output name=PHP_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-php | wc -l)"
44+
echo "::set-output name=PHP_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/php | wc -l)"
45+
4346
- name: Compute specs matrix
4447
id: spec-matrix
4548
shell: bash
@@ -91,6 +94,23 @@ runs:
9194
echo "::set-output name=MATRIX::$matrix"
9295
echo "::set-output name=RUN_CLIENT::$run"
9396
97+
- name: Compute the PHP client build matrix
98+
id: php-matrix
99+
shell: bash
100+
run: |
101+
base_changed=${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.PHP_TEMPLATE_CHANGED > 0 }}
102+
103+
matrix=$(./scripts/ci/create-client-matrix.sh php $base_changed ${{ github.base_ref }})
104+
105+
if [[ $matrix == '{"client":["no-run"]}' ]]; then
106+
run="false"
107+
else
108+
run="true"
109+
fi
110+
111+
echo "::set-output name=MATRIX::$matrix"
112+
echo "::set-output name=RUN_CLIENT::$run"
113+
94114
outputs:
95115
RUN_SPECS:
96116
description: Whether to run specs or not
@@ -116,6 +136,14 @@ outputs:
116136
description: Generate the matrix for the Java client
117137
value: ${{ steps.java-matrix.outputs.MATRIX }}
118138

139+
RUN_PHP:
140+
description: Whether to run php client or not
141+
value: ${{ steps.php-matrix.outputs.RUN_CLIENT }}
142+
143+
PHP_MATRIX:
144+
description: Generate the matrix for the PHP client
145+
value: ${{ steps.php-matrix.outputs.MATRIX }}
146+
119147
RUN_CTS:
120148
description: Determine if the `cts` job should run
121149
value: ${{ github.ref_name == 'main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.SPECS_CHANGED > 0 || steps.diff.outputs.TESTS_CHANGED > 0 || steps.diff.outputs.JS_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 || steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}

.github/workflows/check.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
RUN_JAVA: ${{ steps.setup.outputs.RUN_JAVA }}
3737
JAVA_MATRIX: ${{ steps.setup.outputs.JAVA_MATRIX }}
3838

39+
RUN_PHP: ${{ steps.setup.outputs.RUN_PHP }}
40+
PHP_MATRIX: ${{ steps.setup.outputs.PHP_MATRIX }}
41+
3942
RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }}
4043

4144
specs:
@@ -116,11 +119,44 @@ jobs:
116119
if: steps.cache.outputs.cache-hit != 'true'
117120
run: yarn build:clients java ${{ matrix.client.name }}
118121

122+
client_php:
123+
runs-on: ubuntu-20.04
124+
needs:
125+
- setup
126+
- specs
127+
if: ${{ always() && needs.setup.outputs.RUN_PHP == 'true' }}
128+
strategy:
129+
matrix: ${{ fromJSON(needs.setup.outputs.PHP_MATRIX) }}
130+
steps:
131+
- uses: actions/checkout@v2
132+
133+
- name: Restore cache
134+
uses: ./.github/actions/cache
135+
with:
136+
job: php
137+
138+
- name: Cache ${{ matrix.client.name }} client
139+
id: cache
140+
uses: actions/cache@v2
141+
with:
142+
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/dist'
143+
key: ${{ runner.os }}-php-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}
144+
145+
- name: Generate ${{ matrix.client.name }} client
146+
if: steps.cache.outputs.cache-hit != 'true'
147+
run: yarn generate php ${{ matrix.client.name }}
148+
149+
- name: Build ${{ matrix.client.name }} client
150+
if: steps.cache.outputs.cache-hit != 'true'
151+
run: yarn build:clients php ${{ matrix.client.name }}
152+
119153
cts:
120154
runs-on: ubuntu-20.04
121155
needs:
122156
- client_javascript
123157
- client_java
158+
- client_php
159+
124160
if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
125161
steps:
126162
- uses: actions/checkout@v2

clients/algoliasearch-client-php/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ composer.phar
1010
.phpunit.result.cache
1111

1212
.openapi-generator/
13+
composer.lock

clients/algoliasearch-client-php/.openapi-generator-ignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ docs/**
88
test/**
99

1010
.travis.yml
11-
.php_cs
1211
phpunit.xml.dist
1312
README.md
1413
git_push.sh
14+
.php_cs

clients/algoliasearch-client-php/.openapi-generator/FILES

Lines changed: 0 additions & 104 deletions
This file was deleted.

clients/algoliasearch-client-php/.openapi-generator/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
$config = new PhpCsFixer\Config();
4+
5+
return $config
6+
->setUsingCache(true)
7+
->setRules([
8+
'array_syntax' => [ 'syntax' => 'short' ],
9+
'blank_line_after_namespace' => false,
10+
'blank_line_after_opening_tag' => true,
11+
'blank_line_before_statement' => true,
12+
'braces' => false,
13+
'cast_spaces' => true,
14+
'combine_consecutive_unsets' => true,
15+
'echo_tag_syntax' => true,
16+
'general_phpdoc_tag_rename' => true,
17+
'mb_str_functions' => true,
18+
'no_blank_lines_after_class_opening' => true,
19+
'no_empty_phpdoc' => true,
20+
'no_empty_statement' => true,
21+
'no_extra_blank_lines' => true,
22+
'no_multiline_whitespace_around_double_arrow' => true,
23+
'no_short_bool_cast' => true,
24+
'no_trailing_whitespace' => true,
25+
'no_trailing_whitespace_in_comment' => false,
26+
'no_unneeded_control_parentheses' => true,
27+
'no_unreachable_default_argument_value' => true,
28+
'no_unused_imports' => true,
29+
'no_useless_else' => true,
30+
'no_useless_return' => true,
31+
'no_whitespace_before_comma_in_array' => true,
32+
'no_whitespace_in_blank_line' => true,
33+
'normalize_index_brace' => true,
34+
'not_operator_with_space' => false,
35+
'object_operator_without_whitespace' => true,
36+
'ordered_imports' => true,
37+
'phpdoc_annotation_without_dot' => true,
38+
'phpdoc_inline_tag_normalizer' => true,
39+
'phpdoc_order' => true,
40+
'phpdoc_scalar' => true,
41+
'phpdoc_separation' => true,
42+
'phpdoc_single_line_var_spacing' => true,
43+
'phpdoc_tag_type' => true,
44+
'protected_to_private' => true,
45+
'@PSR2' => true,
46+
'short_scalar_cast' => true,
47+
'single_blank_line_at_eof' => false,
48+
'single_blank_line_before_namespace' => true,
49+
'single_quote' => true,
50+
'space_after_semicolon' => true,
51+
'standardize_not_equals' => true,
52+
'strict_comparison' => true,
53+
'strict_param' => true,
54+
'ternary_operator_spaces' => true,
55+
'trailing_comma_in_multiline' => true,
56+
'trim_array_spaces' => true,
57+
])
58+
->setFinder(
59+
PhpCsFixer\Finder::create()
60+
->exclude('test')
61+
->exclude('tests')
62+
->in(__DIR__)
63+
);

0 commit comments

Comments
 (0)