Skip to content

Commit 23e4fb4

Browse files
authored
Add docbook-cs (#5524)
1 parent 82f00c8 commit 23e4fb4

3 files changed

Lines changed: 144 additions & 29 deletions

File tree

.github/workflows/check-whitespace.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

.github/workflows/docbook-cs.yaml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# https://docs.github.com/en/actions
2+
3+
name: "DocBook Lint"
4+
5+
on:
6+
push:
7+
pull_request:
8+
branches:
9+
- "master"
10+
11+
permissions:
12+
contents: "read"
13+
14+
concurrency:
15+
group: "${{ github.workflow }}-${{ github.ref }}"
16+
cancel-in-progress: true
17+
18+
jobs:
19+
docbook-cs:
20+
name: "DocBook Style Check"
21+
runs-on: "ubuntu-latest"
22+
23+
env:
24+
# Base commit to diff against: PR base on pull_request, pre-push tip on push.
25+
BASE_SHA: |-
26+
${{
27+
case(
28+
github.event_name == 'pull_request', github.event.pull_request.base.sha,
29+
github.event_name == 'push', github.event.before,
30+
'INVALID'
31+
)
32+
}}
33+
34+
strategy:
35+
matrix:
36+
language:
37+
- "en"
38+
39+
steps:
40+
- name: "Checkout php/doc-${{ matrix.language }}"
41+
uses: "actions/checkout@v6"
42+
with:
43+
ref: "${{ github.event.pull_request.head.sha }}"
44+
path: "${{ matrix.language }}"
45+
fetch-depth: 50
46+
47+
- name: "Checkout php/doc-base"
48+
uses: "actions/checkout@v6"
49+
with:
50+
path: "doc-base"
51+
repository: "php/doc-base"
52+
53+
- name: "Checkout php/docbook-cs"
54+
uses: "actions/checkout@v6"
55+
with:
56+
path: "docbook-cs"
57+
repository: "php/docbook-cs"
58+
59+
- name: "Fetch diff base"
60+
working-directory: "${{ matrix.language }}"
61+
run: |
62+
git fetch origin "$BASE_SHA" --depth=50
63+
# Deepen until the merge-base is reachable (long-lived branches)
64+
for i in 1 2 3 4 5; do
65+
git merge-base "$BASE_SHA" HEAD >/dev/null 2>&1 && break
66+
git fetch --deepen=100 origin "$BASE_SHA"
67+
done
68+
69+
- name: "Setup PHP"
70+
uses: "shivammathur/setup-php@v2"
71+
with:
72+
php-version: "8.5"
73+
extensions: "dom, libxml, simplexml"
74+
tools: composer, cs2pr
75+
76+
- name: "Build documentation"
77+
run: |
78+
php doc-base/configure.php \
79+
--disable-libxml-check \
80+
--enable-xml-details \
81+
--redirect-stderr-to-stdout \
82+
--with-lang=${{ matrix.language }}
83+
84+
- name: "Install docbook-cs"
85+
working-directory: "docbook-cs"
86+
run: composer install --no-interaction --no-progress
87+
88+
- name: "Run docbook-cs with diff"
89+
working-directory: "${{ matrix.language }}"
90+
run: |
91+
set -o pipefail
92+
git diff "$BASE_SHA"...HEAD | php ../docbook-cs/bin/docbook-cs \
93+
--report=checkstyle \
94+
--diff \
95+
--no-colors > docbook-report.xml
96+
97+
- name: "Upload report"
98+
if: ${{ ! cancelled() }}
99+
uses: "actions/upload-artifact@v7"
100+
with:
101+
name: "docbook-report"
102+
path: "${{ matrix.language }}/docbook-report.xml"
103+
104+
- name: "Annotate PR with violations"
105+
if: ${{ ! cancelled() }}
106+
working-directory: "${{ matrix.language }}"
107+
run: cs2pr docbook-report.xml --colorize --prepend-filename

docbookcs.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<docbookcs xmlns="https://php.github.io/docbook-cs/config"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://php.github.io/docbook-cs/config
5+
https://php.github.io/docbook-cs/config.xsd">
6+
7+
<project>
8+
<directory alias="doc-en">en</directory>
9+
<directory>doc-base</directory>
10+
</project>
11+
12+
<sniffs>
13+
<sniff class="DocbookCS\Sniff\SimparaSniff" />
14+
<sniff class="DocbookCS\Sniff\ExceptionNameSniff" />
15+
<sniff class="DocbookCS\Sniff\AttributeOrderSniff" />
16+
<sniff class="DocbookCS\Sniff\WhitespaceSniff" />
17+
</sniffs>
18+
19+
<paths>
20+
<path>.</path>
21+
</paths>
22+
23+
<entities>
24+
<file>contributors.ent</file>
25+
<file>extensions.ent</file>
26+
<file>language-defs.ent</file>
27+
<file>language-snippets.ent</file>
28+
<directory>../doc-base/entities/</directory>
29+
<file>../doc-base/temp/file-entities.ent</file>
30+
<directory>../doc-base/temp/file-entities</directory>
31+
</entities>
32+
33+
<exclude>
34+
<pattern>output/*</pattern>
35+
</exclude>
36+
37+
</docbookcs>

0 commit comments

Comments
 (0)