From 49b65c6c5cd9ed7da47ced86b3206e746f75188c Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 09:44:21 +0100 Subject: [PATCH 01/12] Add configlet:fmt command, combine with lint:fix --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 97f5ea4d..63b53748 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,11 @@ "squizlabs/php_codesniffer": "^3.9" }, "scripts": { + "configlet:fmt": "bin/configlet fmt", + "format:fix": [ + "@lint:fix", + "@configlet:fmt" + ], "lint:check": "phpcs", "lint:fix": "phpcbf", "tests:run": "PHPUNIT_BIN='phpunit' bin/test.sh" From 0bfcad433299c188a79e0a6e85e2a5a9b749f2ab Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 09:48:40 +0100 Subject: [PATCH 02/12] Combine all CI tests to command "ci" --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index 63b53748..2cb4f679 100644 --- a/composer.json +++ b/composer.json @@ -16,6 +16,11 @@ "squizlabs/php_codesniffer": "^3.9" }, "scripts": { + "ci": [ + "@configlet:fmt", + "@lint:check", + "@tests:run" + ], "configlet:fmt": "bin/configlet fmt", "format:fix": [ "@lint:fix", From 12f262293b3dae6a75d03714eff164137790d829 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 10:01:04 +0100 Subject: [PATCH 03/12] Don't run configlet, if it does not exist --- composer.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2cb4f679..c113ab08 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,11 @@ "@lint:check", "@tests:run" ], - "configlet:fmt": "bin/configlet fmt", + "tool:configlet:error": "[ -x bin/configlet ] || ( echo 'Fetch configlet first! Run: \"bin/fetch-configlet\"'; false )", + "configlet:fmt": [ + "@tool:configlet:error", + "bin/configlet fmt" + ], "format:fix": [ "@lint:fix", "@configlet:fmt" From 6f96224e4f9eb9a2ce04c5058a0d26185c17a1d5 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 10:10:20 +0100 Subject: [PATCH 04/12] Install / update configlet with composer packages --- README.md | 11 ++++++----- composer.json | 13 +++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d9d17082..449dd0a4 100644 --- a/README.md +++ b/README.md @@ -10,19 +10,19 @@ To solve the exercises, head to the [PHP track][exercism-track-home] and check t The following system dependencies are required: - `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer]. -- [`bash` shell][gnu-bash] +- [`bash` shell][gnu-bash]. - PHP V8.2+ CLI +- An active Internet connection for installing required tools / composer packages. -Run the following commands to get started with this project: +Run the following command to get started with this project: ```shell -bin/fetch-configlet # The official tool for managing Exercism language track repositories composer install # Required dependencies to develop this track ``` ## Running Exercism resources management -`bin/configlet` is a tool to manage exercism resources in this track. +`bin/configlet` is the official tool for managing Exercism language track repositories. See [Building Exercism docs][exercism-configlet]. ## Running Unit Test Suite @@ -49,8 +49,9 @@ composer lint:fix # Automatically fix codestyle issues - Read the documentation at [Exercism][exercism-docs]. - Follow the [PSR-12] coding style (Exercisms PHP track uses a slightly [modified][local-file-phpcs-config] version of [PSR-12]). +- Run `composer ci` to run CI checks locally before pushing. - CI is run on all pull requests, it must pass the required checks for merge. -- CI is running all tests on PHP 8.0 to PHP 8.2 +- CI is running all tests on PHP 8.0 to PHP 8.2 for Linux, Windows and MacOS. ## Generating new practice exercises diff --git a/composer.json b/composer.json index c113ab08..62025ba1 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,25 @@ "squizlabs/php_codesniffer": "^3.9" }, "scripts": { + "post-install-cmd": [ + "echo 'this needs to show up'", + "env", + "@tool:configlet:fetch" + ], + "post-update-cmd": [ + "@tool:configlet:update" + ], "ci": [ "@configlet:fmt", "@lint:check", "@tests:run" ], "tool:configlet:error": "[ -x bin/configlet ] || ( echo 'Fetch configlet first! Run: \"bin/fetch-configlet\"'; false )", + "tool:configlet:fetch": "[ -z \"$CI\" ] || [ -x bin/configlet ] || bin/fetch-configlet", + "tool:configlet:update": [ + "rm bin/configlet || true", + "bin/fetch-configlet" + ], "configlet:fmt": [ "@tool:configlet:error", "bin/configlet fmt" From d0c1f9b2a8df3ecfcf6ab2e6cf4267435f3c9b27 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 10:36:16 +0100 Subject: [PATCH 05/12] CI does not run on force push correctly? --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 62025ba1..06c9831c 100644 --- a/composer.json +++ b/composer.json @@ -17,8 +17,7 @@ }, "scripts": { "post-install-cmd": [ - "echo 'this needs to show up'", - "env", + "echo 'this must show up'; echo '$CI: '$CI", "@tool:configlet:fetch" ], "post-update-cmd": [ From 0546173242725aad2fab2c08882fa8ce48b05d56 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 10:45:54 +0100 Subject: [PATCH 06/12] WTF? --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 06c9831c..d2527653 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "scripts": { "post-install-cmd": [ - "echo 'this must show up'; echo '$CI: '$CI", + "cat composer.json", "@tool:configlet:fetch" ], "post-update-cmd": [ From d47d47f00d2ee4b720ae7c940c1ed6ea5bdc8f8b Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 10:53:53 +0100 Subject: [PATCH 07/12] Try modified workflow to get the environment set --- .github/workflows/exercise-lint-phpcs-psr-12.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/exercise-lint-phpcs-psr-12.yml b/.github/workflows/exercise-lint-phpcs-psr-12.yml index 27d0f4e6..266be13b 100644 --- a/.github/workflows/exercise-lint-phpcs-psr-12.yml +++ b/.github/workflows/exercise-lint-phpcs-psr-12.yml @@ -10,27 +10,24 @@ on: jobs: test: name: PHPCS Linting - ${{ github.event_name }} - runs-on: ubuntu-22.04 + runs-on: ${{ matrix.os }} strategy: fail-fast: false + matrix: + php-version: [8.2] + os: [ubuntu-22.04] steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 - uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d with: - php-version: '8.2' + php-version: ${{ matrix.php-version }} extensions: gmp tools: composer - - name: Install dependencies - shell: bash - run: | - curl -Lo bin/phpcs.phar https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar - chmod +x bin/phpcs.phar - - name: Install composer packages - run: composer install + run: CI="true" composer install - name: Lint exercises shell: bash From 2b04821831db47e89d6d2616535f0ed1dd30edb5 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 11:03:39 +0100 Subject: [PATCH 08/12] Don't fetch configlet on update, too. This might be the problem why it didn't work as expected. No 'composer.lock' -> 'composer update' is run. --- .github/workflows/exercise-lint-phpcs-psr-12.yml | 2 +- composer.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/exercise-lint-phpcs-psr-12.yml b/.github/workflows/exercise-lint-phpcs-psr-12.yml index 266be13b..3434f625 100644 --- a/.github/workflows/exercise-lint-phpcs-psr-12.yml +++ b/.github/workflows/exercise-lint-phpcs-psr-12.yml @@ -27,7 +27,7 @@ jobs: tools: composer - name: Install composer packages - run: CI="true" composer install + run: composer install - name: Lint exercises shell: bash diff --git a/composer.json b/composer.json index d2527653..8786366f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ }, "scripts": { "post-install-cmd": [ - "cat composer.json", "@tool:configlet:fetch" ], "post-update-cmd": [ @@ -32,7 +31,7 @@ "tool:configlet:fetch": "[ -z \"$CI\" ] || [ -x bin/configlet ] || bin/fetch-configlet", "tool:configlet:update": [ "rm bin/configlet || true", - "bin/fetch-configlet" + "[ -n \"$CI\" ] || bin/fetch-configlet" ], "configlet:fmt": [ "@tool:configlet:error", From 6cfb3c41611d2ff9326f23b2c0e7adf5cccbfc2b Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 11:07:38 +0100 Subject: [PATCH 09/12] Remove PHP 7.4 from 'composer.json' --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8786366f..84645ef3 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } }, "require-dev": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "phpunit/phpunit": "^9.6 || ^10.5", "slevomat/coding-standard": "^8.14.1", "squizlabs/php_codesniffer": "^3.9" From 24162ea167987f791794067e7384204d2f701884 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Sun, 3 Mar 2024 11:13:41 +0100 Subject: [PATCH 10/12] Improve README --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 449dd0a4..89a339dc 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,9 @@ composer install # Required dependencies to develop this track `bin/configlet` is the official tool for managing Exercism language track repositories. See [Building Exercism docs][exercism-configlet]. +For convenience, you can use `composer configlet:fmt` to fix formatting issues in the Exercism track files. +This is included in `composer ci` to run the CI checks locally. + ## Running Unit Test Suite The tests are run with PHPUnit. A shell loop injecting `exemplar.php` is provided to ease testing. @@ -35,16 +38,20 @@ Execute the following command to run the tests: composer test:run ``` +This is included in `composer ci` to run the CI checks locally. + ## Running Style Checker -This project use a slightly [modified][local-file-phpcs-config] version of [PSR-12]. +This project uses a slightly [modified][local-file-phpcs-config] version of [PSR-12]. Use the following commands to apply code style: ```shell composer lint:check # Checks the files against the code style rules -composer lint:fix # Automatically fix codestyle issues +composer lint:fix # Automatically fix code style issues ``` +The `lint:check` is included in `composer ci` to run the CI checks locally. + ## Contributing - Read the documentation at [Exercism][exercism-docs]. From efe3c277376b0c2157ed4291fdde5f48ed759893 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Mon, 4 Mar 2024 08:52:36 +0100 Subject: [PATCH 11/12] Add dot to list in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 89a339dc..7c5d0a88 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The following system dependencies are required: - `composer`, as recommended in the [PHP track installation docs][exercism-track-installation-composer]. - [`bash` shell][gnu-bash]. -- PHP V8.2+ CLI +- PHP V8.2+ CLI. - An active Internet connection for installing required tools / composer packages. Run the following command to get started with this project: From 59aab70e4ed192de9b53e62985f90843d5dcda15 Mon Sep 17 00:00:00 2001 From: Michael Kramer Date: Mon, 4 Mar 2024 18:27:34 +0100 Subject: [PATCH 12/12] Do not run composer scripts in CI, remove checks --- .github/workflows/exercise-lint-phpcs-psr-12.yml | 2 +- composer.json | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/exercise-lint-phpcs-psr-12.yml b/.github/workflows/exercise-lint-phpcs-psr-12.yml index 3434f625..699777fe 100644 --- a/.github/workflows/exercise-lint-phpcs-psr-12.yml +++ b/.github/workflows/exercise-lint-phpcs-psr-12.yml @@ -27,7 +27,7 @@ jobs: tools: composer - name: Install composer packages - run: composer install + run: composer install --no-scripts - name: Lint exercises shell: bash diff --git a/composer.json b/composer.json index 84645ef3..695a71d9 100644 --- a/composer.json +++ b/composer.json @@ -27,14 +27,12 @@ "@lint:check", "@tests:run" ], - "tool:configlet:error": "[ -x bin/configlet ] || ( echo 'Fetch configlet first! Run: \"bin/fetch-configlet\"'; false )", - "tool:configlet:fetch": "[ -z \"$CI\" ] || [ -x bin/configlet ] || bin/fetch-configlet", + "tool:configlet:fetch": "[ -x bin/configlet ] || bin/fetch-configlet", "tool:configlet:update": [ "rm bin/configlet || true", - "[ -n \"$CI\" ] || bin/fetch-configlet" + "bin/fetch-configlet" ], "configlet:fmt": [ - "@tool:configlet:error", "bin/configlet fmt" ], "format:fix": [