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      uses: dawidd6/action-download-artifact@v2
25      with:
26        workflow: doc-build.yml
27        run_id: ${{ github.event.workflow_run.id }}
28
29    - name: Load PR number
30      run: |
31        echo "PR_NUM=$(<pr_num/pr_num)" >> $GITHUB_ENV
32
33    - name: Check PR number
34      id: check-pr
35      uses: carpentries/actions/check-valid-pr@v0.14.0
36      with:
37        pr: ${{ env.PR_NUM }}
38        sha: ${{ github.event.workflow_run.head_sha }}
39
40    - name: Validate PR number
41      if: steps.check-pr.outputs.VALID != 'true'
42      run: |
43        echo "ABORT: PR number validation failed!"
44        exit 1
45
46    - name: Uncompress HTML docs
47      run: |
48        tar xf html-output/html-output.tar.xz -C html-output
49
50    - name: Configure AWS Credentials
51      uses: aws-actions/configure-aws-credentials@v2
52      with:
53        aws-access-key-id: ${{ vars.AWS_BUILDS_ZEPHYR_PR_ACCESS_KEY_ID }}
54        aws-secret-access-key: ${{ secrets.AWS_BUILDS_ZEPHYR_PR_SECRET_ACCESS_KEY }}
55        aws-region: us-east-1
56
57    - name: Upload to AWS S3
58      env:
59        HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
60      run: |
61        aws s3 sync --quiet html-output/html \
62          s3://builds.zephyrproject.org/${{ github.event.repository.name }}/pr/${PR_NUM}/docs \
63          --delete
64