Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/rtcamp-standard.yml
Comment thread
Adi-ty marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: rtCamp Standard

on:
workflow_call:
inputs:
build-artifact-paths:
description: 'Newline-separated paths whose contents must not be committed.'
required: false
type: string
default: |
assets/build/
run-phpstan:
description: 'Whether to run the PHPStan job.'
required: false
type: boolean
default: true

permissions:
contents: read

jobs:
build-artifact-gate:
name: 'Block committed build artifacts'
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Fetch base branch
run: git fetch --depth=1 --no-tags origin "${{ github.base_ref }}"

- name: Detect committed build artifacts
env:
GATED_PATHS: ${{ inputs.build-artifact-paths }}
run: |
set -euo pipefail

PATTERN=$(printf '%s\n' "$GATED_PATHS" \
| sed 's/^[[:space:]]*//; s/[[:space:]]*$//' \
| grep -v '^$' \
| sed 's/\./\\./g' \
| paste -sd '|' -)

if [[ -z "$PATTERN" ]]; then
echo "No gated paths configured; skipping."
exit 0
fi

ANCHORED="^(${PATTERN})"
echo "Checking changed files against: ${ANCHORED}"

CHANGED=$(git diff --name-only --diff-filter=ACMR FETCH_HEAD HEAD \
| grep -E "${ANCHORED}" || true)

if [[ -n "$CHANGED" ]]; then
echo "::error::Build artifacts must not be committed. Offending files:"
printf '%s\n' "$CHANGED" | sed 's/^/ - /'
echo
echo "These paths are produced by CI on merge. Remove them from the PR"
echo "(e.g. 'git rm --cached <file>') and ensure they are gitignored."
exit 1
fi

echo "No committed build artifacts detected."

phpstan:
name: 'PHPStan'
runs-on: ubuntu-latest
if: ${{ inputs.run-phpstan }}
steps:
- name: Checkout
uses: actions/checkout@v6

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none

- name: Get Composer Cache Directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Configure Composer cache
uses: actions/cache@v5.0.3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction --no-scripts

- name: Run PHPStan
run: composer phpstan
10 changes: 9 additions & 1 deletion .github/workflows/test-measure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
MODIFIED_FILES_DATA=$(node .github/bin/determine-modified-files-count.js "$IGNORE_PATH_REGEX" "$MODIFIED_FILES" "all")
CSS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.s?css|package\.json|package-lock\.json" "$MODIFIED_FILES")
JS_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.(js|snap)|package\.json|package-lock\.json" "$MODIFIED_FILES")
PHP_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.php|composer\.(json|lock)|phpstan\.neon\.dist" "$MODIFIED_FILES")
PHP_FILE_COUNT=$(node .github/bin/determine-modified-files-count.js ".+\.php|composer\.(json|lock)|phpstan\.neon\.dist|phpstan-baseline\.neon" "$MODIFIED_FILES")
GHA_WORKFLOW_COUNT=$(node .github/bin/determine-modified-files-count.js "(\.github\/(workflows|actions)\/.+\.yml)" "$MODIFIED_FILES")

echo "Changed file count: $MODIFIED_FILES_DATA"
Expand Down Expand Up @@ -218,3 +218,11 @@ jobs:
run: npm run build:prod
env:
CI: true

rtcamp-standard:
name: 'rtCamp Standard'
needs: pre-run
if: ${{ github.event_name == 'pull_request' }}
uses: ./.github/workflows/rtcamp-standard.yml
with:
run-phpstan: ${{ fromJSON(needs.pre-run.outputs.changed-php-count) > 0 }}
Loading