diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml deleted file mode 100644 index c57adda..0000000 --- a/.github/workflows/pr.yml +++ /dev/null @@ -1,167 +0,0 @@ -on: pull_request -name: Review - -jobs: - changelog: - runs-on: ubuntu-latest - name: Changelog should be updated - strategy: - matrix: - php-versions: [ '8.3' ] - fail-fast: false - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: Git fetch - run: git fetch - - - name: Check that changelog has been updated. - run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0 - - - markdown-coding-standards: - name: Markdown coding standards - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Coding standards - run: | - docker run --rm --volume "$PWD:/md" itkdev/markdownlint $(git ls-files *.md) - - composer-normalize: - name: composer-normalize - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: [ '8.3' ] - fail-fast: false - steps: - - uses: actions/checkout@v4 - - run: | - docker network create frontend - docker compose run --user root --rm phpfpm composer install - docker compose run --user root --rm phpfpm composer normalize - - coding-standards-phpcs: - name: coding-standards-check/phpcs - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: [ '8.3' ] - fail-fast: false - steps: - - uses: actions/checkout@v4 - - run: | - docker network create frontend - docker compose run --user root --rm phpfpm composer install - docker compose run --user root --rm phpfpm composer coding-standards-check/phpcs - - coding-standards-twig-cs-fixer: - name: coding-standards-check/twig-cs-fixer - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: [ '8.3' ] - fail-fast: false - steps: - - uses: actions/checkout@v4 - - run: | - docker network create frontend - docker compose run --user root --rm phpfpm composer install - docker compose run --user root --rm phpfpm composer coding-standards-check/twig-cs-fixer - - install-site: - name: Check that site can be installed - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: setup-docker-and-composer - run: | - docker network create frontend - docker compose pull - docker compose up --detach - - # Important: Use --no-interaction to make https://getcomposer.org/doc/06-config.md#discard-changes have effect. - docker compose exec --user root phpfpm composer install --no-interaction - - - name: Install site - if: ${{ (hashFiles('config/sync/core.extension.yml') == '') && (hashFiles('web/sites/default/settings.local.php') != '') }} - run: | - # Install the site - docker compose exec --user root phpfpm vendor/bin/drush site:install minimal - - - name: Install site from config - if: ${{ hashFiles('config/sync/core.extension.yml') != '' }} - run: | - # Install the site from config - docker compose exec --user root phpfpm vendor/bin/drush site:install --existing-config --yes - - - name: Open site - run: | - echo $(docker compose exec phpfpm vendor/bin/drush --uri=http://$(docker compose port nginx 8080) user:login) - - config-check: - name: Check that config is up to date - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Install site - if: ${{ (hashFiles('config/sync/core.extension.yml') != '') && (hashFiles('web/sites/default/settings.local.php') != '') }} - run: | - docker network create frontend - docker compose pull - docker compose up --detach - - # Important: Use --no-interaction to make https://getcomposer.org/doc/06-config.md#discard-changes have effect. - docker compose exec --user root phpfpm composer install --no-interaction - - # Install the site - docker compose exec --user root phpfpm vendor/bin/drush site:install --existing-config --yes - - - name: Export config - if: ${{ (hashFiles('config/sync/core.extension.yml') != '') && (hashFiles('web/sites/default/settings.local.php') != '') }} - run: docker compose exec --user root phpfpm vendor/bin/drush config:export --yes - - name: Check for changes in config - if: ${{ (hashFiles('config/sync/core.extension.yml') != '') && (hashFiles('web/sites/default/settings.local.php') != '') }} - run: git diff --diff-filter=ACMRT --exit-code config/ - - code-analysis: - name: PHP - Code analysis - runs-on: ubuntu-latest - strategy: - matrix: - php-versions: [ '8.3' ] - dependency-version: [ prefer-lowest, prefer-stable ] - steps: - - uses: actions/checkout@master - - name: Setup PHP, with composer and extensions - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-versions }} - 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 - - name: code-analysis - run: | - composer code-analysis diff --git a/.github/workflows/template_test.yml b/.github/workflows/template_test.yml index dcaff9e..b3e90d8 100644 --- a/.github/workflows/template_test.yml +++ b/.github/workflows/template_test.yml @@ -7,19 +7,17 @@ on: pull_request: jobs: - test-prune-project: + changelog: runs-on: ubuntu-latest - name: Test prune project - env: - PROJECT_NAME: my-test-project + name: Changelog should be updated steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 2 - # https://taskfile.dev/installation/#github-actions - - name: Setup Task - uses: arduino/setup-task@v2 + - name: Git fetch + run: git fetch - - name: Prune project - run: | - task template-prune PROJECTNAME=$PROJECT_NAME + - name: Check that changelog has been updated. + run: git diff --exit-code origin/${{ github.base_ref }} -- CHANGELOG.md && exit 1 || exit 0 \ No newline at end of file diff --git a/.markdownlint.jsonc b/.markdownlint.jsonc deleted file mode 100644 index 86516e7..0000000 --- a/.markdownlint.jsonc +++ /dev/null @@ -1,18 +0,0 @@ -{ - "default": true, - // https://github.com/DavidAnson/markdownlint/blob/main/doc/md013.md - "line-length": { - "line_length": 120, - "code_blocks": false, - "tables": false - }, - // https://github.com/DavidAnson/markdownlint/blob/main/doc/md024.md - "no-duplicate-heading": { - "siblings_only": true - }, - // https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/organizing-information-with-collapsed-sections#creating-a-collapsed-section - // https://github.com/DavidAnson/markdownlint/blob/main/doc/md033.md - "no-inline-html": { - "allowed_elements": ["details", "summary"] - } -} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..2ec5195 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +config/ \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 1644ac6..67c96e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,19 @@ and this project adheres to [Semantic Versioning]. ## [Unreleased] -* [PR-7](https://github.com/itk-dev/drupal-11-template/pull/7) - Miscellaneous +## [1.0.0] ### Added * Template files added +### Changed + +* [PR-9](https://github.com/itk-dev/drupal-11-template/pull/9) + - Fixed github actions. +* [PR-7](https://github.com/itk-dev/drupal-11-template/pull/7) + - Miscellaneous + [Keep a Changelog]: https://keepachangelog.com/en/1.1.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html [Unreleased]: https://github.com/itk-dev/drupal-11-template/compare/main...develop diff --git a/README.md b/README.md index 42a634a..86cb6c8 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,6 @@ Build a new project using this template (replace `{REPO_NAME}` with a proper Git gh repo create itk-dev/{REPO_NAME} --template itk-dev/drupal-11-template --public --clone ``` -Install the newest docker compose setup from [https://github.com/itk-dev/devops_itkdev-docker](https://github.com/itk-dev/devops_itkdev-docker). - -```shell -task docker:install -``` - ### Prune the project Prune the project to remove/override template specific files and set up the diff --git a/Taskfile.yml b/Taskfile.yml index b44ceb4..38cc010 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,37 +1,33 @@ version: '3' -dotenv: [".task.env", ".env"] +dotenv: [".env.task", ".env"] tasks: template-prune: - name: Prune installation desc: Update the repository's files to match current project name cmds: - - | - cat <<'EOF' > .env - COMPOSE_PROJECT_NAME={{.PROJECTNAME}} - COMPOSE_DOMAIN={{.PROJECTNAME}}.local.itkdev.dk - EOF - - rm -R web/themes/custom/TEMPLATE_THEME - - | - cat <<'EOF' >> deploy-templates/settings.local.php - - /** - * Set trusted host pattern. - */ - $settings['trusted_host_patterns'][] = '^{{.PROJECTNAME}}\.local\.itkdev\.dk$'; - EOF + # Modify contents of settings.local.yml and create .env file. + - PROJECTNAME={{.PROJECTNAME}} ./deploy-templates/scripts/modifyFilesContent.sh + + # Add docker setup + - task docker:install + # Move Drupal configuration files into place. - mkdir -p web/sites/default - mv deploy-templates/{settings.local.php,services.local.yml} web/sites/default/ + + # Set the actual project name in select files (Sed command different between mac and linux). + - task rename + + # Remove build scripts + - rm -Rf deploy-templates/scripts + # Move the rest of the files "here" - mv deploy-templates/* . - # Set the actual project name in select files. - - sed -i '' -e 's/{PROJECTNAME}/{{.PROJECTNAME}}/g' README.md CHANGELOG.md + # Remove deploy templates - rmdir deploy-templates # Remove workflows that make sense only in the template project - rm .github/workflows/template_*.yml - requires: vars: - PROJECTNAME @@ -41,7 +37,12 @@ tasks: msg: "PROJECTNAME should only contain lowercase a-z, digits and hyphens" docker:install: - name: Install ITKDev docker compose desc: Install docker compose templates (to get the newest version) cmds: - - itkdev-docker-compose template:install drupal-10 --force + - itkdev-docker-compose template:install drupal-11 --force + + rename: + desc: Sed command fails in github actions, so we require darwin platform to avoid. @todo better approach. + cmds: + - docker run --rm --volume=$PWD:/app itkdev/php8.3-fpm:latest sed -i -e 's/{PROJECTNAME}/{{.PROJECTNAME}}/g' README.md CHANGELOG.md + platforms: ['darwin'] diff --git a/composer.json b/composer.json index 6fe6071..f2562cf 100644 --- a/composer.json +++ b/composer.json @@ -15,14 +15,19 @@ } ], "require": { + "php": "^8.3", + "chx/drupal-issue-fork": "^1.0", "composer/installers": "^2.0", - "drupal/core-composer-scaffold": "^11.0", - "drupal/core-project-message": "^11.0", - "drupal/core-recommended": "^11.0", + "cweagans/composer-patches": "^1.7", + "drupal/core-composer-scaffold": "^11.2", + "drupal/core-project-message": "^11.2", + "drupal/core-recommended": "^11.2", + "drupal/hook_event_dispatcher": "^4.2", + "itk-dev/itkdev_base_theme": "^1.0", "drush/drush": "^13.2" }, "require-dev": { - "drupal/core-dev": "^11.0", + "drupal/core-dev": "^11.2", "ergebnis/composer-normalize": "^2.43", "vincentlanglet/twig-cs-fixer": "^3.0", "mglaman/phpstan-drupal": "^1.1", @@ -30,13 +35,16 @@ "phpstan/phpstan-deprecation-rules": "^1.1" }, "conflict": { - "drupal/drupal": "*" + "drupal/drupal": "*", + "dealerdirect/phpcodesniffer-composer-installer": "1.1.0" }, - "minimum-stability": "stable", + "minimum-stability": "dev", "prefer-stable": true, "config": { "allow-plugins": { + "chx/drupal-issue-fork": true, "composer/installers": true, + "cweagans/composer-patches": true, "drupal/core-composer-scaffold": true, "drupal/core-project-message": true, "phpstan/extension-installer": true, @@ -82,6 +90,11 @@ "type:drupal-custom-theme" ] }, + "patches": { + "drupal/core": { + "Add an Autowire trait for plugins (https://www.drupal.org/project/drupal/issues/3294266)": "https://www.drupal.org/files/issues/2023-08-18/3294266-24.patch" + } + }, "drupal-core-project-message": { "include-keys": [ "homepage", @@ -103,33 +116,5 @@ " composer remove drupal/core-project-message" ] } - }, - "scripts": { - "coding-standards-apply": [ - "@coding-standards-apply/phpcs", - "@coding-standards-apply/twig-cs-fixer" - ], - "coding-standards-apply/phpcs": [ - "phpcbf --standard=phpcs.xml.dist" - ], - "coding-standards-apply/twig-cs-fixer": [ - "twig-cs-fixer lint web/themes/custom/*/templates --fix" - ], - "coding-standards-check": [ - "@coding-standards-check/phpcs", - "@coding-standards-check/twig-cs-fixer" - ], - "coding-standards-check/phpcs": [ - "phpcs --standard=phpcs.xml.dist" - ], - "coding-standards-check/twig-cs-fixer": [ - "twig-cs-fixer lint web/themes/custom/*/templates" - ], - "code-analysis/phpstan": [ - "phpstan analyse --configuration=phpstan.neon" - ], - "code-analysis": [ - "@code-analysis/phpstan" - ] } } diff --git a/deploy-templates/README.md b/deploy-templates/README.md index 4292285..e0d6ad9 100644 --- a/deploy-templates/README.md +++ b/deploy-templates/README.md @@ -1,10 +1,10 @@ # Readme for {PROJECTNAME} -Create/edit `.task.env` and set a custom [`docker compose`](https://docs.docker.com/compose/) command if needed, e.g. +Create/edit `.env.task` and set a custom [`docker compose`](https://docs.docker.com/compose/) command if needed, e.g. ``` shell # .env.task -TASK_DOCKER_COMPOSE="docker compose --env-file .env.docker.local --file=docker-compose.server.yml --file=docker-compose.server.override.yml" +TASK_DOCKER_COMPOSE=itkdev-docker-compose ``` ## Build assets @@ -56,40 +56,21 @@ open "http://$(docker compose port nginx 8080)" Export config created from drupal: ```shell -itkdev-docker-compose drush config:export +task drush -- config:export ``` Import config from config files: ```shell -itkdev-docker-compose drush config:import +task drush -- config:import ``` ### Coding standards -```shell name=coding-standards-composer -task compose -- exec phpfpm composer install -task compose -- exec phpfpm composer normalize +```shell name=coding-standards-check +task code:check ``` -```shell name=coding-standards-php -docker compose exec phpfpm composer install -docker compose exec phpfpm composer coding-standards-apply/phpcs -docker compose exec phpfpm composer coding-standards-check/phpcs -``` - -```shell name=coding-standards-twig -docker compose exec phpfpm composer install -docker compose exec phpfpm composer coding-standards-apply/twig-cs-fixer -docker compose exec phpfpm composer coding-standards-check/twig-cs-fixer -``` - -```shell name=code-analysis -docker compose exec phpfpm composer install -docker compose exec phpfpm composer code-analysis -``` - -```shell name=coding-standards-markdown -docker run --platform linux/amd64 --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint $(git ls-files *.md) --fix -docker run --platform linux/amd64 --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint $(git ls-files *.md) -``` +```shell name=coding-standards-apply +task code:apply-standards +``` \ No newline at end of file diff --git a/deploy-templates/Taskfile.yml b/deploy-templates/Taskfile.yml index af332b0..7bed2e0 100644 --- a/deploy-templates/Taskfile.yml +++ b/deploy-templates/Taskfile.yml @@ -1,43 +1,69 @@ version: '3' -dotenv: [".task.env", ".env"] +dotenv: [".env.task", ".env"] vars: DOCKER_COMPOSE: '{{ .TASK_DOCKER_COMPOSE | default "docker compose" }}' tasks: compose: + desc: Run docker compose or itkdev-docker-compose if TASK_DOCKER_COMPOSE is set in .env.task cmds: - '{{ .DOCKER_COMPOSE }} {{ .CLI_ARGS }}' silent: true composer: + desc: Run composer through phpfpm container cmds: - task compose -- exec phpfpm composer {{ .CLI_ARGS }} silent: true drush: + desc: Run drush through phpfpm container cmds: - task compose -- exec --no-TTY phpfpm vendor/bin/drush {{ .CLI_ARGS }} silent: true build-site:new: + desc: Build a new site with a custom theme cmds: - - task drush -- site:install minimal -y + - task compose -- up --detach + - task composer -- install + - task drush -- site:install minimal -y + - task compose -- run phpfpm php /app/web/core/scripts/drupal generate-theme {{.THEMENAME}} --name="{{.THEMENAME_READABLE}}" --path="themes/custom" --starterkit=starterkit_project_theme + requires: + vars: + - THEMENAME + - THEMENAME_READABLE + + preconditions: + - sh: "[[ {{.THEMENAME}} =~ ^[a-z\\_]+$ ]]" + msg: "THEMENAME should only contain lowercase a-z and underscores" build-site:existing-conf: + desc: Build a new site from existing site configuration cmds: - task compose -- up --detach - task composer -- install - task drush -- site-install --existing-config --yes - simulate-github-actions: + code:check: + desc: Check php, twig and markdown files and analyze php code cmds: - - task composer -- normalize - - task check-code + - task compose -- exec phpfpm vendor/bin/phpcs --standard=phpcs.xml.dist + - task compose -- exec phpfpm vendor/bin/phpstan analyse --configuration=phpstan.neon + - task compose -- exec phpfpm vendor/bin/twig-cs-fixer lint web/themes/custom/*/templates + - docker compose run --rm prettier '**/*.{yml,yaml}' --check + - docker compose run --rm prettier 'web/themes/custom/**/js/**/*.js' --check + - docker compose run --rm prettier 'web/themes/custom/**/css/**/*.{css,scss}' --check + - docker run --rm --volume "$PWD:/md" itkdev/markdownlint '**/*.md' - check-code: + code:apply-standards: + desc: Apply coding standards to php, twig and markdown files cmds: - - docker run --rm --volume "$PWD:/md" peterdavehello/markdownlint markdownlint $(git ls-files *.md) - - task composer -- code-analysis - - task composer -- coding-standards-check/twig-cs-fixer + - task compose -- exec phpfpm vendor/bin/phpcbf --standard=phpcs.xml.dist + - task compose -- exec phpfpm vendor/bin/twig-cs-fixer lint web/themes/custom/*/templates --fix + - docker compose run --rm prettier '**/*.{yml,yaml}' --write + - docker compose run --rm prettier 'web/themes/custom/**/js/**/*.js' --write + - docker compose run --rm prettier 'web/themes/custom/**/css/**/*.{css,scss}' --write + - docker run --rm --volume "$PWD:/md" itkdev/markdownlint '**/*.md' --fix diff --git a/deploy-templates/scripts/modifyFilesContent.sh b/deploy-templates/scripts/modifyFilesContent.sh new file mode 100755 index 0000000..72699fd --- /dev/null +++ b/deploy-templates/scripts/modifyFilesContent.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +file="./deploy-templates/settings.local.php" +echo "" >> $file +echo "/**" >> $file +echo " * Set trusted host pattern." >> $file +echo " */" >> $file +echo "\$settings['trusted_host_patterns'][] = '^$PROJECTNAME\.local\.itkdev\.dk$';" >> $file +cat $file diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 6baffeb..8fb7123 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -1,4 +1,13 @@ services: + node: + image: node:20 + profiles: + # Used only to build assets + - dev + working_dir: /app + volumes: + - .:/app + phpfpm: environment: - PHP_MAX_EXECUTION_TIME=60 diff --git a/recipes/.gitignore b/recipes/.gitignore new file mode 100644 index 0000000..739a339 --- /dev/null +++ b/recipes/.gitignore @@ -0,0 +1 @@ +/README.txt \ No newline at end of file diff --git a/web/themes/custom/TEMPLATE_THEME/templates/.gitkeep b/web/themes/custom/TEMPLATE_THEME/templates/.gitkeep deleted file mode 100644 index e69de29..0000000