-
Notifications
You must be signed in to change notification settings - Fork 3
155 lines (135 loc) · 5.46 KB
/
Copy pathpages.yml
File metadata and controls
155 lines (135 loc) · 5.46 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
# This workflow builds and deploys the app and optional documentation to
# GitHub Pages. It is intentionally guarded by repository variables so forks
# do not publish pages unless explicitly enabled.
#
# Triggers:
# - `push` to `main`: a deployment is possible but only runs when
# `ENABLE_GH_PAGES` repository variable is set to `true`.
# - `workflow_dispatch`: manual trigger with an `enable_docs` input to build
# documentation on demand.
#
# Key points for contributors:
# - `ENABLE_GH_PAGES` (repo variable) controls automatic deployments from CI.
# - `ENABLE_JSDOC_BUILD` (repo variable) or the `enable_docs` input controls
# whether the documentation (`docs-html`) is built and published.
# - The job creates a `gh-pages/` directory containing the app, docs, and a
# landing page, which is uploaded using `actions/upload-pages-artifact`.
# Note: Publishing with `actions/deploy-pages` uploads an artifact and then
# GitHub runs its own Pages publish pipeline. That will appear as a separate
# "pages build and deployment" run in the Actions UI in addition to this
# workflow run. This is expected behavior.
name: Deploy to GitHub Pages
on:
push:
branches: [main]
workflow_dispatch:
inputs:
enable_docs:
description: 'Build and deploy API documentation'
required: false
type: boolean
default: false
permissions:
contents: read
pages: write
id-token: write
concurrency:
group: 'pages'
cancel-in-progress: true
jobs:
log-context:
name: Log workflow context
runs-on: ubuntu-latest
# Run only when this workflow would otherwise run (same guard as `build`).
if: vars.ENABLE_GH_PAGES == 'true' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- name: Debug Info
uses: ./.github/actions/debug-info
with:
show-env: 'false'
- name: Log workflow context
run: |
echo "[Pages][log-context] Triggered by $GITHUB_EVENT_NAME on ref $GITHUB_REF for $GITHUB_REPOSITORY"
echo "[Pages][log-context] ENABLE_GH_PAGES=${{ vars.ENABLE_GH_PAGES }}"
build:
name: Build
runs-on: ubuntu-latest
# Only run if ENABLE_GH_PAGES is explicitly set to 'true' OR workflow_dispatch is used
# For forks: Set this in Settings → Secrets and variables → Actions → Variables
needs: log-context
if: vars.ENABLE_GH_PAGES == 'true' || github.event_name == 'workflow_dispatch'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Cache Vite build cache
# Cache Vite build artifacts to speed up the `npm run build` step for
# the Pages job. This is separate from the node/npm cache provided by
# `actions/setup-node` and targets Vite's local cache directories.
uses: actions/cache@v4
with:
path: |
node_modules/.vite
.vite
# Include lockfile and vite config in key so cache invalidates when
# dependencies or build configuration change.
key: ${{ runner.os }}-vite-${{ hashFiles('**/package-lock.json') }}-${{ hashFiles('**/vite.config.ts') }}
restore-keys: |
${{ runner.os }}-vite-
- name: Install dependencies
run: npm ci
- name: Build app
# `VITE_BASE_PATH` sets the app base used by Vite so the app can be
# hosted under `/modern-react-template/app/` on GitHub Pages.
env:
VITE_BASE_PATH: /modern-react-template/app/
run: npm run build
- name: Generate documentation (optional)
# Builds HTML docs when `ENABLE_JSDOC_BUILD` repo var is true or when
# the manual `enable_docs` input is provided at dispatch.
if: vars.ENABLE_JSDOC_BUILD == 'true' || inputs.enable_docs == true
run: npm run docs:html
- name: Build GitHub Pages landing (optional)
# Some repositories produce a separate landing page build; this step
# runs only when the `ENABLE_GH_PAGES` variable is enabled.
if: ${{ vars.ENABLE_GH_PAGES == 'true' }}
run: npm run build:gh-pages
- name: Create GitHub Pages structure
# Prepare the `gh-pages/` directory structure that will be uploaded.
run: |
mkdir -p gh-pages
# Copy the main app
cp -r dist gh-pages/app
# Copy documentation (if built)
if [ -d docs-html ]; then
cp -r docs-html gh-pages/docs
fi
# Copy the landing page
if [ -f dist/gh-pages-index.html ]; then
cp dist/gh-pages-index.html gh-pages/index.html
else
cp public/gh-pages-index.html gh-pages/index.html
fi
- name: Upload artifact
# Upload the `gh-pages/` folder as the Pages artifact. The separate
# `deploy` job consumes this artifact to publish the site.
uses: actions/upload-pages-artifact@v3
with:
path: gh-pages
deploy:
name: Deploy to GitHub Pages
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
# `actions/deploy-pages` reads the uploaded artifact and publishes it to
# the repository's GitHub Pages site. Check the Actions run logs and the
# Pages settings in the repo to verify the published URL.
uses: actions/deploy-pages@v4