|
1 | | -name: GitHub Pages |
| 1 | +# Sample workflow for building and deploying a Hugo site to GitHub Pages |
| 2 | +name: Deploy Hugo site to Pages |
2 | 3 |
|
3 | 4 | on: |
| 5 | + # Runs on pushes targeting the default branch |
4 | 6 | push: |
5 | 7 | branches: |
6 | 8 | - master |
7 | | - pull_request: |
| 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 |
8 | 29 |
|
9 | 30 | jobs: |
10 | | - pages: |
11 | | - name: Deploy to GitHub Pages |
| 31 | + # Build job |
| 32 | + build: |
12 | 33 | runs-on: ubuntu-latest |
| 34 | + env: |
| 35 | + HUGO_VERSION: 0.147.2 |
| 36 | + HUGO_ENVIRONMENT: production |
| 37 | + TZ: America/Los_Angeles |
13 | 38 | steps: |
| 39 | + - name: Install Hugo CLI |
| 40 | + run: | |
| 41 | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ |
| 42 | + && sudo dpkg -i ${{ runner.temp }}/hugo.deb |
| 43 | + - name: Install Dart Sass |
| 44 | + run: sudo snap install dart-sass |
14 | 45 | - name: Checkout |
15 | 46 | uses: actions/checkout@v4 |
16 | 47 | with: |
17 | | - submodules: true |
| 48 | + submodules: recursive |
18 | 49 | fetch-depth: 0 |
19 | | - |
20 | | - - name: Setup Hugo |
21 | | - uses: peaceiris/actions-hugo@v3 |
| 50 | + - name: Setup Pages |
| 51 | + id: pages |
| 52 | + uses: actions/configure-pages@v5 |
| 53 | + - name: Install Node.js dependencies |
| 54 | + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" |
| 55 | + - name: Cache Restore |
| 56 | + id: cache-restore |
| 57 | + uses: actions/cache/restore@v4 |
22 | 58 | with: |
23 | | - hugo-version: "latest" |
24 | | - extended: true |
25 | | - |
26 | | - - name: Clean public |
27 | | - working-directory: exampleSite |
28 | | - run: rm -rf ./public/* |
| 59 | + path: | |
| 60 | + ${{ runner.temp }}/hugo_cache |
| 61 | + key: hugo-${{ github.run_id }} |
| 62 | + restore-keys: |
| 63 | + hugo- |
| 64 | + - name: Configure Git |
| 65 | + run: git config core.quotepath false |
29 | 66 |
|
30 | | - - name: Build |
| 67 | + - name: Build with Hugo |
31 | 68 | working-directory: exampleSite |
32 | | - run: hugo --themesDir=../.. --minify --environment production -b https://ntk148v.github.io/shibui |
33 | | - |
34 | | - - name: Deploy |
35 | | - uses: peaceiris/actions-gh-pages@v3 |
36 | | - if: ${{ github.ref == 'refs/heads/master' }} |
| 69 | + run: | |
| 70 | + hugo \ |
| 71 | + --themesDir=../.. \ |
| 72 | + --gc \ |
| 73 | + --minify \ |
| 74 | + --baseURL "${{ steps.pages.outputs.base_url }}/" \ |
| 75 | + --cacheDir "${{ runner.temp }}/hugo_cache" |
| 76 | + - name: Cache Save |
| 77 | + id: cache-save |
| 78 | + uses: actions/cache/save@v4 |
37 | 79 | with: |
38 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
39 | | - publish_branch: gh-pages |
40 | | - publish_dir: ./exampleSite/public |
41 | | - |
42 | | - - name: Setup hugo cache |
43 | | - uses: actions/cache@v4 |
| 80 | + path: | |
| 81 | + ${{ runner.temp }}/hugo_cache |
| 82 | + key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 83 | + - name: Upload artifact |
| 84 | + uses: actions/upload-pages-artifact@v3 |
44 | 85 | with: |
45 | | - path: ./exampleSite/resources |
46 | | - key: ${{ runner.os }}-hugo-${{ hashFiles('./exampleSite/resources') }} |
47 | | - restore-keys: ${{ runner.os }}-hugo- |
| 86 | + path: ./public |
| 87 | + |
| 88 | + # Deployment job |
| 89 | + deploy: |
| 90 | + environment: |
| 91 | + name: github-pages |
| 92 | + url: ${{ steps.deployment.outputs.page_url }} |
| 93 | + runs-on: ubuntu-latest |
| 94 | + needs: build |
| 95 | + steps: |
| 96 | + - name: Deploy to GitHub Pages |
| 97 | + id: deployment |
| 98 | + uses: actions/deploy-pages@v4 |
0 commit comments