|
| 1 | +# Sample workflow for building and deploying a Hugo site to GitHub Pages |
| 2 | +name: Deploy Hugo site to Pages |
| 3 | + |
| 4 | +on: |
| 5 | + # Runs on pushes targeting the default branch |
| 6 | + push: |
| 7 | + 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 | + # GitHub-hosted runners automatically enable `set -eo pipefail` for Bash shells. |
| 29 | + shell: bash |
| 30 | + |
| 31 | +jobs: |
| 32 | + # Build job |
| 33 | + build: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + env: |
| 36 | + DART_SASS_VERSION: 1.89.2 |
| 37 | + HUGO_VERSION: 0.148.0 |
| 38 | + HUGO_ENVIRONMENT: production |
| 39 | + TZ: America/Los_Angeles |
| 40 | + steps: |
| 41 | + - name: Install Hugo CLI |
| 42 | + run: | |
| 43 | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb |
| 44 | + sudo dpkg -i ${{ runner.temp }}/hugo.deb |
| 45 | + - name: Install Dart Sass |
| 46 | + run: | |
| 47 | + wget -O ${{ runner.temp }}/dart-sass.tar.gz https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz |
| 48 | + tar -xf ${{ runner.temp }}/dart-sass.tar.gz --directory ${{ runner.temp }} |
| 49 | + mv ${{ runner.temp }}/dart-sass/ /usr/local/bin |
| 50 | + echo "/usr/local/bin/dart-sass" >> $GITHUB_PATH |
| 51 | + - name: Checkout |
| 52 | + uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + submodules: recursive |
| 55 | + fetch-depth: 0 |
| 56 | + - name: Setup Pages |
| 57 | + id: pages |
| 58 | + uses: actions/configure-pages@v5 |
| 59 | + - name: Install Node.js dependencies |
| 60 | + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" |
| 61 | + - name: Cache Restore |
| 62 | + id: cache-restore |
| 63 | + uses: actions/cache/restore@v4 |
| 64 | + with: |
| 65 | + path: | |
| 66 | + ${{ runner.temp }}/hugo_cache |
| 67 | + key: hugo-${{ github.run_id }} |
| 68 | + restore-keys: |
| 69 | + hugo- |
| 70 | + - name: Configure Git |
| 71 | + run: git config core.quotepath false |
| 72 | + - name: Build with Hugo |
| 73 | + run: | |
| 74 | + hugo \ |
| 75 | + --gc \ |
| 76 | + --minify \ |
| 77 | + --baseURL "${{ steps.pages.outputs.base_url }}/" \ |
| 78 | + --cacheDir "${{ runner.temp }}/hugo_cache" |
| 79 | + - name: Cache Save |
| 80 | + id: cache-save |
| 81 | + uses: actions/cache/save@v4 |
| 82 | + with: |
| 83 | + path: | |
| 84 | + ${{ runner.temp }}/hugo_cache |
| 85 | + key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 86 | + - name: Upload artifact |
| 87 | + uses: actions/upload-pages-artifact@v3 |
| 88 | + with: |
| 89 | + path: ./public |
| 90 | + |
| 91 | + # Deployment job |
| 92 | + deploy: |
| 93 | + environment: |
| 94 | + name: github-pages |
| 95 | + url: ${{ steps.deployment.outputs.page_url }} |
| 96 | + runs-on: ubuntu-latest |
| 97 | + needs: build |
| 98 | + steps: |
| 99 | + - name: Deploy to GitHub Pages |
| 100 | + id: deployment |
| 101 | + uses: actions/deploy-pages@v4 |
0 commit comments