docs: Use tabs on choosing a GitHub action file (#11145)

Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
This commit is contained in:
David King Roderos 2025-05-06 16:34:48 +08:00 committed by GitHub
parent fef6c4c8cb
commit 42223ef9eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -374,12 +374,96 @@ Add these two workflow files:
:::warning Tweak the parameters for your setup
These files assume you are using Yarn. If you use npm, change `cache: yarn`, `yarn install --frozen-lockfile`, `yarn build` to `cache: npm`, `npm ci`, `npm run build` accordingly.
If your Docusaurus project is not at the root of your repo, you may need to configure a [default working directory](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-set-the-default-shell-and-working-directory), and adjust the paths accordingly.
:::
<Tabs>
<TabItem value="npm" label="npm">
```yml title=".github/workflows/deploy.yml"
name: Deploy to GitHub Pages
on:
push:
branches:
- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
jobs:
build:
name: Build Docusaurus
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- name: Install dependencies
run: npm ci
- name: Build website
run: npm build
- name: Upload Build Artifact
uses: actions/upload-pages-artifact@v3
with:
path: build
deploy:
name: Deploy to GitHub Pages
needs: build
# Grant GITHUB_TOKEN the permissions required to make a Pages deployment
permissions:
pages: write # to deploy to Pages
id-token: write # to verify the deployment originates from an appropriate source
# Deploy to the github-pages environment
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
```
```yml title=".github/workflows/test-deploy.yml"
name: Test deployment
on:
pull_request:
branches:
- main
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on
jobs:
test-deploy:
name: Test deployment
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 18
cache: npm
- name: Install dependencies
run: npm ci
- name: Test build website
run: npm build
```
</TabItem>
<TabItem value="yarn" label="Yarn">
```yml title=".github/workflows/deploy.yml"
name: Deploy to GitHub Pages
@ -462,6 +546,8 @@ jobs:
- name: Test build website
run: yarn build
```
</TabItem>
</Tabs>
</details>