1# Copyright (c) 2020 Linaro Limited.
2# Copyright (c) 2021 Nordic Semiconductor ASA
3# SPDX-License-Identifier: Apache-2.0
4
5name: Documentation Publish (Pull Request)
6
7on:
8  workflow_run:
9    workflows: ["Documentation Build"]
10    types:
11    - completed
12
13jobs:
14  doc-publish:
15    name: Publish Documentation
16    runs-on: ubuntu-22.04
17    if: |
18      github.event.workflow_run.event == 'pull_request' &&
19      github.event.workflow_run.conclusion == 'success' &&
20      github.repository == 'zephyrproject-rtos/zephyr'
21
22    steps:
23    - name: Download artifacts
24      id: download-artifacts
25      uses: dawidd6/action-download-artifact@v6
26      with:
27        workflow: doc-build.yml
28        run_id: ${{ github.event.workflow_run.id }}
29        if_no_artifact_found: ignore
30
31    - name: Load PR number
32      if: steps.download-artifacts.outputs.found_artifact == 'true'
33      uses: actions/github-script@v7
34      with:
35        script: |
36          let fs = require("fs");
37          let pr_number = Number(fs.readFileSync("./pr_num/pr_num"));
38          core.exportVariable("PR_NUM", pr_number);
39
40    - name: Check PR number
41      if: steps.download-artifacts.outputs.found_artifact == 'true'
42      id: check-pr
43      uses: carpentries/actions/check-valid-pr@v0.14.0
44      with:
45        pr: ${{ env.PR_NUM }}
46        sha: ${{ github.event.workflow_run.head_sha }}
47
48    - name: Validate PR number
49      if: |
50        steps.download-artifacts.outputs.found_artifact == 'true' &&
51        steps.check-pr.outputs.VALID != 'true'
52      run: |
53        echo "ABORT: PR number validation failed!"
54        exit 1
55
56    - name: Uncompress HTML docs
57      if: steps.download-artifacts.outputs.found_artifact == 'true'
58      run: |
59        tar xf html-output/html-output.tar.xz -C html-output
60        if [ -f api-coverage/api-coverage.tar.xz ]; then
61          tar xf api-coverage/api-coverage.tar.xz -C api-coverage
62        fi
63
64    - name: Configure AWS Credentials
65      if: steps.download-artifacts.outputs.found_artifact == 'true'
66      uses: aws-actions/configure-aws-credentials@v4
67      with:
68        aws-access-key-id: ${{ vars.AWS_BUILDS_ZEPHYR_PR_ACCESS_KEY_ID }}
69        aws-secret-access-key: ${{ secrets.AWS_BUILDS_ZEPHYR_PR_SECRET_ACCESS_KEY }}
70        aws-region: us-east-1
71
72    - name: Upload to AWS S3
73      if: steps.download-artifacts.outputs.found_artifact == 'true'
74      env:
75        HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
76      run: |
77        aws s3 sync --quiet html-output/html \
78          s3://builds.zephyrproject.org/${{ github.event.repository.name }}/pr/${PR_NUM}/docs \
79          --delete
80        if [ -d api-coverage/coverage-report ]; then
81          aws s3 sync --quiet api-coverage/coverage-report/ \
82            s3://builds.zephyrproject.org/${{ github.event.repository.name }}/pr/${PR_NUM}/api-coverage \
83            --delete
84        fi
85