Skip to content

Update GitHub Actions #19

Update GitHub Actions

Update GitHub Actions #19

Workflow file for this run

name: Run PHPUnit Tests
on:
workflow_dispatch:
pull_request:
push:
branches: [ "main" ]
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
wiki:
name: Update Wiki
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.head_ref || github.ref_name }}
- name: Install dependencies
uses: php-actions/composer@v6
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
with:
php_version: '8.4'
- name: Create Docs Markdown
uses: phpDocumentor/[email protected]
with:
target: 'docs/wiki'
template: 'vendor/saggre/phpdocumentor-markdown/themes/markdown'
- name: Commit submodule changes
run: |
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
cd docs/wiki
git remote set-url origin https://x-access-token:${{ github.token }}@github.com/${{ github.repository }}.wiki.git
git fetch origin
git checkout ${{ github.head_ref || github.ref_name }}
git pull origin ${{ github.head_ref || github.ref_name }} --rebase
git add .
if git diff --cached --quiet; then
echo "No changes to commit in submodule"
exit 0
fi
git commit -m "Update wiki content"
git push origin HEAD:refs/heads/${{ github.head_ref || github.ref_name }}
cd ../..
git submodule update --remote --merge
git add docs/wiki
if git diff --cached --quiet; then
echo "No submodule reference change to commit"
exit 0
fi
git commit -m "Update wiki submodule reference [skip ci]"
git push origin HEAD:refs/heads/${{ github.head_ref || github.ref_name }}
tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.head_ref || github.ref_name }}
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Install dependencies
uses: php-actions/composer@v6
env:
COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ github.token }}"} }'
with:
php_version: '8.4'
- name: Run PHPUnit tests
uses: php-actions/phpunit@v3
env:
XDEBUG_MODE: coverage
with:
php_version: '8.4'
php_extensions: pcov
- name: Ensure minimum code coverage
env:
MINIMUM_COVERAGE: 80
run: |
COVERAGE=$(php -r '
$xml = new SimpleXMLElement(file_get_contents("public/coverage/clover.xml"));
$m = $xml->project->metrics;
$pct = (int) round(((int) $m["coveredstatements"]) * 100 / (int) $m["statements"]);
echo $pct;
')
echo "Coverage: ${COVERAGE}%"
if [ "${COVERAGE}" -lt ${{ env.MINIMUM_COVERAGE }} ]; then
echo "Code coverage below ${{ env.MINIMUM_COVERAGE }}% threshold."
exit 1
fi
- name: Generate API docs
uses: phpDocumentor/[email protected]
with:
target: 'public/'
template: 'default'
- name: Upload artifact
if: github.ref == 'refs/heads/main'
uses: actions/upload-pages-artifact@v3
with:
path: public/
deploy:
name: Deploy API Docs & Coverage to GitHub Pages
if: github.ref == 'refs/heads/main'
needs: tests
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4