-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
115 lines (110 loc) · 4.31 KB
/
Copy pathaction.yml
File metadata and controls
115 lines (110 loc) · 4.31 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: 'Documentation Publish'
description: Publish documentation to azure.
inputs:
doc-subdir:
description: 'Subdirectory where the docs should be placed'
default: 'ncs'
doc-zip-name:
description: 'Name of zip with documentation (can contain wildcards)'
default: 'legacy-ncs*.zip'
workflow:
description: 'Workflow file that produced the documentation artifacts.'
required: false
default: 'docbuild.yml'
storage-url:
description: 'Azure storage container URL to upload the docs to.'
required: true
storage-url-pr:
description: 'Azure storage container uRL for upload of PR docs.'
storage-sas:
description: 'SAS token for prod builds.'
required: true
storage-pr-sas:
description: 'SAS token for pr builds.'
doc-url:
description: "Url of doc storage for PR's preview"
default: "https://ncsbmdoc.z6.web.core.windows.net/"
publish-pr:
description: "If true, publish PR builds"
default: true
github-token:
description: "GitHub token used to download artifacts and comment on PRs"
default: ${{ github.token }}
runs:
using: composite
steps:
- name: Check whether to publish
id: gate
shell: bash
env:
IS_PR: ${{ github.event.workflow_run.event == 'pull_request' }}
PUBLISH_PR: ${{ inputs.publish-pr }}
run: |
publish=true
if [ "$IS_PR" = "true" ] && [ "$PUBLISH_PR" != "true" ]; then
publish=false
echo "::notice title=Docs publish skipped::publish-pr is false and this is a pull request build."
fi
echo "publish=$publish" >> "$GITHUB_OUTPUT"
- name: Download artifacts
if: steps.gate.outputs.publish == 'true'
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
workflow: ${{ inputs.workflow }}
run_id: ${{ github.event.workflow_run.id }}
github_token: ${{ inputs.github-token }}
- name: Unzip html archive
if: steps.gate.outputs.publish == 'true'
shell: bash
working-directory: docs
id: unzip
run: |
OUTDIR=${{ inputs.doc-subdir }}/$(awk 'NR==1 { if ($3 ~ /^(latest|PR-[0-9]+|[0-9]+\.[0-9a-zA-Z\.\-]+)$/) print $3 }' monitor_*.txt)
mkdir -p "$OUTDIR"
echo "OUTDIR=$OUTDIR" >> "$GITHUB_ENV"
unzip ${{ inputs.doc-zip-name }} -d $OUTDIR
find "$OUTDIR" -type l -delete
- name: Obtain PR number
if: steps.gate.outputs.publish == 'true'
shell: bash
working-directory: docs
run: |
if [ -f pr.txt ]; then
PR=$(head -n 1 pr.txt | tr -cd '0-9')
fi
printf 'PR=%s\n' "$PR" >> "$GITHUB_ENV"
- name: Upload to Azure storage
if: steps.gate.outputs.publish == 'true'
shell: bash
working-directory: docs
env:
AZCOPY_CONCURRENCY_VALUE: 1024
NCS_DOC_SAS_PRS: ${{ inputs.storage-pr-sas }}
NCS_DOC_SAS_MAIN: ${{ inputs.storage-sas }}
run: |
if [[ "${{ github.event.workflow_run.event }}" == "pull_request" ]]; then
NCS_DOC_STORAGE_URL="${{ inputs.storage-url-pr }}"
azcopy cp $OUTDIR "${NCS_DOC_STORAGE_URL}${{ inputs.doc-subdir }}?${NCS_DOC_SAS_PRS}" --recursive=true
else
NCS_DOC_STORAGE_URL="${{ inputs.storage-url }}"
azcopy cp $OUTDIR "${NCS_DOC_STORAGE_URL}${{ inputs.doc-subdir }}?${NCS_DOC_SAS_MAIN}" --recursive=true
fi
- name: Find Comment
if: ${{ steps.gate.outputs.publish == 'true' && github.event.workflow_run.event == 'pull_request' }}
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3
id: fc
with:
token: ${{ inputs.github-token }}
issue-number: ${{ env.PR }}
comment-author: 'github-actions[bot]'
body-includes: documentation preview
- name: Create or update comment
if: ${{ steps.gate.outputs.publish == 'true' && github.event.workflow_run.event == 'pull_request' }}
uses: peter-evans/create-or-update-comment@71345be0265236311c031f5c7866368bd1eff043 # v4
with:
token: ${{ inputs.github-token }}
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ env.PR }}
body: |
You can find the documentation preview for this PR [here](${{ inputs.doc-url }}${{ inputs.doc-subdir }}/PR-${{ env.PR }}/).
edit-mode: replace