Skip to content

Commit 30b323d

Browse files
committed
docs: rewrite github/gitlab deploying guide (closes #2205)
1 parent 29b8f76 commit 30b323d

File tree

1 file changed

+61
-58
lines changed

1 file changed

+61
-58
lines changed

Diff for: docs/guide/deploy.md

+61-58
Original file line numberDiff line numberDiff line change
@@ -119,66 +119,87 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f
119119

120120
### GitHub Pages
121121

122-
1. In your theme config file, `docs/.vitepress/config.js`, set the `base` property to the name of your GitHub repository. If you plan to deploy your site to `https://foo.github.io/bar/`, then you should set base to `'/bar/'`. It should always start and end with a slash.
123-
124-
2. Create a file named `deploy.yml` inside `.github/workflows` directory of your project with the following content:
122+
1. Create a file named `deploy.yml` inside `.github/workflows` directory of your project with some content like this:
125123

126124
```yaml
127-
name: Deploy
125+
# Sample workflow for building and deploying a VitePress site to GitHub Pages
126+
#
127+
name: Deploy VitePress site to Pages
128+
128129
on:
129-
workflow_dispatch: {}
130+
# Runs on pushes targeting the `main` branch. Change this to `master` if you're
131+
# using the `master` branch as the default branch.
130132
push:
131-
branches:
132-
- main
133+
branches: [main]
134+
135+
# Allows you to run this workflow manually from the Actions tab
136+
workflow_dispatch:
137+
138+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
139+
permissions:
140+
contents: read
141+
pages: write
142+
id-token: write
143+
144+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
145+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
146+
concurrency:
147+
group: pages
148+
cancel-in-progress: false
149+
133150
jobs:
134-
deploy:
151+
# Build job
152+
build:
135153
runs-on: ubuntu-latest
136-
permissions:
137-
contents: read
138-
pages: write
139-
id-token: write
140-
environment:
141-
name: github-pages
142-
url: ${{ steps.deployment.outputs.page_url }}
143154
steps:
144-
- uses: actions/checkout@v3
155+
- name: Checkout
156+
uses: actions/checkout@v3
145157
with:
146-
fetch-depth: 0
147-
- uses: actions/setup-node@v3
158+
fetch-depth: 0 # Not needed if lastUpdated is not enabled
159+
# - uses: pnpm/action-setup@v2 # Uncomment this if you're using pnpm
160+
- name: Setup Node
161+
uses: actions/setup-node@v3
148162
with:
149-
node-version: 16
150-
cache: npm
151-
- run: npm ci
152-
- name: Build
153-
run: npm run docs:build
154-
- uses: actions/configure-pages@v2
155-
- uses: actions/upload-pages-artifact@v1
163+
node-version: 18
164+
cache: npm # or pnpm / yarn
165+
- name: Setup Pages
166+
uses: actions/configure-pages@v3
167+
- name: Install dependencies
168+
run: npm ci # or pnpm install / yarn install
169+
- name: Build with VitePress
170+
run: npm run docs:build # or pnpm docs:build / yarn docs:build
171+
- name: Upload artifact
172+
uses: actions/upload-pages-artifact@v2
156173
with:
157174
path: docs/.vitepress/dist
158-
- name: Deploy
175+
176+
# Deployment job
177+
deploy:
178+
environment:
179+
name: github-pages
180+
url: ${{ steps.deployment.outputs.page_url }}
181+
needs: build
182+
runs-on: ubuntu-latest
183+
name: Deploy
184+
steps:
185+
- name: Deploy to GitHub Pages
159186
id: deployment
160-
uses: actions/deploy-pages@v1
187+
uses: actions/deploy-pages@v2
161188
```
162189
163-
::: tip
164-
Please replace the corresponding branch name. For example, if the branch you want to build is `master`, then you should replace `main` with `master` in the above file.
190+
::: warning
191+
Make sure the `base` option in your VitePress is properly configured. See [Setting a Public Base Path](#setting-a-public-base-path) for more details.
165192
:::
166193

167-
3. In your repository's Settings under Pages menu item, select `GitHub Actions` in Build and deployment's Source.
168-
169-
4. Now commit your code and push it to the `main` branch.
194+
2. In your repository's settings under "Pages" menu item, select "GitHub Actions" in "Build and deployment > Source".
170195

171-
5. Wait for actions to complete.
172-
173-
6. In your repository's Settings under Pages menu item, click `Visit site`, then you can see your site. Your docs will automatically deploy each time you push.
196+
3. Push your changes to the `main` branch and wait for the GitHub Actions workflow to complete. You should see your site deployed to `https://<username>.github.io/[repository]/` or `https://<custom-domain>/` depending on your settings. Your site will automatically be deployed on every push to the `main` branch.
174197

175198
### GitLab Pages
176199

177-
1. Set `outDir` in `docs/.vitepress/config.js` to `../public`.
178-
179-
2. Still in your config file, `docs/.vitepress/config.js`, set the `base` property to the name of your GitLab repository. If you plan to deploy your site to `https://foo.gitlab.io/bar/`, then you should set base to `'/bar/'`. It should always start and end with a slash.
200+
1. Set `outDir` in VitePress config to `../public`. Configure `base` option to `'/<repository>/'` if you want to deploy to `https://<username>.gitlab.io/<repository>/`.
180201

181-
3. Create a file called `.gitlab-ci.yml` in the root of your project with the content below. This will build and deploy your site whenever you make changes to your content:
202+
2. Create a file named `.gitlab-ci.yml` in the root of your project with the content below. This will build and deploy your site whenever you make changes to your content:
182203

183204
```yaml
184205
image: node:16
@@ -187,25 +208,7 @@ Don't enable options like _Auto Minify_ for HTML code. It will remove comments f
187208
paths:
188209
- node_modules/
189210
script:
190-
- npm install
191-
- npm run docs:build
192-
artifacts:
193-
paths:
194-
- public
195-
only:
196-
- main
197-
```
198-
199-
4. Alternatively, if you want to use an _alpine_ version of node, you have to install `git` manually. In that case, the code above modifies to this:
200-
```yaml
201-
image: node:16-alpine
202-
pages:
203-
cache:
204-
paths:
205-
- node_modules/
206-
before_script:
207-
- apk add git
208-
script:
211+
# - apk add git # Uncomment this if you're using small docker images like alpine and have lastUpdated enabled
209212
- npm install
210213
- npm run docs:build
211214
artifacts:

0 commit comments

Comments
 (0)