|
| 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 |
0 commit comments