Skip to content
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

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

Merged
merged 14 commits into from
Jan 14, 2022
7 changes: 7 additions & 0 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,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 }}-java-client-${{ hashFiles('clients/algoliasearch-client-php/**') }}
damcou marked this conversation as resolved.
Show resolved Hide resolved

# setup yarn
- name: Get yarn cache directory path
shell: bash
Expand Down
10 changes: 9 additions & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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)"

outputs:
# specs variables
RUN_SPECS_SEARCH:
Expand Down Expand Up @@ -102,7 +105,12 @@ outputs:
description: Determine if the `client_java_*` job should run
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SEARCH_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JAVA_CLIENT_CHANGED > 0 || steps.diff.outputs.JAVA_TEMPLATE_CHANGED > 0 }}

# php client variables
RUN_PHP_CLIENT_SEARCH:
description: Determine if the `client_php_*` job should run
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.SEARCH_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.PHP_CLIENT_CHANGED > 0 || steps.diff.outputs.PHP_TEMPLATE_CHANGED > 0 }}

# cts variables
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.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 }}
value: ${{ github.ref_name == 'main' || steps.diff.outputs.GITHUB_ACTIONS_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 || steps.diff.outputs.PHP_CLIENT_CHANGED > 0 || steps.diff.outputs.PHP_TEMPLATE_CHANGED > 0 }}
30 changes: 30 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:

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

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

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

specs_search:
Expand Down Expand Up @@ -318,6 +320,33 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients java search

client_php_search:
runs-on: ubuntu-20.04
needs: [specs_search]
if: ${{ always() && needs.setup.outputs.RUN_PHP_CLIENT == 'true' }}
steps:
- uses: actions/checkout@v2

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

- name: Cache built clients
id: cache
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/**') }}

- name: Generate search client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate php search

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

cts:
runs-on: ubuntu-20.04
needs:
Expand All @@ -328,6 +357,7 @@ jobs:
- client_javascript_analytics
- client_javascript_insights
- client_java_search
- client_php_search

if: ${{ always() && needs.setup.outputs.RUN_CTS == 'true' }}
steps:
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
1 change: 0 additions & 1 deletion clients/algoliasearch-client-php/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ docs/**
test/**

.travis.yml
.php_cs
phpunit.xml.dist
README.md
git_push.sh
1 change: 1 addition & 0 deletions clients/algoliasearch-client-php/.openapi-generator/FILES
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gitignore
damcou marked this conversation as resolved.
Show resolved Hide resolved
.php_cs
composer.json
lib/Api/SearchApi.php
lib/ApiException.php
Expand Down
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' => false,
'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,
'psr_autoloading' => 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__)
);
File renamed without changes.
3 changes: 2 additions & 1 deletion openapitools.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
"gitRepoId": "algoliasearch-client-php",
"invokerPackage": "Algolia\\AlgoliaSearch",
"additionalProperties": {
"variableNamingConvention": "camelCase"
"variableNamingConvention": "camelCase",
"packageName": "algoliasearch-client-php"
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions scripts/post-gen/php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

export GENERATOR=$1
export CLIENT=$(cat openapitools.json | jq -r --arg generator "$GENERATOR" '."generator-cli".generators[$generator].output' | sed 's/#{cwd}\///g')

lint_client() {
set +e

echo "> Linting ${GENERATOR}..."
cd $CLIENT
composer install
php vendor/bin/php-cs-fixer fix lib/ -v --using-cache=no --allow-risky=yes

set -e
}

lint_client
59 changes: 59 additions & 0 deletions templates/php/.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'array_syntax' => [ 'syntax' => 'short' ],
'blank_line_after_namespace' => false,
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
'braces' => false,
'cast_spaces' => true,
'combine_consecutive_unsets' => true,
'mb_str_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'no_short_bool_cast' => true,
'no_short_echo_tag' => true,
'no_trailing_whitespace' => false,
'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' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
'protected_to_private' => true,
'psr4' => 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_array' => true,
'trim_array_spaces' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('test')
->exclude('tests')
->in(__DIR__)
);
1 change: 1 addition & 0 deletions templates/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