Skip to content

Stacked PR - adds a Moffice model #830

Stacked PR - adds a Moffice model

Stacked PR - adds a Moffice model #830

Workflow file for this run

name: "PHP checks"
on:
pull_request:
push:
branches:
- main
permissions:
contents: read
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, pdo, sqlite
coverage: none # Use 'xdebug' or 'pcov' for code coverage
tools: composer
- name: validate configuration
run: composer validate
- name: composer install packages
run: composer install
- name: Lint
run: make lint-php-ci
- name: phpcs
run: make phpcs-ci
- name: audit dependencies
run: composer audit
test:
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
pull-requests: write
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_twfy
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Needed for SonarCloud analysis
- name: Checkout phplib
uses: actions/checkout@v4
with:
repository: openaustralia/phplib
path: phplib-checkout
ref: main
- name: Switch phplib to PR branch if it exists
run: git fetch origin ${{ github.head_ref || github.ref_name }} && git checkout ${{ github.head_ref || github.ref_name }} || echo "No PR branch found, using main"
working-directory: phplib-checkout
- name: Link phplib as sibling
run: ln -s ${{ github.workspace }}/phplib-checkout ../phplib
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, mysqli
coverage: xdebug
tools: composer
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
- name: Load database schema
run: ./vendor/bin/phinx migrate -c phinx.php
env:
DB_HOST: 127.0.0.1
DB_USER: root
DB_PASSWORD: root
DB_NAME: test_twfy
- name: Run tests with coverage
run: |
set -o pipefail
XDEBUG_MODE=coverage ./vendor/bin/phpunit \
--coverage-text \
--coverage-clover=coverage/clover.xml \
--coverage-html=coverage/html \
--log-junit=coverage/junit.xml | tee phpunit-coverage.out
env:
DB_HOST: 127.0.0.1
DB_USER: root
DB_PASSWORD: root
DB_NAME: test_twfy
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v8.1.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
schema-check:
name: Schema in git matches migrations
runs-on: ubuntu-latest
needs: lint
permissions:
contents: read
pull-requests: write
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_twfy
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Post in-progress schema check comment on PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: schema-drift
only_update: true # edit the existing comment in place; never create a new one
message: |
## ⏳ Schema check running…
Applying Phinx migrations to a fresh database and comparing
against `db/schema.sql`. This comment will update with the
result when the job finishes.
See the [job run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for live progress.
- name: Setup PHP 8.3
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
extensions: mbstring, mysqli
coverage: none
tools: composer
- name: Install dependencies
run: composer install --no-interaction --prefer-dist
- name: Run migrations
run: ./vendor/bin/phinx migrate -c phinx.php
env:
DB_HOST: 127.0.0.1
DB_USER: root
DB_PASSWORD: root
DB_NAME: test_twfy
- name: Dump schema from migrated database
run: |
docker run --rm --network host mysql:8.0 mysqldump \
--host=127.0.0.1 --protocol=TCP \
--user=root --password=root \
--no-data --skip-comments --skip-add-drop-table --skip-set-charset \
--routines --triggers --events --no-tablespaces \
--ignore-table=test_twfy.phinxlog \
test_twfy > /tmp/schema.dumped.sql
- name: Compare against db/schema.sql in git
id: schema_diff
run: |
if diff -u db/schema.sql /tmp/schema.dumped.sql > /tmp/schema.diff; then
echo "matches=true" >> "$GITHUB_OUTPUT"
{
echo "## ✅ Schema matches migrations"
echo
echo "The committed \`db/schema.sql\` matches the schema produced by running all Phinx migrations from scratch."
} > /tmp/schema-drift-comment.md
else
echo "matches=false" >> "$GITHUB_OUTPUT"
{
echo "## ❌ Schema drift detected"
echo
echo "The committed \`db/schema.sql\` does not match the schema produced by running all Phinx migrations from scratch."
echo
echo "Run \`make docker-dump-schema\` locally and commit the updated \`db/schema.sql\`."
echo
echo "<details><summary>Diff (committed vs. migrated)</summary>"
echo
echo '```diff'
# Cap to keep the comment within GitHub's 65k char limit.
head -c 60000 /tmp/schema.diff
if [ "$(wc -c < /tmp/schema.diff)" -gt 60000 ]; then
echo
echo "... (diff truncated)"
fi
echo '```'
echo
echo "</details>"
} > /tmp/schema-drift-comment.md
fi
- name: Post schema check comment on PR
if: github.event_name == 'pull_request'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: schema-drift
recreate: true
path: /tmp/schema-drift-comment.md
- name: Fail if schema drifted
if: steps.schema_diff.outputs.matches == 'false'
run: |
echo "::error::db/schema.sql is out of date with migrations. Run 'make docker-dump-schema' and commit the result."
cat /tmp/schema.diff
exit 1