Skip to content

Run tests

Run tests #1549

Workflow file for this run

name: Run tests
on:
pull_request_target:
types: [opened, synchronize, labeled]
schedule:
- cron: '0 0 * * *'
jobs:
access_check:
runs-on: ubuntu-latest
name: Access check
steps:
- name: Ensure pull-request is safe to run
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
if (context.eventName === 'schedule') {
return
}
// If the user that pushed the commit is a maintainer, skip the check
const collaborators = await github.rest.repos.listCollaborators({
owner: context.repo.owner,
repo: context.repo.repo
});
if (collaborators.data.some(c => c.login === context.actor)) {
console.log(`User ${context.actor} is allowed to run tests because they are a collaborator.`);
return
}
const issue_number = context.issue.number;
const repository = context.repo.repo;
const owner = context.repo.owner;
const response = await github.rest.issues.listLabelsOnIssue({
owner,
repo: repository,
issue_number
});
const labels = response.data.map(label => label.name);
let hasLabel = labels.includes('safe-to-test')
if (context.payload.action === 'synchronize' && hasLabel) {
hasLabel = false
await github.rest.issues.removeLabel({
owner,
repo: repository,
issue_number,
name: 'safe-to-test'
});
}
if (!hasLabel) {
throw "Action was not authorized. Exiting now."
}
load-matrix:
runs-on: ubuntu-latest
needs: access_check
outputs:
db: ${{ steps.load.outputs.db }}
payload: ${{ steps.load.outputs.payload }}
steps:
- name: Checkout PR code to read matrix.json
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Load matrix
id: load
run: |
echo "db=$(jq -c '.db' matrix.json)" >> $GITHUB_OUTPUT
echo "payload=$(jq -c '.payload' matrix.json)" >> $GITHUB_OUTPUT
php-tests:
runs-on: ubuntu-latest
needs: load-matrix
strategy:
matrix:
db: ${{ fromJson(needs.load-matrix.outputs.db) }}
payload: ${{ fromJson(needs.load-matrix.outputs.payload) }}
name: PHP ${{ matrix.payload.php }} - Laravel ${{ matrix.payload.laravel }} - DB ${{ matrix.db }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.payload.php }}
extensions: mbstring, dom, fileinfo, mysql
coverage: none
- name: Set up MySQL and PostgreSQL
run: |
if [ "${{ matrix.db }}" != "sqlite" ]; then
MYSQL_PORT=3307 POSTGRES_PORT=5432 docker compose up ${{ matrix.db }} -d
fi
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.payload.laravel }}" "orchestra/testbench:${{ matrix.payload.testbench }}" "nunomaduro/collision:${{ matrix.payload.collision }}" --no-interaction --no-update
composer update --prefer-stable --prefer-dist --no-interaction
if [ "${{ matrix.db }}" = "mysql" ]; then
while ! mysqladmin ping --host=127.0.0.1 --user=test --port=3307 --password=test --silent; do
echo "Waiting for MySQL..."
sleep 1
done
else
echo "Not waiting for MySQL."
fi
- name: Execute tests
run: DB_DRIVER=${{ matrix.db }} composer test