Fix github authentication #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.1' | ||
| - localgov-version: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.2' | ||
| - localgov-version: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.3' | ||
| - localgov-version: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.4' | ||
| - 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: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.1' | ||
| - localgov-version: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.2' | ||
| - localgov-version: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.3' | ||
| - localgov-version: '3.x' | ||
| drupal-version: '~10.0' | ||
| php-version: '8.4' | ||
| - 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 for D10 | ||
| if: matrix.drupal-version == '~10.0' | ||
| 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 /var/www/html/${{inputs.project_path}}" | ||
| - name: Run PHPUnit tests for D11 | ||
| if: matrix.drupal-version == '~11.0' | ||
| 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}}" | ||