Make WordPress Core


Ignore:
Timestamp:
05/17/2024 05:41:40 PM (5 months ago)
Author:
desrosj
Message:

Build/Test Tools: Convert GitHub action workflows into reusable ones.

With a few exceptions, GitHub Actions workflows run using the version of the workflow file present in the commit SHA or Git ref for the triggering event. This is useful for maintaining different versions of a workflow file.

In the case of WordPress where there are currently 25+ branches that could potentially receive a security fix, it creates a huge maintenance burden. When 3rd party actions are updated or features are deprecated on GitHub Actions, the required changes need to be backported to all of those branches. This takes considerable time and effort.

This change converts Core’s workflow files to reusable ones. This allows the same workflow to be used for all (or most) branches, allowing the described maintenance updates to be made once in trunk.

To keep track of which files are reusable vs. those that are responsible for holding the strategy matrix for that branch, reusable workflows are now prefixed with reusable-.

Props johnbillion, swissspidy, jorbin, desrosj.
Fixes #61213.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/.github/workflows/coding-standards.yml

    r57757 r58165  
    4646
    4747jobs:
    48   # Runs PHP coding standards checks.
    49   #
    50   # Violations are reported inline with annotations.
    51   #
    52   # Performs the following steps:
    53   # - Checks out the repository.
    54   # - Sets up PHP.
    55   # - Configures caching for PHPCS scans.
    56   # - Installs Composer dependencies.
    57   # - Make Composer packages available globally.
    58   # - Runs PHPCS on the full codebase with warnings suppressed.
    59   # - Generate a report for displaying issues as pull request annotations.
    60   # - Runs PHPCS on the `tests` directory without warnings suppressed.
    61   # - Generate a report for displaying `test` directory issues as pull request annotations.
    62   # - Ensures version-controlled files are not modified or deleted.
     48  # Runs the PHP coding standards checks.
    6349  phpcs:
    6450    name: PHP coding standards
    65     runs-on: ubuntu-latest
     51    uses: WordPress/wordpress-develop/.github/workflows/reusable-coding-standards-php.yml@trunk
    6652    permissions:
    6753      contents: read
    68     timeout-minutes: 20
    6954    if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
    7055
    71     steps:
    72       - name: Checkout repository
    73         uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
    74         with:
    75           show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
    76 
    77       - name: Set up PHP
    78         uses: shivammathur/setup-php@a4e22b60bbb9c1021113f2860347b0759f66fe5d # v2.30.0
    79         with:
    80           php-version: 'latest'
    81           coverage: none
    82           tools: cs2pr
    83 
    84       # This date is used to ensure that the PHPCS cache is cleared at least once every week.
    85       # http://man7.org/linux/man-pages/man1/date.1.html
    86       - name: "Get last Monday's date"
    87         id: get-date
    88         run: echo "date=$(/bin/date -u --date='last Mon' "+%F")" >> $GITHUB_OUTPUT
    89 
    90       - name: Cache PHPCS scan cache
    91         uses: actions/cache@ab5e6d0c87105b4c9c2047343972218f562e4319 # v4.0.1
    92         with:
    93           path: |
    94             .cache/phpcs-src.json
    95             .cache/phpcs-tests.json
    96           key: ${{ runner.os }}-date-${{ steps.get-date.outputs.date }}-phpcs-cache-${{ hashFiles('**/composer.json', 'phpcs.xml.dist') }}
    97 
    98       # Since Composer dependencies are installed using `composer update` and no lock file is in version control,
    99       # passing a custom cache suffix ensures that the cache is flushed at least once per week.
    100       - name: Install Composer dependencies
    101         uses: ramsey/composer-install@57532f8be5bda426838819c5ee9afb8af389d51a # v3.0.0
    102         with:
    103           custom-cache-suffix: ${{ steps.get-date.outputs.date }}
    104 
    105       - name: Make Composer packages available globally
    106         run: echo "${PWD}/vendor/bin" >> $GITHUB_PATH
    107 
    108       - name: Run PHPCS on all Core files
    109         id: phpcs-core
    110         run: phpcs -n --report-full --cache=./.cache/phpcs-src.json --report-checkstyle=./.cache/phpcs-report.xml
    111 
    112       - name: Show PHPCS results in PR
    113         if: ${{ always() && steps.phpcs-core.outcome == 'failure' }}
    114         run: cs2pr ./.cache/phpcs-report.xml
    115 
    116       - name: Check test suite files for warnings
    117         id: phpcs-tests
    118         run: phpcs tests --report-full --cache=./.cache/phpcs-tests.json --report-checkstyle=./.cache/phpcs-tests-report.xml
    119 
    120       - name: Show test suite scan results in PR
    121         if: ${{ always() && steps.phpcs-tests.outcome == 'failure' }}
    122         run: cs2pr ./.cache/phpcs-tests-report.xml
    123 
    124       - name: Ensure version-controlled files are not modified during the tests
    125         run: git diff --exit-code
    126 
    12756  # Runs the JavaScript coding standards checks.
    128   #
    129   # JSHint violations are not currently reported inline with annotations.
    130   #
    131   # Performs the following steps:
    132   # - Checks out the repository.
    133   # - Sets up Node.js.
    134   # - Logs debug information about the GitHub Action runner.
    135   # - Installs npm dependencies.
    136   # - Run the WordPress JSHint checks.
    137   # - Ensures version-controlled files are not modified or deleted.
    13857  jshint:
    13958    name: JavaScript coding standards
    140     runs-on: ubuntu-latest
     59    uses: WordPress/wordpress-develop/.github/workflows/reusable-coding-standards-javascript.yml@trunk
    14160    permissions:
    14261      contents: read
    143     timeout-minutes: 20
    14462    if: ${{ github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' }}
    145     env:
    146       PUPPETEER_SKIP_DOWNLOAD: ${{ true }}
    147 
    148     steps:
    149       - name: Checkout repository
    150         uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
    151         with:
    152           show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
    153 
    154       - name: Set up Node.js
    155         uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
    156         with:
    157           node-version-file: '.nvmrc'
    158           cache: npm
    159 
    160       - name: Log debug information
    161         run: |
    162           npm --version
    163           node --version
    164           git --version
    165 
    166       - name: Install npm Dependencies
    167         run: npm ci
    168 
    169       - name: Run JSHint
    170         run: npm run grunt jshint
    171 
    172       - name: Ensure version-controlled files are not modified or deleted
    173         run: git diff --exit-code
    17463
    17564  slack-notifications:
Note: See TracChangeset for help on using the changeset viewer.