From 59a9bd712fbaac064b413da9d6d48e15b982fb59 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 14 Nov 2025 07:12:54 +0100 Subject: [PATCH] GH Actions: split workflow GitHub has the annoying habit of disabling workflows with a cron job after two months if the repo doesn't see any activity. This is regularly the case for this repo and this creates the following problem: * If the same workflow is used for both the cron job as well as the push/pull_request CI checks... * ... and a repo doesn't have any activity in two months time... * ... the workflow gets disabled... * ... which then also means that CI checks will no longer be run for new PRs.... * ... which means new PRs can't be merged as (in most cases) the repo has branch protection in place and requires that the CI checks pass before a PR can be merged. This commit basically changes the original workflow to a reusable workflow and then creates two new workflows, with different `on` targets, which each trigger the reusable workflow. * One workflow will be triggered via `cron`. * One workflow will have all the other triggers (`push`/`pull_request`/`workflow_dispatch`). This way, if the cron job workflow gets disabled, the workflow which is used for the other triggers will continue to function. The downside of this, is that it may go unnoticed that the cron job has stopped running, but so be it. --- .github/workflows/ci-cron.yml | 15 ++++++++ .github/workflows/ci.yml | 49 ++---------------------- .github/workflows/reusable-qa-checks.yml | 47 +++++++++++++++++++++++ 3 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/ci-cron.yml create mode 100644 .github/workflows/reusable-qa-checks.yml diff --git a/.github/workflows/ci-cron.yml b/.github/workflows/ci-cron.yml new file mode 100644 index 0000000..e387097 --- /dev/null +++ b/.github/workflows/ci-cron.yml @@ -0,0 +1,15 @@ +name: CI Cronjob + +on: + # Run this workflow on day 10 of every month as the repo isn't that active. + schedule: + - cron: '0 0 10 * *' + +permissions: {} + +jobs: + QA: + # Don't run the cron job on forks. + if: ${{ github.event.repository.fork == false }} + + uses: ./.github/workflows/reusable-qa-checks.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89f994d..0dd0bc0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,57 +1,14 @@ name: CI on: - # Run on all pushes and pull requests. + # Run on pushes to `main` and on all pull requests. push: branches: - main pull_request: - # Also run this workflow on day 10 of every month as the repo isn't that active. - schedule: - - cron: '0 0 10 * *' # Allow manually triggering the workflow. workflow_dispatch: jobs: - xmllint: - # Don't run the cron job on forks. - if: ${{ github.event_name != 'schedule' || github.event.repository.fork == false }} - - name: 'Check install and XML' - runs-on: ubuntu-latest - - env: - XMLLINT_INDENT: ' ' - - steps: - - name: Checkout code - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - with: - persist-credentials: false - - - name: Install PHP - uses: shivammathur/setup-php@bf6b4fbd49ca58e4608c9c89fba0b8d90bd2a39f # 2.35.5 - with: - php-version: 'latest' - coverage: none - - # Install dependencies to make sure the PHPCS XSD file is available. - - name: Install dependencies - run: composer install --prefer-dist --no-interaction --no-progress - - # Validate the composer.json file. - # @link https://getcomposer.org/doc/03-cli.md#validate - - name: Validate Composer installation - run: composer validate --no-check-all --strict - - # Validate the xml file. - - name: Validate against schema - uses: phpcsstandards/xmllint-validate@0fd9c4a9046055f621fca4bbdccb8eab1fd59fdc # v1.0.1 - with: - pattern: "PHPCSDev/ruleset.xml" - xsd-file: "vendor/squizlabs/php_codesniffer/phpcs.xsd" - - # Check the code-style consistency of the xml file. - # Note: this needs xmllint, but that will be installed via the phpcsstandards/xmllint-validate action runner. - - name: Check code style - run: diff -B ./PHPCSDev/ruleset.xml <(xmllint --format "./PHPCSDev/ruleset.xml") + QA: + uses: ./.github/workflows/reusable-qa-checks.yml diff --git a/.github/workflows/reusable-qa-checks.yml b/.github/workflows/reusable-qa-checks.yml new file mode 100644 index 0000000..61a8bb5 --- /dev/null +++ b/.github/workflows/reusable-qa-checks.yml @@ -0,0 +1,47 @@ +name: CI + +on: + workflow_call: + +permissions: {} + +jobs: + xmllint: + name: 'Check install and XML' + runs-on: ubuntu-latest + + env: + XMLLINT_INDENT: ' ' + + steps: + - name: Checkout code + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + + - name: Install PHP + uses: shivammathur/setup-php@bf6b4fbd49ca58e4608c9c89fba0b8d90bd2a39f # 2.35.5 + with: + php-version: 'latest' + coverage: none + + # Install dependencies to make sure the PHPCS XSD file is available. + - name: Install dependencies + run: composer install --prefer-dist --no-interaction --no-progress + + # Validate the composer.json file. + # @link https://getcomposer.org/doc/03-cli.md#validate + - name: Validate Composer installation + run: composer validate --no-check-all --strict + + # Validate the xml file. + - name: Validate against schema + uses: phpcsstandards/xmllint-validate@0fd9c4a9046055f621fca4bbdccb8eab1fd59fdc # v1.0.1 + with: + pattern: "PHPCSDev/ruleset.xml" + xsd-file: "vendor/squizlabs/php_codesniffer/phpcs.xsd" + + # Check the code-style consistency of the xml file. + # Note: this needs xmllint, but that will be installed via the phpcsstandards/xmllint-validate action runner. + - name: Check code style + run: diff -B ./PHPCSDev/ruleset.xml <(xmllint --format "./PHPCSDev/ruleset.xml")