|
1 | | -# Sample workflow for building and deploying a Hugo site to GitHub Pages |
2 | | -name: Deploy Hugo site to Pages |
| 1 | +name: GitHub Pages |
3 | 2 |
|
4 | 3 | on: |
5 | | - # Runs on pushes targeting the default branch |
6 | 4 | push: |
7 | 5 | branches: |
8 | | - - main |
9 | | - |
10 | | - # Allows you to run this workflow manually from the Actions tab |
11 | | - workflow_dispatch: |
12 | | - |
13 | | -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
14 | | -permissions: |
15 | | - contents: read |
16 | | - pages: write |
17 | | - id-token: write |
18 | | - |
19 | | -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
20 | | -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
21 | | -concurrency: |
22 | | - group: "pages" |
23 | | - cancel-in-progress: false |
24 | | - |
25 | | -# Default to bash |
26 | | -defaults: |
27 | | - run: |
28 | | - shell: bash |
| 6 | + - main # Set a branch to deploy |
| 7 | + pull_request: |
29 | 8 |
|
30 | 9 | jobs: |
31 | | - # Build job |
32 | | - build: |
33 | | - runs-on: ubuntu-latest |
| 10 | + deploy: |
| 11 | + runs-on: ubuntu-22.04 |
34 | 12 | env: |
35 | | - HUGO_VERSION: 0.138.0 |
| 13 | + HUGO_CACHEDIR: /tmp/hugo_cache |
| 14 | + concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
36 | 16 | steps: |
37 | | - - name: Install Hugo CLI |
38 | | - run: | |
39 | | - wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ |
40 | | - && sudo dpkg -i ${{ runner.temp }}/hugo.deb |
41 | | - - name: Install Dart Sass |
42 | | - run: sudo snap install dart-sass |
43 | | - - name: Checkout |
44 | | - uses: actions/checkout@v3 |
| 17 | + - uses: actions/checkout@v4 |
45 | 18 | with: |
46 | | - submodules: recursive |
47 | | - fetch-depth: 0 |
48 | | - - name: Setup Pages |
49 | | - id: pages |
50 | | - uses: actions/configure-pages@v3 |
51 | | - - name: Install Node.js dependencies |
52 | | - run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" |
53 | | - - name: Build with Hugo |
54 | | - env: |
55 | | - # For maximum backward compatibility with Hugo modules |
56 | | - HUGO_ENVIRONMENT: production |
57 | | - HUGO_ENV: production |
58 | | - run: | |
59 | | - hugo \ |
60 | | - --gc \ |
61 | | - --minify \ |
62 | | - --baseURL "${{ steps.pages.outputs.base_url }}/" |
63 | | - - name: Upload artifact |
64 | | - uses: actions/upload-pages-artifact@v1 |
| 19 | + submodules: true # Fetch Hugo themes (true OR recursive) |
| 20 | + fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod |
| 21 | + |
| 22 | + - name: Setup Hugo |
| 23 | + uses: peaceiris/actions-hugo@v3 |
65 | 24 | with: |
66 | | - path: ./public |
| 25 | + hugo-version: '0.119.0' |
| 26 | + # extended: true |
| 27 | + - uses: actions/cache@v4 |
| 28 | + with: |
| 29 | + path: ${{ env.HUGO_CACHEDIR }} # <- Use the same env variable just right here |
| 30 | + key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} |
| 31 | + restore-keys: | |
| 32 | + ${{ runner.os }}-hugomod- |
67 | 33 |
|
68 | | - # Deployment job |
69 | | - deploy: |
70 | | - environment: |
71 | | - name: github-pages |
72 | | - url: ${{ steps.deployment.outputs.page_url }} |
73 | | - runs-on: ubuntu-latest |
74 | | - needs: build |
75 | | - steps: |
76 | | - - name: Deploy to GitHub Pages |
77 | | - id: deployment |
78 | | - uses: actions/deploy-pages@v2 |
| 34 | + - name: Build |
| 35 | + run: hugo --minify |
| 36 | + |
| 37 | + - name: Deploy |
| 38 | + uses: peaceiris/actions-gh-pages@v3 |
| 39 | + if: github.ref == 'refs/heads/main' |
| 40 | + with: |
| 41 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 42 | + publish_dir: ./public |
0 commit comments