-
Notifications
You must be signed in to change notification settings - Fork 2
154 lines (143 loc) · 5.76 KB
/
Copy pathcd-docs.yml
File metadata and controls
154 lines (143 loc) · 5.76 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
# Documentation Deployment Pipeline
#
# - PR with docs changes: build a /-rooted bundle, deploy preview to Surge.sh
# - push to main with docs changes: build /Hephaestus/-rooted bundle, deploy to GitHub Pages
# - PR close: cd-docs-teardown.yml removes the preview (path filters are unreliable on close)
name: CD / Docs
on:
push:
branches: [main]
paths:
- "docs/**"
- ".github/workflows/cd-docs.yml"
pull_request:
types: [opened, synchronize, reopened]
paths:
- "docs/**"
- ".github/workflows/cd-docs.yml"
workflow_dispatch:
concurrency:
group: docs-deploy-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.number) || github.ref }}
cancel-in-progress: true
permissions:
contents: read
pages: write
id-token: write
pull-requests: write
statuses: write
jobs:
# build-preview and build-production are split so each only spins up a runner
# for the event it serves; collapsing into a matrix would burn ~30s on the
# idle flavor for every trigger. The shared steps live in setup-pnpm-node.
build-preview:
name: Build (preview)
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: ./.github/actions/setup-pnpm-node
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
docs/.docusaurus
docs/node_modules/.cache
key: ${{ runner.os }}-docusaurus-preview-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('docs/**/*.md', 'docs/**/*.mdx', 'docs/**/*.ts') }}
restore-keys: |
${{ runner.os }}-docusaurus-preview-${{ hashFiles('pnpm-lock.yaml') }}-
${{ runner.os }}-docusaurus-preview-
- run: pnpm install --frozen-lockfile
- run: pnpm --filter docs run build
env:
DOCUSAURUS_BASE_URL: "/"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: docs-build-preview
path: docs/build
retention-days: 1
build-production:
name: Build (production)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: ./.github/actions/setup-pnpm-node
- uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: |
docs/.docusaurus
docs/node_modules/.cache
key: ${{ runner.os }}-docusaurus-production-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('docs/**/*.md', 'docs/**/*.mdx', 'docs/**/*.ts') }}
restore-keys: |
${{ runner.os }}-docusaurus-production-${{ hashFiles('pnpm-lock.yaml') }}-
${{ runner.os }}-docusaurus-production-
- run: pnpm install --frozen-lockfile
- run: pnpm --filter docs run build
env:
DOCUSAURUS_BASE_URL: "/Hephaestus/"
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
with:
name: docs-build-production
path: docs/build
retention-days: 1
preview:
name: PR Preview
needs: build-preview
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
env:
PREVIEW_URL: ls1intum-hephaestus-docs-pr-${{ github.event.number }}.surge.sh
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
# Need: composite action, Node version, lockfile (for actions/setup-node cache key).
sparse-checkout: |
.github/actions/setup-pnpm-node
.node-version
pnpm-lock.yaml
sparse-checkout-cone-mode: false
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: docs-build-preview
path: docs-build
- uses: ./.github/actions/setup-pnpm-node
- name: Deploy to Surge.sh
run: pnpm dlx surge ./docs-build ${{ env.PREVIEW_URL }} --token ${{ secrets.SURGE_TOKEN }}
- uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
with:
header: docs-preview
message: |
## 📚 Documentation Preview
This PR includes documentation changes. A preview has been deployed:
🔗 **[View Docs Preview](https://${{ env.PREVIEW_URL }})**
<sub>Preview for commit ${{ github.event.pull_request.head.sha }}. Updates automatically on new commits.</sub>
- uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
with:
script: |
const sha = context.payload.pull_request?.head?.sha || context.sha;
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: sha,
state: 'success',
target_url: 'https://${{ env.PREVIEW_URL }}',
description: 'Click Details to view Docs Preview',
context: 'Preview / Docs'
});
deploy:
name: GitHub Pages
needs: build-production
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: docs-build-production
path: docs-build
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3
with:
path: docs-build
- id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4