|
| 1 | +name: Deploy Hugo Site To GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + # run on pushes, targeting the default branch |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | + # allow the workflow to be started manually from the GitHub Actions tab |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +# set permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + pages: write |
| 16 | + id-token: write |
| 17 | + |
| 18 | +# allow only one concurrent deployment, skipping runs queued between the run in progress and the latest run queued |
| 19 | +# however, do not cancel in-progress runs, in order to allow these production deployments to complete |
| 20 | +concurrency: |
| 21 | + group: "pages" |
| 22 | + cancel-in-progress: false |
| 23 | + |
| 24 | +# default to bash shell |
| 25 | +defaults: |
| 26 | + run: |
| 27 | + shell: bash |
| 28 | + |
| 29 | +jobs: |
| 30 | + build: |
| 31 | + runs-on: ubuntu-latest |
| 32 | + env: |
| 33 | + HUGO_VERSION: 0.147.3 |
| 34 | + HUGO_ENVIRONMENT: production |
| 35 | + TZ: Europe/London |
| 36 | + 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: Check Out Solution |
| 44 | + uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + submodules: recursive |
| 47 | + fetch-depth: 0 |
| 48 | + - name: Configure Pages |
| 49 | + id: pages |
| 50 | + uses: actions/configure-pages@v5 |
| 51 | + - name: Install Node.JS Dependencies |
| 52 | + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" |
| 53 | + - name: Restore Cache |
| 54 | + id: cache-restore |
| 55 | + uses: actions/cache/restore@v4 |
| 56 | + with: |
| 57 | + path: | |
| 58 | + ${{ runner.temp }}/hugo_cache |
| 59 | + key: hugo-${{ github.run_id }} |
| 60 | + restore-keys: |
| 61 | + hugo- |
| 62 | + - name: Configure Git |
| 63 | + run: git config core.quotepath false |
| 64 | + - name: Build With Hugo |
| 65 | + run: | |
| 66 | + hugo \ |
| 67 | + --gc \ |
| 68 | + --minify \ |
| 69 | + --baseURL "${{ steps.pages.outputs.base_url }}/" \ |
| 70 | + --cacheDir "${{ runner.temp }}/hugo_cache" |
| 71 | + - name: Save Cache |
| 72 | + id: cache-save |
| 73 | + uses: actions/cache/save@v4 |
| 74 | + with: |
| 75 | + path: | |
| 76 | + ${{ runner.temp }}/hugo_cache |
| 77 | + key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 78 | + - name: Upload Pages Artefact |
| 79 | + uses: actions/upload-pages-artifact@v3 |
| 80 | + with: |
| 81 | + path: ./public |
| 82 | + |
| 83 | + deploy: |
| 84 | + environment: |
| 85 | + name: github-pages |
| 86 | + url: ${{ steps.deployment.outputs.page_url }} |
| 87 | + runs-on: ubuntu-latest |
| 88 | + needs: build |
| 89 | + steps: |
| 90 | + - name: Deploy To GitHub Pages |
| 91 | + id: deployment |
| 92 | + uses: actions/deploy-pages@v4 |
0 commit comments