Skip to content

Coding Standards

Coding Standards #212

name: Coding Standards
# Disable permissions for all available scopes by default.
# Any needed permissions should be configured at the job level.
permissions: {}
on:
push:
branches:
- main
paths:
# Any change to a PHP file should run checks.
- '**.php'
# These files configure Composer. Changes could affect the outcome.
- 'composer.*'
# This file configures PHPCS. Changes could affect the outcome.
- 'phpcs.xml.dist'
# Changes to workflow files should always verify all workflows are successful.
- '.github/workflows/*.yml'
pull_request:
branches:
- main
paths:
# Any change to a PHP file should run checks.
- '**.php'
# These files configure Composer. Changes could affect the outcome.
- 'composer.*'
# This file configures PHPCS. Changes could affect the outcome.
- 'phpcs.xml.dist'
# Changes to workflow files should always verify all workflows are successful.
- '.github/workflows/*.yml'
schedule:
- cron: '45 3 * * SUN'
workflow_dispatch:
# Cancels all previous workflow runs for pull requests that have not completed.
concurrency:
# The concurrency group contains the workflow name and the branch name for pull requests
# or the commit hash for any other events.
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
# Runs PHP coding standards checks.
#
# Violations are reported inline with annotations.
#
# Performs the following steps:
# - Sets up PHP.
# - Checks out the repository.
# - Installs Composer dependencies.
# - Makes Composer packages available globally.
# - Runs PHPCS on the full code base without warnings suppressed.
# - Generates a report for displaying issues as PR/commit annotations.
# - Ensures version-controlled files are not modified or deleted.
phpcs:
name: PHP coding standards
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Set up PHP
uses: shivammathur/setup-php@c665c7a15b5295c2488ac8a87af9cb806cd72198 # v2.30.4
with:
php-version: 'latest'
coverage: none
tools: cs2pr
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout TablePress repository
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Install Composer dependencies
uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
- name: Make Composer packages available globally
run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH
- name: Check PHP coding standards
id: phpcs
run: phpcs --report-full --report-checkstyle=./phpcs-report.xml
- name: Show PHPCS results in PR/commit
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml
- name: Ensure version-controlled files are not modified during the tests
run: git diff --exit-code
failed-workflow:
name: Failed workflow tasks
runs-on: ubuntu-latest
permissions:
actions: write
needs: [ phpcs ]
if: |
always() &&
github.event_name != 'pull_request' &&
github.run_attempt < 2 &&
(
needs.phpcs.result == 'cancelled' || needs.phpcs.result == 'failure'
)
steps:
- name: Dispatch workflow run
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'failed-workflow.yml',
ref: 'main',
inputs: {
run_id: '${{ github.run_id }}'
}
});