summaryrefslogtreecommitdiffstats
path: root/.github/workflows/docs_build_rebuild.yaml
blob: 06c774589b9ad577dac1a855aeeb9ed2d1e1ea43 (plain) (blame)
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
71
name: Rebuild documentation

on:
  pull_request_target:
    types: [labeled]

jobs:
  build-docs:
    if: |
      github.event.label.name == 'rebuild_docs' &&
      github.event.pull_request.state == 'open'
    concurrency:
      group: docs-build-${{ github.event.pull_request.number }}
      cancel-in-progress: true
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
      issues: write
    steps:
      - name: Check PR has docs changes
        id: docs-changes
        uses: actions/github-script@v8
        with:
          script: |
            const files = await github.paginate(github.rest.pulls.listFiles, {
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.payload.pull_request.number,
              per_page: 100,
            });
            const hasDocs = files.some((f) => f.filename.startsWith('ydb/docs/'));
            core.setOutput('has_docs', hasDocs ? 'true' : 'false');

      - name: Checkout
        if: steps.docs-changes.outputs.has_docs == 'true'
        uses: actions/checkout@v5
        with:
          ref: ${{ github.event.pull_request.head.sha }}

      - name: Get commit SHA
        id: sha
        if: steps.docs-changes.outputs.has_docs == 'true'
        run: echo "value=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT

      - name: Build
        if: steps.docs-changes.outputs.has_docs == 'true'
        uses: diplodoc-platform/docs-build-action@v3
        with:
          revision: "pr-${{ github.event.pull_request.number }}-${{ steps.sha.outputs.value }}"
          src-root: "./ydb/docs"
          cli-version: stable

      - name: Remove rebuild_docs label
        if: always()
        uses: actions/github-script@v8
        with:
          script: |
            // Always clear trigger label so manual re-run is a single re-add.
            try {
              await github.rest.issues.removeLabel({
                owner: context.repo.owner,
                repo: context.repo.repo,
                issue_number: context.payload.pull_request.number,
                name: 'rebuild_docs',
              });
            } catch (error) {
              if (error.status !== 404) {
                throw error;
              }
            }