Skip to content

Commit

Permalink
Update workflows to make them reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
sclark3-godaddy committed May 18, 2024
1 parent 8f4bbc9 commit 05c2c15
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 117 deletions.
23 changes: 2 additions & 21 deletions workflow-templates/php-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,5 @@ on:
- 'composer.json'
- '.github/workflows/php-compatibility.yml'
jobs:
phpcompatibility:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Run PHPCS inspection
uses: rtCamp/action-phpcs-code-review@v3
env:
GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
PHPCS_STANDARD_FILE_NAME: .phpcs.compat.xml
phpcs-compatibility:
uses: pods-framework/.github/workflows/php-compatibility.yml@main
51 changes: 1 addition & 50 deletions workflow-templates/php-phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,4 @@ on:
- '.github/workflows/php-phpcs.yml'
jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

# ------------------------------------------------------------------------------
# Prepare our cache directories
# ------------------------------------------------------------------------------
- name: Get Composer Cache Directory
id: get-composer-cache-dir
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v2
id: composer-cache
with:
path: ${{ steps.get-composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- uses: "shivammathur/setup-php@v2"
with:
php-version: 7.4
- uses: "ramsey/composer-install@v2"

- name: "Give permissions"
run: |
sudo chown -R root:root $GITHUB_WORKSPACE
# ------------------------------------------------------------------------------
# Get changed files
# ------------------------------------------------------------------------------
- name: Get list of changed files
id: files
run: |
echo "CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.php$' | tr '\n' ' ')" >> $GITHUB_ENV
# ------------------------------------------------------------------------------
# PHPCS
# ------------------------------------------------------------------------------
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
vendor/bin/phpcs --report=json ${CHANGED_FILES} | jq -r ' .files | to_entries[] | .key as $path | .value.messages[] as $msg | "\($path):\($msg.line):\($msg.column):`\($msg.source)`<br>\($msg.message)" ' | reviewdog -efm="%f:%l:%c:%m" -name="phpcs" -filter-mode="added" -fail-on-error=true -reporter=github-pr-review
uses: pods-framework/.github/workflows/php-phpcs.yml@main
47 changes: 1 addition & 46 deletions workflow-templates/php-phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,4 @@ on:
- '.github/workflows/php-phpstan.yml'
jobs:
phpstan:
strategy:
matrix:
phpVersion: [
"7.4",
"8.0",
"8.1",
"8.2",
"8.3"
]
runs-on: ubuntu-20.04
steps:
# ------------------------------------------------------------------------------
# Checkout the repository
# ------------------------------------------------------------------------------
- name: Checkout the repository
uses: actions/checkout@v4
# ------------------------------------------------------------------------------
# Get the changed files in a space separated list.
# ------------------------------------------------------------------------------
- name: Get all changed files and use a space separator in the output
id: changed-files
uses: tj-actions/changed-files@v44
with:
separator: " "
# ------------------------------------------------------------------------------
# Set up PHP and run phpstan
# ------------------------------------------------------------------------------
- name: Configure PHP environment to run phpstan
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.phpVersion }}
# ------------------------------------------------------------------------------
# Override composer php version
# ------------------------------------------------------------------------------
- name: Set php version ${{ matrix.phpVersion }} in composer
run: composer config platform.php ${{ matrix.phpVersion }}
# ------------------------------------------------------------------------------
# Install dependencies - ignoring php requirements
# ------------------------------------------------------------------------------
- name: Install dependencies
run: composer i --ignore-platform-req=php+
# ------------------------------------------------------------------------------
# Run phpstan
# ------------------------------------------------------------------------------
- name: Run phpstan
run: ./vendor/bin/phpstan analyse --error-format=table -c phpstan.neon ${{ steps.changed-files.outputs.all_changed_files }}
uses: pods-framework/.github/workflows/php-phpstan.yml@main
23 changes: 23 additions & 0 deletions workflows/php-compatibility.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: 'PHP Compatibility'
jobs:
phpcs-compatibility:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Run PHPCS inspection
uses: rtCamp/action-phpcs-code-review@v3
env:
GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
PHPCS_STANDARD_FILE_NAME: .phpcs.compat.xml
53 changes: 53 additions & 0 deletions workflows/php-phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: 'PHP CodeSniffer'
jobs:
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

# ------------------------------------------------------------------------------
# Prepare our cache directories
# ------------------------------------------------------------------------------
- name: Get Composer Cache Directory
id: get-composer-cache-dir
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v2
id: composer-cache
with:
path: ${{ steps.get-composer-cache-dir.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- uses: "shivammathur/setup-php@v2"
with:
php-version: 7.4
- uses: "ramsey/composer-install@v2"

- name: "Give permissions"
run: |
sudo chown -R root:root $GITHUB_WORKSPACE
# ------------------------------------------------------------------------------
# Get changed files
# ------------------------------------------------------------------------------
- name: Get list of changed files
id: files
run: |
echo "CHANGED_FILES=$(git diff --name-only --diff-filter=AM ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep '\.php$' | tr '\n' ' ')" >> $GITHUB_ENV
# ------------------------------------------------------------------------------
# PHPCS
# ------------------------------------------------------------------------------
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest # Optional. [latest,nightly,v.X.Y.Z]
- name: Run reviewdog
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
run: |
vendor/bin/phpcs --report=json ${CHANGED_FILES} | jq -r ' .files | to_entries[] | .key as $path | .value.messages[] as $msg | "\($path):\($msg.line):\($msg.column):`\($msg.source)`<br>\($msg.message)" ' | reviewdog -efm="%f:%l:%c:%m" -name="phpcs" -filter-mode="added" -fail-on-error=true -reporter=github-pr-review
49 changes: 49 additions & 0 deletions workflows/php-phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: 'PHP Static Analysis'
jobs:
phpstan:
strategy:
matrix:
phpVersion: [
"7.4",
"8.0",
"8.1",
"8.2",
"8.3"
]
runs-on: ubuntu-20.04
steps:
# ------------------------------------------------------------------------------
# Checkout the repository
# ------------------------------------------------------------------------------
- name: Checkout the repository
uses: actions/checkout@v4
# ------------------------------------------------------------------------------
# Get the changed files in a space separated list.
# ------------------------------------------------------------------------------
- name: Get all changed files and use a space separator in the output
id: changed-files
uses: tj-actions/changed-files@v44
with:
separator: " "
# ------------------------------------------------------------------------------
# Set up PHP and run phpstan
# ------------------------------------------------------------------------------
- name: Configure PHP environment to run phpstan
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.phpVersion }}
# ------------------------------------------------------------------------------
# Override composer php version
# ------------------------------------------------------------------------------
- name: Set php version ${{ matrix.phpVersion }} in composer
run: composer config platform.php ${{ matrix.phpVersion }}
# ------------------------------------------------------------------------------
# Install dependencies - ignoring php requirements
# ------------------------------------------------------------------------------
- name: Install dependencies
run: composer i --ignore-platform-req=php+
# ------------------------------------------------------------------------------
# Run phpstan
# ------------------------------------------------------------------------------
- name: Run phpstan
run: ./vendor/bin/phpstan analyse --error-format=table -c phpstan.neon ${{ steps.changed-files.outputs.all_changed_files }}

0 comments on commit 05c2c15

Please sign in to comment.