Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: run tasks conditionally #3159

Merged
merged 13 commits into from
Jan 31, 2025
61 changes: 33 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,36 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-22.04
outputs:
php: ${{ steps.filter.outputs.php }}
node: ${{ steps.filter.outputs.node }}
steps:
- name: Check changed files
uses: dorny/paths-filter@v3
id: filter
with:
filters: |
php:
- '**/*.php'
- 'composer.json'
- 'composer.lock'
- 'phpstan.neon'
- 'pint.json'
node:
- '**/*.js'
- '**/*.ts'
- '**/*.tsx'
- 'package.json'
- 'pnpm-lock.yaml'
- '*eslint*'
- 'tailwind.config.json'
- 'lang/**/*.json'

php-setup:
needs: changes
if: needs.changes.outputs.php == 'true'
runs-on: ubuntu-22.04
name: PHP Setup
outputs:
Expand Down Expand Up @@ -46,10 +75,10 @@ jobs:
run: composer install --prefer-dist

node-setup:
needs: changes
if: needs.changes.outputs.node == 'true'
runs-on: ubuntu-22.04
name: Node.js Setup
outputs:
cache-key: ${{ steps.cache-key.outputs.value }}
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -65,24 +94,6 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'

- name: Generate cache key
id: cache-key
run: echo "value=${{ runner.os }}-node-${{ hashFiles('**/pnpm-lock.yaml') }}" >> $GITHUB_OUTPUT

- name: Install
if: steps.node-cache.outputs.cache-hit != 'true'
run: pnpm install --frozen-lockfile --prefer-offline

- name: Cache node_modules
id: node-cache
uses: actions/cache@v4
with:
path: |
node_modules
.pnpm-store
key: ${{ steps.cache-key.outputs.value }}

php-checks:
needs: php-setup
Expand Down Expand Up @@ -153,14 +164,8 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Restore node_modules
uses: actions/cache@v4
with:
path: |
node_modules
.pnpm-store
key: ${{ needs.node-setup.outputs.cache-key }}
- name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline
- name: Run ${{ matrix.check }}
run: ${{ matrix.command }}
env: ${{ matrix.env || fromJSON('{}') }}