diff --git a/.github/workflows/test-module.yml b/.github/workflows/test-module.yml index 297a564..93a2d7c 100644 --- a/.github/workflows/test-module.yml +++ b/.github/workflows/test-module.yml @@ -22,6 +22,9 @@ jobs: name: Install LocalGov Drupal runs-on: ubuntu-latest + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + strategy: fail-fast: false matrix: @@ -38,10 +41,10 @@ jobs: - localgov-version: '3.x' drupal-version: '~10.0' php-version: '8.4' - - localgov-version: '3.x' + - localgov-version: '4.x' drupal-version: '~11.0' php-version: '8.3' - - localgov-version: '3.x' + - localgov-version: '4.x' drupal-version: '~11.0' php-version: '8.4' @@ -92,30 +95,17 @@ jobs: repository: localgovdrupal/drupal-container ref: php${{ matrix.php-version }} - # Split project creation to make debugging easier for now - - name: Create LocalGov Drupal 10 project - if: matrix.drupal-version == '~10.0' + - name: Create LocalGov Drupal project run: | composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "${{ matrix.localgov-version }}" composer --working-dir=./html require --no-install localgovdrupal/localgov:${{ matrix.localgov-version }}-dev composer --working-dir=./html require --no-install drupal/core-recommended:${{ matrix.drupal-version }} drupal/core-composer-scaffold:${{ matrix.drupal-version }} drupal/core-project-message:${{ matrix.drupal-version }} drupal/core-dev:${{ matrix.drupal-version }} composer --working-dir=./html install - # Split project creation to make debugging easier for now - - name: Create LocalGov Drupal 11 project - if: matrix.drupal-version == '~11.0' - run: | - composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "3.2.x" - composer require --working-dir=./html --no-install --with-all-dependencies localgovdrupal/localgov:3.2.x-dev - composer require --working-dir=./html --no-install --with-all-dependencies drupal/core-recommended:${{ matrix.drupal-version }} drupal/core-composer-scaffold:${{ matrix.drupal-version }} drupal/core-project-message:${{ matrix.drupal-version }} drupal/core-dev:${{ matrix.drupal-version }} - composer install --working-dir=./html - - name: Obtain the test target using Composer if: env.HEAD_USER == 'localgovdrupal' run: | - composer --working-dir=html config repositories.1 vcs git@github.com:${{inputs.project}}.git - composer global config github-oauth.github.com ${{ github.token }} - composer --working-dir=./html require --with-all-dependencies ${{inputs.project}}:"${COMPOSER_REF} as ${LATEST_RELEASE}" + composer --working-dir=./html require --with-all-dependencies ${{ inputs.project }}:"${COMPOSER_REF} as ${LATEST_RELEASE}" - name: Obtain the test target using Git if: env.HEAD_USER != 'localgovdrupal' @@ -144,9 +134,9 @@ jobs: fail-fast: false matrix: localgov-version: - - '3.x' + - '4.x' drupal-version: - - '~10.0' + - '~11.0' php-version: - '8.4' @@ -181,9 +171,9 @@ jobs: fail-fast: false matrix: localgov-version: - - '3.x' + - '4.x' drupal-version: - - '~10.0' + - '~11.0' php-version: - '8.4' @@ -218,9 +208,9 @@ jobs: fail-fast: false matrix: localgov-version: - - '3.x' + - '4.x' drupal-version: - - '~10.0' + - '~11.0' php-version: - '8.4' @@ -255,7 +245,7 @@ jobs: fail-fast: false matrix: localgov-version: - - '3.x' + - '4.x' drupal-version: - '~11.0' php-version: @@ -291,7 +281,7 @@ jobs: fail-fast: false matrix: localgov-version: - - '3.x' + - '4.x' drupal-version: - '~11.0' php-version: @@ -342,10 +332,10 @@ jobs: - localgov-version: '3.x' drupal-version: '~10.0' php-version: '8.4' - - localgov-version: '3.x' + - localgov-version: '4.x' drupal-version: '~11.0' php-version: '8.3' - - localgov-version: '3.x' + - localgov-version: '4.x' drupal-version: '~11.0' php-version: '8.4' diff --git a/.github/workflows/test-profile-4.x.yml b/.github/workflows/test-profile-4.x.yml new file mode 100644 index 0000000..9fb07ca --- /dev/null +++ b/.github/workflows/test-profile-4.x.yml @@ -0,0 +1,341 @@ +name: Test localgovdrupal drupal-module + +on: + workflow_call: + inputs: + project: + description: 'LocalGov Drupal module name' + required: true + type: string + project_path: + description: 'LocalGov Drupal module path' + required: true + type: string + use_module_phpstan_config: + description: 'Use phpstan.neon from the module under test, instead of the drupal root.' + required: false + default: false + type: boolean + +jobs: + build: + name: Install LocalGov Drupal + runs-on: ubuntu-latest + + env: + COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + strategy: + fail-fast: false + matrix: + include: + - localgov-version: '4.x' + drupal-version: '~11.0' + php-version: '8.3' + - localgov-version: '4.x' + drupal-version: '~11.0' + php-version: '8.4' + + steps: + - name: Save git branch and git repo names to env if this is not a pull request + if: github.event_name != 'pull_request' + run: | + echo "GIT_BASE=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "GIT_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + echo "HEAD_USER=localgovdrupal" >> $GITHUB_ENV + + - name: Save git branch and git repo names to env if this is a pull request + if: github.event_name == 'pull_request' + run: | + echo "GIT_BASE=${GITHUB_BASE_REF}" >> $GITHUB_ENV + echo "GIT_BRANCH=${GITHUB_HEAD_REF}" >> $GITHUB_ENV + export HEAD="${{ github.event.pull_request.head.label }}" + echo "HEAD_USER=${HEAD%%:*}" >> $GITHUB_ENV + + - name: Set composer branch reference for version branches + if: endsWith(github.ref, '.x') || endsWith(env.GIT_BRANCH, '.x') + run: echo "COMPOSER_REF=${GIT_BRANCH}-dev" >> $GITHUB_ENV + + - name: Set composer branch reference for non-version branches + if: endsWith(github.ref, '.x') == false && endsWith(env.GIT_BRANCH, '.x') == false + run: echo "COMPOSER_REF=dev-${GIT_BRANCH}" >> $GITHUB_ENV + + - name: Get the latest tagged release for branch version + run: | + LATEST_RELEASE=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${GIT_BASE%%.*} | grep -Po '(?<=refs/tags/)[^"]+' | tail -1) + if [ -z $LATEST_RELEASE ]; then LATEST_RELEASE=1; fi + echo "LATEST_RELEASE=${LATEST_RELEASE}" >> $GITHUB_ENV + + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Clone drupal_container + uses: actions/checkout@v4 + with: + repository: localgovdrupal/drupal-container + ref: php${{ matrix.php-version }} + + - name: Create LocalGov Drupal project + run: | + composer create-project --stability dev --no-install localgovdrupal/localgov-project ./html "${{ matrix.localgov-version }}" + composer --working-dir=./html require --no-install localgovdrupal/localgov:${{ matrix.localgov-version }}-dev + composer --working-dir=./html require --no-install drupal/core-recommended:${{ matrix.drupal-version }} drupal/core-composer-scaffold:${{ matrix.drupal-version }} drupal/core-project-message:${{ matrix.drupal-version }} drupal/core-dev:${{ matrix.drupal-version }} + composer --working-dir=./html install + + - name: Obtain the test target using Composer + if: env.HEAD_USER == 'localgovdrupal' + run: | + composer --working-dir=./html require --with-all-dependencies ${{ inputs.project }}:"${COMPOSER_REF} as ${LATEST_RELEASE}" + + - name: Obtain the test target using Git + if: env.HEAD_USER != 'localgovdrupal' + uses: actions/checkout@v4 + with: + path: ${{inputs.project_path}} + + # Allow continue on error as breaks D11 installs because suggest doesn't have a version + # so it falls back to stable versions, which do not have D11 releases so fails + - name: Obtain suggested dependencies + continue-on-error: true + run: composer --working-dir=./html/${{inputs.project_path}} suggests --list | xargs composer --working-dir=./html require + + - name: Obtain dev dependencies + if: hashFiles('./html/${{inputs.project_path}}/composer.json') != '' + run: | + composer --working-dir=./html require 'drupal/facets:^2.0' + jq --raw-output '.["require-dev"] | values | to_entries[] | @sh "\(.key):\(.value)"' ./html/${{inputs.project_path}}/composer.json | xargs composer --working-dir=./html require + + eslint_js: + name: ESLint javascript checks + needs: build + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + localgov-version: + - '4.x' + drupal-version: + - '~11.0' + php-version: + - '8.4' + + steps: + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + restore-keys: | + localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}- + + - name: Install packages + if: ${{ hashFiles(format('./html/{0}/**/*.js', inputs.project_path)) != '' }} + run: | + cd html/web/core + npm i + + - name: Run coding standards checks + if: ${{ hashFiles(format('./html/{0}/**/*.js', inputs.project_path)) != '' }} + run: | + cd html/web/core + cp -f .prettierrc.json ../.prettierrc.json + node ./node_modules/eslint/bin/eslint.js --ext .js --resolve-plugins-relative-to=./web/core ../../${{inputs.project_path}} + + eslint_yaml: + name: ESLint yaml checks + needs: build + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + localgov-version: + - '4.x' + drupal-version: + - '~11.0' + php-version: + - '8.4' + + steps: + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + restore-keys: | + localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}- + + - name: Install packages + if: ${{ hashFiles(format('./html/{0}/**/*.yml', inputs.project_path)) != '' }} + run: | + cd html/web/core + npm i + + - name: Run coding standards checks + if: ${{ hashFiles(format('./html/{0}/**/*.yml', inputs.project_path)) != '' }} + run: | + cd html/web/core + cp -f .prettierrc.json ../.prettierrc.json + node ./node_modules/eslint/bin/eslint.js --ext .yml --resolve-plugins-relative-to=./web/core ../../${{inputs.project_path}} + + stylelint: + name: Stylelint checks + needs: build + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + localgov-version: + - '4.x' + drupal-version: + - '~11.0' + php-version: + - '8.4' + + steps: + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + restore-keys: | + localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}- + + - name: Install packages + if: ${{ hashFiles(format('./html/{0}/**/*.css', inputs.project_path)) != '' }} + run: | + cd html/web/core + npm i + + - name: Run coding standards checks + if: ${{ hashFiles(format('./html/{0}/**/*.css', inputs.project_path)) != '' }} + run: | + cd html/web/core + cp -f .prettierrc.json ../.prettierrc.json + node ./node_modules/.bin/stylelint --ignore-path .stylelintignore --config .stylelintrc.json "../../${{inputs.project_path}}/**/*.css" + + phpcs: + name: PHP coding standards checks + needs: build + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + localgov-version: + - '4.x' + drupal-version: + - '~11.0' + php-version: + - '8.4' + + steps: + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + restore-keys: | + localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Run coding standards checks + run: | + cd html + ./bin/phpcs -p ${{inputs.project_path}} + + phpstan: + name: PHP static analysis checks + needs: build + runs-on: ubuntu-latest + env: + PHPSTAN_NEON_PATH: "./phpstan.neon" + + strategy: + fail-fast: false + matrix: + localgov-version: + - '4.x' + drupal-version: + - '~11.0' + php-version: + - '8.4' + + steps: + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + restore-keys: | + localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}- + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + + - name: Override phpstan.neon path if requested + if: ${{inputs.use_module_phpstan_config}} + run: echo "PHPSTAN_NEON_PATH=\"${{inputs.project_path}}/phpstan.neon\"" >> $GITHUB_ENV + + - name: Run static analysis checks + if: ${{ hashFiles(format('./html/{0}/**/*.inc', inputs.project_path), format('./html/{0}/**/*.install', inputs.project_path), format('./html/{0}/**/*.module', inputs.project_path), format('./html/{0}/**/*.php', inputs.project_path), format('./html/{0}/**/*.profile', inputs.project_path), format('./html/{0}/**/*.test', inputs.project_path), format('./html/{0}/**/*.theme', inputs.project_path)) != '' }} + run: | + cd html + ./bin/phpstan analyse -c ${{ env.PHPSTAN_NEON_PATH }} ${{inputs.project_path}} + + phpunit: + name: PHPUnit tests + needs: [build,phpcs,phpstan] + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - localgov-version: '4.x' + drupal-version: '~11.0' + php-version: '8.3' + - localgov-version: '4.x' + drupal-version: '~11.0' + php-version: '8.4' + + steps: + - name: Clone Drupal container + uses: actions/checkout@v4 + with: + repository: localgovdrupal/drupal-container + ref: php${{ matrix.php-version }} + + - name: Cached workspace + uses: actions/cache@v4 + with: + path: ./html + key: localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}-${{ github.run_id }}-${{ secrets.CACHE_VERSION }} + restore-keys: | + localgov-build-${{ matrix.localgov-version }}-${{ matrix.drupal-version }}-${{ matrix.php-version }}- + + - name: Start Docker environment + run: docker compose -f docker-compose.yml up -d + + - name: Run PHPUnit tests + run: | + mkdir -p ./html/web/sites/simpletest && chmod 777 ./html/web/sites/simpletest + sed -i "s#http://localgov.lndo.site#http://drupal#" ./html/phpunit.xml.dist + docker exec -t drupal bash -c 'chown docker:docker -R /var/www/html' + docker exec -u docker -t drupal bash -c "cd /var/www/html && ./bin/phpunit -c ./phpunit.d11.xml.dist /var/www/html/${{inputs.project_path}}"