-
Notifications
You must be signed in to change notification settings - Fork 363
156 lines (140 loc) · 5.77 KB
/
build-docs.yml
File metadata and controls
156 lines (140 loc) · 5.77 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Deploy CCCL Documentation
on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Reusable workflow for PR previews
workflow_call:
inputs:
destination_dir:
description: "Destination directory for deployment"
required: false
default: "docs"
type: string
pr_number:
description: "PR number for preview URL generation"
required: false
default: ""
type: string
remove_pr_preview:
description: "If true, deploy empty folder to remove PR preview"
required: false
default: false
type: boolean
outputs:
preview_url:
description: "The URL where the PR preview is deployed"
value: ${{ jobs.build-and-deploy.outputs.preview_url }}
# Sets permissions of the GITHUB_TOKEN to allow GitHub Pages deployment and PR comments
permissions:
contents: write
pull-requests: write
pages: write
# Serialize deploy/cleanup for same PR to prevent races
concurrency:
group: ${{ inputs.pr_number && format('pr-preview-{0}', inputs.pr_number) || 'pages-main' }}
cancel-in-progress: false
jobs:
# Build and deploy job
build-and-deploy:
runs-on: ${{ github.repository == 'NVIDIA/cccl' && 'linux-amd64-cpu32' || 'ubuntu-latest' }}
outputs:
preview_url: ${{ steps.set-preview-url.outputs.preview_url }}
steps:
- name: Validate inputs
run: |
if [ "${{ inputs.remove_pr_preview }}" = "true" ] && [ -z "${{ inputs.pr_number }}" ]; then
echo "Error: remove_pr_preview requires pr_number to be set"
exit 1
fi
if [ -n "${{ inputs.pr_number }}" ] && ! echo "${{ inputs.pr_number }}" | grep -qE '^[0-9]+$'; then
echo "Error: pr_number must be numeric (got: '${{ inputs.pr_number }}')"
exit 1
fi
- name: Set preview URL
id: set-preview-url
run: |
if [ -n "${{ inputs.pr_number }}" ]; then
echo "preview_url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ inputs.pr_number }}/" >> $GITHUB_OUTPUT
else
echo "preview_url=" >> $GITHUB_OUTPUT
fi
- name: Checkout
uses: actions/checkout@v6
with:
persist-credentials: false
- name: Build docs
if: ${{ !inputs.remove_pr_preview }}
uses: ./.github/actions/docs-build
with:
upload_workflow_artifact: "true"
- name: Create empty directory for cleanup
if: ${{ inputs.remove_pr_preview }}
run: |
mkdir -p _site
echo "# Preview Removed" > _site/README.md
echo "This PR preview has been removed because the pull request was closed." >> _site/README.md
- name: Set commit message
id: commit-msg
run: |
if [ "${{ inputs.remove_pr_preview }}" = "true" ]; then
echo "message=Clean up doc preview for PR ${{ inputs.pr_number }} (${{ github.sha }})" >> $GITHUB_OUTPUT
elif [ -n "${{ inputs.pr_number }}" ]; then
echo "message=Deploy doc preview for PR ${{ inputs.pr_number }} (${{ github.sha }})" >> $GITHUB_OUTPUT
else
echo "message=Deploy main docs (${{ github.sha }})" >> $GITHUB_OUTPUT
fi
- name: Deploy .nojekyll to docs root
if: ${{ github.event_name == 'push' && !inputs.pr_number }} # Only create .nojekyll for main docs deployment
run: |
mkdir -p _nojekyll
touch _nojekyll/.nojekyll
- name: Ensure Jekyll is disabled for GitHub Pages
if: ${{ github.event_name == 'push' && !inputs.pr_number }} # Only deploy .nojekyll for main docs, not PR previews
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_nojekyll
publish_branch: gh-pages
destination_dir: docs
keep_files: true
commit_message: "Deploy .nojekyll to disable Jekyll processing"
- name: Deploy to GitHub Pages
if: ${{ github.event_name == 'push' && !inputs.pr_number }} # Don't deploy doc previews for now to avoid overflowing gh-pages branch
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./_site
publish_branch: gh-pages
destination_dir: ${{ inputs.destination_dir || 'docs' }}
keep_files: true
commit_message: ${{ steps.commit-msg.outputs.message }}
# - name: Leave PR preview comment
# if: ${{ inputs.pr_number && !inputs.remove_pr_preview }}
# uses: marocchino/sticky-pull-request-comment@67d0dec7b07ed060a405f9b2a64b8ab319fdd7db # v2.9.2
# with:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# header: pr-preview
# number: ${{ inputs.pr_number }}
# skip_unchanged: true
# message: |
# ## 📖 Doc Preview CI
#
# 🚀 **Preview URL:** [${{ steps.set-preview-url.outputs.preview_url }}](${{ steps.set-preview-url.outputs.preview_url }})
#
# _Preview will be available once GitHub Pages deployment completes._
# - name: Leave cleanup comment
# if: ${{ inputs.pr_number && inputs.remove_pr_preview }}
# uses: marocchino/sticky-pull-request-comment@67d0dec7b07ed060a405f9b2a64b8ab319fdd7db # v2.9.2
# with:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# header: pr-preview
# number: ${{ inputs.pr_number }}
# hide_and_recreate: true
# hide_classify: "OUTDATED"
# message: |
# ## 📖 Doc Preview CI
#
# Preview removed because the pull request was closed.