This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

部署(Deploy)

将站点发布到网上。

1 - Github

使用 Github Action 部署站点。

核心项目: https://github.com/peaceiris/actions-hugo#readme

本项目为例: .github/workflows/gh-pages.yaml

 1name: GitHub Pages
 2
 3on:
 4  push:
 5    branches:
 6      - master  # Set a branch to deploy
 7  pull_request:
 8
 9jobs:
10  deploy:
11    runs-on: ubuntu-22.04
12    concurrency:
13      group: ${{ github.workflow }}-${{ github.ref }}
14    steps:
15      - uses: actions/checkout@v4
16        with:
17          submodules: recursive  # Fetch the Docsy theme
18          fetch-depth: 0         # Fetch all history for .GitInfo and .Lastmod
19
20      - name: Setup Hugo
21        uses: peaceiris/actions-hugo@v2
22        with:
23          hugo-version: '0.119.0'
24          extended: true
25
26      - name: Setup Node
27        uses: actions/setup-node@v3
28        with:
29          node-version: '18'
30          cache: 'npm'
31          # The action defaults to search for the dependency file (package-lock.json,
32          # npm-shrinkwrap.json or yarn.lock) in the repository root, and uses its
33          # hash as a part of the cache key.
34          # https://github.com/actions/setup-node/blob/main/docs/advanced-usage.md#caching-packages-data
35          cache-dependency-path: '**/package-lock.json'
36
37      - run: npm ci
38      - run: hugo --minify
39        env:
40          HUGO_ENV: production
41
42      - name: Deploy
43        uses: peaceiris/actions-gh-pages@v3
44        if: github.ref == 'refs/heads/master'
45        with:
46          github_token: ${{ secrets.GITHUB_TOKEN }}
47          publish_branch: gh-pages