Skip to content

chore(php): Add PHP linting and CI workflow #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ runs:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-java-2/target
key: ${{ runner.os }}-java-client-${{ hashFiles('clients/algoliasearch-client-java-2/**') }}

- name: Restore built PHP search client
if: ${{ inputs.job == 'cts' }}
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-php/dist
key: ${{ runner.os }}-php-client-${{ hashFiles('clients/algoliasearch-client-php/**') }}

# setup yarn
- name: Get yarn cache directory path
shell: bash
Expand Down
28 changes: 28 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ runs:
echo "::set-output name=JAVA_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-java-2 | wc -l)"
echo "::set-output name=JAVA_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/java | wc -l)"

echo "::set-output name=PHP_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-php | wc -l)"
echo "::set-output name=PHP_TEMPLATE_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- templates/php | wc -l)"

- name: Compute specs matrix
id: spec-matrix
shell: bash
Expand Down Expand Up @@ -91,6 +94,23 @@ runs:
echo "::set-output name=MATRIX::$matrix"
echo "::set-output name=RUN_CLIENT::$run"

- name: Compute the PHP client build matrix
id: php-matrix
shell: bash
run: |
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 }}

matrix=$(./scripts/ci/create-client-matrix.sh php $base_changed ${{ github.base_ref }})

if [[ $matrix == '{"client":["no-run"]}' ]]; then
run="false"
else
run="true"
fi

echo "::set-output name=MATRIX::$matrix"
echo "::set-output name=RUN_CLIENT::$run"

outputs:
RUN_SPECS:
description: Whether to run specs or not
Expand All @@ -116,6 +136,14 @@ outputs:
description: Generate the matrix for the Java client
value: ${{ steps.java-matrix.outputs.MATRIX }}

RUN_PHP:
description: Whether to run php client or not
value: ${{ steps.php-matrix.outputs.RUN_CLIENT }}

PHP_MATRIX:
description: Generate the matrix for the PHP client
value: ${{ steps.php-matrix.outputs.MATRIX }}

RUN_CTS:
description: Determine if the `cts` job should run
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 }}
36 changes: 36 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:
RUN_JAVA: ${{ steps.setup.outputs.RUN_JAVA }}
JAVA_MATRIX: ${{ steps.setup.outputs.JAVA_MATRIX }}

RUN_PHP: ${{ steps.setup.outputs.RUN_PHP }}
PHP_MATRIX: ${{ steps.setup.outputs.PHP_MATRIX }}

RUN_CTS: ${{ steps.setup.outputs.RUN_CTS }}

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

client_php:
runs-on: ubuntu-20.04
needs:
- setup
- specs
if: ${{ always() && needs.setup.outputs.RUN_PHP == 'true' }}
strategy:
matrix: ${{ fromJSON(needs.setup.outputs.PHP_MATRIX) }}
steps:
- uses: actions/checkout@v2

- name: Restore cache
uses: ./.github/actions/cache
with:
job: php

- name: Cache ${{ matrix.client.name }} client
id: cache
uses: actions/cache@v2
with:
path: '/home/runner/work/api-clients-automation/api-clients-automation/${{ matrix.client.folder }}/dist'
key: ${{ runner.os }}-php-client-${{ matrix.client.name }}-${{ hashFiles(format('{0}/**', matrix.client.folder)) }}

- name: Generate ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate php ${{ matrix.client.name }}

- name: Build ${{ matrix.client.name }} client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients php ${{ matrix.client.name }}

cts:
runs-on: ubuntu-20.04
needs:
- client_javascript
- client_java
- client_php

if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions clients/algoliasearch-client-php/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ composer.phar
.phpunit.result.cache

.openapi-generator/
composer.lock
2 changes: 1 addition & 1 deletion clients/algoliasearch-client-php/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ docs/**
test/**

.travis.yml
.php_cs
phpunit.xml.dist
README.md
git_push.sh
.php_cs
104 changes: 0 additions & 104 deletions clients/algoliasearch-client-php/.openapi-generator/FILES

This file was deleted.

This file was deleted.

63 changes: 63 additions & 0 deletions clients/algoliasearch-client-php/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

$config = new PhpCsFixer\Config();

return $config
->setUsingCache(true)
->setRules([
'array_syntax' => [ 'syntax' => 'short' ],
'blank_line_after_namespace' => false,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => true,
'braces' => false,
'cast_spaces' => true,
'combine_consecutive_unsets' => true,
'echo_tag_syntax' => true,
'general_phpdoc_tag_rename' => true,
'mb_str_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_blank_lines' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_short_bool_cast' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => false,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_space' => false,
'object_operator_without_whitespace' => true,
'ordered_imports' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_tag_type' => true,
'protected_to_private' => true,
'@PSR2' => true,
'short_scalar_cast' => true,
'single_blank_line_at_eof' => false,
'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
'strict_comparison' => true,
'strict_param' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('test')
->exclude('tests')
->in(__DIR__)
);
Loading