Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
123 changes: 120 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ on:
- main
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
issue_comment:
types: [created]
workflow_dispatch:

jobs:
php-lint:
name: PHP Lint
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
if: github.event_name != 'issue_comment' && (github.event_name != 'pull_request' || github.event.pull_request.draft == false)

strategy:
matrix:
Expand Down Expand Up @@ -40,7 +42,7 @@ jobs:
php-cs-fixer:
name: PHP-CS-Fixer (dry-run)
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
if: github.event_name != 'issue_comment' && (github.event_name != 'pull_request' || github.event.pull_request.draft == false)

steps:
- uses: actions/checkout@v5
Expand All @@ -64,7 +66,7 @@ jobs:
rexstan:
name: rexstan
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
if: github.event_name != 'issue_comment' && (github.event_name != 'pull_request' || github.event.pull_request.draft == false)
permissions:
contents: read

Expand Down Expand Up @@ -146,3 +148,118 @@ jobs:

- name: Run rexstan
run: redaxo_cms/redaxo/bin/console rexstan:analyze "redaxo/src/addons/${ADDON_KEY}"

php-cs-fixer-autofix:
name: PHP-CS-Fixer (autofix via /fix-cs)
runs-on: ubuntu-latest
if: >
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
contains(github.event.comment.body, '/fix-cs') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
permissions:
contents: write
pull-requests: write
issues: write

steps:
- name: Read PR context
id: pr
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const pull_number = context.payload.issue.number;
const { data: pr } = await github.rest.pulls.get({ owner, repo, pull_number });

core.setOutput('number', String(pr.number));
core.setOutput('headRef', pr.head.ref);
core.setOutput('headRepo', pr.head.repo.full_name);

- name: Abort for fork pull requests
if: steps.pr.outputs.headRepo != github.repository
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.payload.issue.number;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: 'Auto-Fix wurde nicht ausgefuehrt: Fork-PRs werden aus Sicherheitsgruenden nicht automatisch gepusht. Bitte local php-cs-fixer ausfuehren und committen.'
});

- name: Checkout PR branch
if: steps.pr.outputs.headRepo == github.repository
uses: actions/checkout@v5
with:
ref: ${{ steps.pr.outputs.headRef }}
fetch-depth: 0

- name: Setup PHP
if: steps.pr.outputs.headRepo == github.repository
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: none
tools: php-cs-fixer

- name: Run PHP-CS-Fixer (write mode)
if: steps.pr.outputs.headRepo == github.repository
run: |
if [ -f .php-cs-fixer.dist.php ] || [ -f .php-cs-fixer.php ]; then
php-cs-fixer fix --ansi --config=.php-cs-fixer.php
elif [ -f .php_cs.dist ] || [ -f .php_cs ]; then
php-cs-fixer fix --ansi
else
echo "Kein php-cs-fixer-Konfig vorhanden, verwende @PSR12"
php-cs-fixer fix --ansi --rules=@PSR12
fi

- name: Commit and push fixes
if: steps.pr.outputs.headRepo == github.repository
id: commit
run: |
if [ -n "$(git status --porcelain)" ]; then
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add -A
git commit -m "style: apply php-cs-fixer"
git push origin "HEAD:${{ steps.pr.outputs.headRef }}"
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Comment result (fixed)
if: steps.pr.outputs.headRepo == github.repository && steps.commit.outputs.changed == 'true'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.payload.issue.number;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: 'php-cs-fixer wurde ausgefuehrt und die Aenderungen wurden auf den PR-Branch gepusht.'
});

- name: Comment result (clean)
if: steps.pr.outputs.headRepo == github.repository && steps.commit.outputs.changed == 'false'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = context.payload.issue.number;
await github.rest.issues.createComment({
owner,
repo,
issue_number,
body: 'php-cs-fixer wurde ausgefuehrt. Keine Aenderungen erforderlich.'
});
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,25 @@ Default-Klassen: `uk-margin` (Clear) und `uk-divider-icon` (HR) – pro Profil

Issues, Pull Requests und Plugin-Ideen sind willkommen. Beim Beisteuern bitte die Hinweise in [DEVS.md](DEVS.md) beachten (Stilregeln, Build-Layout, Tests).

### PR-Kommando fuer PHP-CS-Fixer

Bei Pull Requests kann per Kommentar ein Auto-Fix gestartet werden:

```text
/fix-cs
```

Was passiert dann:

- GitHub Action fuehrt php-cs-fixer im Write-Mode auf dem PR-Branch aus.
- Falls Aenderungen entstehen, werden sie automatisch committed und auf denselben Branch gepusht.
- Anschliessend schreibt die Action einen Ergebnis-Kommentar in den PR.

Hinweise:

- Das Kommando ist auf Kommentare von `OWNER`, `MEMBER` und `COLLABORATOR` beschraenkt.
- Fork-PRs werden aus Sicherheitsgruenden nicht automatisch gepusht.

## Lizenzen

| Komponente | Lizenz |
Expand Down
2 changes: 1 addition & 1 deletion lib/TinyMce/Creator/Profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static function profilesCreate(?array $getProfile = null): void
$extraKeys = [];
foreach ($extras as $key => $value) {
$extraKeys[$key] = "\"$key\":\"$key\"";
$extraValues[$key] = $value;
$extraValues[$key] = $value ?: '';
}

$profiles = json_encode($jsonProfiles);
Expand Down