find-and-split
is a GitHub Action that finds and splits files:
- uses: remarkablemark/find-and-split@v1
id: my-files
with:
pattern: '*.txt'
chunk: 1/2
- name: Print files
run: echo ${{ steps.my-files.outputs.files }}
It’s useful for test sharding, or splitting tests that can be run in parallel jobs. For example:
# .github/workflows/test.yml
name: test
on: push
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
shard: [1/2, 1/2]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Find and split files
uses: remarkablemark/find-and-split@v1
id: tests
with:
chunk: ${{ matrix.shard }}
directory: tests
pattern: '*Test.php'
- name: Run tests
run: |
composer install
vendor/bin/phpunit ${{ steps.tests.outputs.files }}
See the documentation and examples.