diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 44dcf985..a48efcfb 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -1,5 +1,10 @@ on: pull_request +# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#defining-environment-variables-for-a-single-workflow +# (cf. services.phpfpm.user in ../../docker-compose.yml) +env: + COMPOSE_USER: root + name: PR Review jobs: fail-for-do-not-merge: @@ -58,112 +63,65 @@ jobs: composer install --no-interaction --no-progress composer normalize composer.json --dry-run - coding-standards-phpcs: - name: PHP - Check Coding Standards + coding-standards-assets: + name: Assets - Check Coding Standards runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v2 - with: - php-version: 8.3 - extensions: ctype, dom, iconv, json, zip, gd, soap - coverage: none - tools: composer:v2 - # https://github.com/shivammathur/setup-php#cache-composer-dependencies - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Dependencies - run: | - composer install --no-interaction --no-progress --no-scripts - # @see https://github.com/Dealerdirect/phpcodesniffer-composer-installer#calling-the-plugin-directly - composer run-script install-codestandards - - name: PHPCS - run: | - composer coding-standards-check/phpcs + - uses: pnorton5432/setup-task@v1 + - run: task coding-standards:assets:check + # Check for any changes (task …:check runs task …:apply) + - run: git diff --exit-code - coding-standards-twig-cs-fixer: - name: Twig - Check Coding Standards + coding-standards-markdown: + name: Markdown - Check Coding Standards runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v2 - with: - php-version: 8.3 - extensions: ctype, dom, iconv, json, zip, gd, soap - coverage: none - tools: composer:v2 - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Dependencies - run: | - composer install --no-interaction --no-progress --no-scripts - # @see https://github.com/Dealerdirect/phpcodesniffer-composer-installer#calling-the-plugin-directly - composer run-script install-codestandards - - name: TwigCS - run: | - composer coding-standards-check/twig-cs-fixer + - uses: pnorton5432/setup-task@v1 + - run: task coding-standards:markdown:check + # Check for any changes (task …:check runs task …:apply) + - run: git diff --exit-code - coding-standards-markdown: - name: Yarn - Check Coding Standards (Node ${{ matrix.node }}) + coding-standards-php: + name: PHP - Check Coding Standards runs-on: ubuntu-latest - strategy: - matrix: - node: [ '16' ] steps: - uses: actions/checkout@v4 - - name: Setup node - uses: actions/setup-node@v2 - with: - node-version: ${{ matrix.node }} + - uses: pnorton5432/setup-task@v1 - run: | - yarn install - yarn coding-standards-check + docker network create frontend + task compose -- up --detach + task composer -- install + task coding-standards:php:check + # Check for any changes (task …:check runs task …:apply) + - run: git diff --exit-code + + coding-standards-twig: + name: Twig - Check Coding Standards + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnorton5432/setup-task@v1 + - run: | + docker network create frontend + task compose -- up --detach + task composer -- install + task coding-standards:twig:check + # Check for any changes (task …:check runs task …:apply) + - run: git diff --exit-code code-analysis: name: PHP - Code analysis runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v2 - with: - php-version: 8.3 - extensions: ctype, dom, iconv, json, zip, gd, soap - coverage: none - tools: composer:v2 - # https://github.com/shivammathur/setup-php#cache-composer-dependencies - - name: Get composer cache directory - id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composer-cache.outputs.dir }} - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- - - name: Install Dependencies - run: | - # Using `--no-scripts` breaks something with mglaman/drupal-check. - composer install --no-interaction --no-progress --no-scripts - - name: code-analysis - run: | - composer code-analysis + - uses: pnorton5432/setup-task@v1 + - run: | + docker network create frontend + task compose -- up --detach + task composer -- install + task code-analysis coding-standards-custom-themes: name: Yarn - Check Coding Standards in custom themes diff --git a/Taskfile.yml b/Taskfile.yml index bf7f775e..a74ac771 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -134,8 +134,8 @@ tasks: coding-standards:apply: desc: "Apply coding standards" cmds: - - task: coding-standards:markdown:apply - task: coding-standards:assets:apply + - task: coding-standards:markdown:apply - task: coding-standards:php:apply - task: coding-standards:twig:apply silent: true @@ -143,8 +143,8 @@ tasks: coding-standards:check: desc: "Apply coding standards" cmds: - - task: coding-standards:markdown:check - task: coding-standards:assets:check + - task: coding-standards:markdown:check - task: coding-standards:php:check - task: coding-standards:twig:check silent: true @@ -156,43 +156,58 @@ tasks: # https://github.com/prettier/prettier/issues/15206) have an official # docker image. # https://hub.docker.com/r/jauderho/prettier is good candidate (cf. https://hub.docker.com/search?q=prettier&sort=updated_at&order=desc) - - docker pull jauderho/prettier - docker run --rm --volume "$PWD:/work" jauderho/prettier --write playwright coding-standards:assets:check: desc: "Apply and check coding standards for assets" cmds: - task: coding-standards:assets:apply - - docker pull jauderho/prettier - docker run --rm --volume "$PWD:/work" jauderho/prettier --check playwright coding-standards:markdown:apply: desc: "Apply coding standards for Markdown" cmds: - - docker pull peterdavehello/markdownlint - docker run --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint --ignore '**/node_modules/**' --ignore '**/vendor/**' '*.md' 'web/*/custom/**/*.md' 'documentation/*.md' --fix - silent: true coding-standards:markdown:check: desc: "Apply and check coding standards for Markdown" cmds: - task: coding-standards:markdown:apply - docker run --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint --ignore '**/node_modules/**' --ignore '**/vendor/**' '*.md' 'web/*/custom/**/*.md' 'documentation/*.md' - silent: true coding-standards:php:apply: desc: "Apply coding standards for PHP" cmds: - - task composer -- coding-standards-apply + - task composer -- coding-standards-apply/php silent: true coding-standards:php:check: desc: "Apply and check coding standards for PHP" cmds: - task: coding-standards:php:apply - - task composer -- coding-standards-check + - task composer -- coding-standards-check/php + silent: true + + coding-standards:twig:apply: + desc: "Apply coding standards for Twig" + cmds: + - task composer -- coding-standards-apply/twig + silent: true + + coding-standards:twig:check: + desc: "Apply and check coding standards for Twig" + cmds: + - task: coding-standards:twig:apply + - task composer -- coding-standards-check/twig silent: true code-analysis: cmds: - task composer -- code-analysis + + docker-pull: + desc: "Pull all development docker images" + cmds: + - docker pull jauderho/prettier + - docker pull peterdavehello/markdownlint + - task compose -- pull diff --git a/composer.json b/composer.json index b55731d3..df40a8a6 100755 --- a/composer.json +++ b/composer.json @@ -268,9 +268,15 @@ "@coding-standards-apply/phpcs", "@coding-standards-apply/twig-cs-fixer" ], + "coding-standards-apply/php": [ + "@coding-standards-apply/phpcs" + ], "coding-standards-apply/phpcs": [ "phpcbf --standard=phpcs.xml.dist" ], + "coding-standards-apply/twig": [ + "@coding-standards-apply/twig-cs-fixer" + ], "coding-standards-apply/twig-cs-fixer": [ "twig-cs-fixer lint web/themes/custom/hoeringsportal/templates --fix" ], @@ -278,9 +284,15 @@ "@coding-standards-check/phpcs", "@coding-standards-check/twig-cs-fixer" ], + "coding-standards-check/php": [ + "@coding-standards-check/phpcs" + ], "coding-standards-check/phpcs": [ "phpcs --standard=phpcs.xml.dist" ], + "coding-standards-check/twig": [ + "@coding-standards-check/twig-cs-fixer" + ], "coding-standards-check/twig-cs-fixer": [ "twig-cs-fixer lint web/themes/custom/hoeringsportal/templates" ], diff --git a/docker-compose.yml b/docker-compose.yml index 0dece663..f0a6e6b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,10 @@ services: phpfpm: image: itkdev/php8.3-fpm:latest + # https://docs.docker.com/reference/compose-file/services/#user + # https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/#interpolation-syntax + # (used in .github/workflows/pr.yaml to run service as root) + user: ${COMPOSE_USER:-deploy} networks: - app extra_hosts: