-
Notifications
You must be signed in to change notification settings - Fork 318
70 lines (63 loc) · 2.62 KB
/
php-cs.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Workflow de vérification du style de code K&R
# Ne vérifie que les lignes modifiées dans les fichiers PHP des PR
name: PHP K&R Style Check
on:
pull_request:
jobs:
style-check:
name: Check K&R style
runs-on: ubuntu-latest
steps:
# Récupération du code avec l'historique pour pouvoir faire le diff
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
# Identifie les fichiers PHP modifiés et génère leurs diffs
- name: Get changed files and diffs
id: changes
run: |
FILES=$(git diff --name-only --diff-filter=ACMRT origin/${{ github.base_ref }} ${{ github.sha }} | grep "\.php$" || true)
echo "PHP files changed:"
echo "$FILES"
echo "files=$FILES" >> $GITHUB_OUTPUT
mkdir -p .diffs
for file in $FILES; do
git diff --unified=0 origin/${{ github.base_ref }} ${{ github.sha }} -- "$file" > ".diffs/$(basename "$file").diff"
done
# Exécute la vérification de style dans un container Docker
- name: Run PHP CS check
id: style_check
if: steps.changes.outputs.files != ''
continue-on-error: true
run: |
docker run --rm \
-v ${{ github.workspace }}:/app \
-v ${{ github.workspace }}/.diffs:/app/.diffs \
-w /app \
php:8.1-cli \
bash -c 'apt-get update && apt-get install -y git && chmod +x .github/scripts/check-style.sh && DIFF_DIR=/app/.diffs .github/scripts/check-style.sh ${{ steps.changes.outputs.files }}'
# Poste un commentaire avec les instructions en cas d'erreur
- name: Post documentation notice
if: steps.style_check.outcome == 'failure'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const message = `## Code Style Errors Detected
Pour corriger ces erreurs, consultez la documentation :
- [Documentation FR](docs/fr_FR/code-styling.md)
- [Documentation EN](docs/en_US/code-styling.md)
- [Documentation DE](docs/de_DE/code-styling.md)
- [Documentation ES](docs/es_ES/code-styling.md)
`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});
# Faire échouer le workflow si des erreurs sont trouvées
- name: Check for errors
if: steps.style_check.outcome == 'failure'
run: exit 1