From 9d1470d0fb5094af82c8aa8dd7ce6fa4f5abecef Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 14 Nov 2025 05:28:42 +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/reusable-validate.yml | 35 +++++++++++++++++++++++++ .github/workflows/validate-cron.yml | 15 +++++++++++ .github/workflows/validate.yml | 33 +---------------------- 3 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/reusable-validate.yml create mode 100644 .github/workflows/validate-cron.yml diff --git a/.github/workflows/reusable-validate.yml b/.github/workflows/reusable-validate.yml new file mode 100644 index 0000000..d53c05b --- /dev/null +++ b/.github/workflows/reusable-validate.yml @@ -0,0 +1,35 @@ +name: Validate + +on: + workflow_call: + +permissions: {} + +jobs: + validate: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: ['5.4', 'latest'] + + name: PHP ${{ matrix.php }} + + 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: ${{ matrix.php }} + coverage: none + + - name: Install dependencies + run: composer update --no-interaction --no-progress + + - name: Validate Composer installation + run: composer validate --no-check-all --strict diff --git a/.github/workflows/validate-cron.yml b/.github/workflows/validate-cron.yml new file mode 100644 index 0000000..d0a6455 --- /dev/null +++ b/.github/workflows/validate-cron.yml @@ -0,0 +1,15 @@ +name: Validate Cronjob + +on: + # Run the validation workflow on day 15 of every month as the repo isn't that active. + schedule: + - cron: '0 0 15 * *' + +permissions: {} + +jobs: + validate: + # Don't run the cron job on forks. + if: ${{ github.event.repository.fork == false }} + + uses: ./.github/workflows/reusable-validate.yml diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 94dc23a..4316519 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -4,9 +4,6 @@ on: # Run on all pushes and pull requests. push: pull_request: - # Also run this workflow on day 15 of every month as the repo isn't that active. - schedule: - - cron: '0 0 15 * *' # Allow manually triggering the workflow. workflow_dispatch: @@ -14,32 +11,4 @@ permissions: {} jobs: validate: - # Don't run the cron job on forks. - if: ${{ github.event_name != 'schedule' || github.event.repository.fork == false }} - - runs-on: ubuntu-latest - - strategy: - fail-fast: true - matrix: - php: ['5.4', 'latest'] - - name: PHP ${{ matrix.php }} - - 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: ${{ matrix.php }} - coverage: none - - - name: Install dependencies - run: composer update --no-interaction --no-progress - - - name: Validate Composer installation - run: composer validate --no-check-all --strict + uses: ./.github/workflows/reusable-validate.yml