|
1 | | -name: Hugo Build and deploy |
| 1 | +# Sample workflow for building and deploying a Hugo site to GitHub Pages |
| 2 | +name: Deploy Hugo site to Pages |
| 3 | + |
2 | 4 | on: |
| 5 | + # Runs on pushes targeting the default branch |
3 | 6 | push: |
4 | | - branches: |
5 | | - - main |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | + # Allows you to run this workflow manually from the Actions tab |
6 | 10 | workflow_dispatch: |
| 11 | + |
| 12 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
7 | 13 | permissions: |
8 | 14 | contents: read |
9 | 15 | pages: write |
10 | 16 | id-token: write |
| 17 | + |
| 18 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 19 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
11 | 20 | concurrency: |
12 | | - group: pages |
| 21 | + group: "pages" |
13 | 22 | cancel-in-progress: false |
| 23 | + |
| 24 | +# Default to bash |
14 | 25 | defaults: |
15 | 26 | run: |
16 | 27 | shell: bash |
| 28 | + |
17 | 29 | jobs: |
| 30 | + # Build job |
18 | 31 | build: |
19 | 32 | runs-on: ubuntu-latest |
20 | 33 | env: |
21 | | - DART_SASS_VERSION: 1.93.2 |
22 | | - GO_VERSION: 1.25.1 |
23 | 34 | HUGO_VERSION: 0.151.0 |
24 | | - NODE_VERSION: 22.18.0 |
25 | | - TZ: Europe/Oslo |
26 | 35 | steps: |
| 36 | + - name: Install Hugo CLI |
| 37 | + run: | |
| 38 | + wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ |
| 39 | + && sudo dpkg -i ${{ runner.temp }}/hugo.deb |
| 40 | + - name: Install Dart Sass |
| 41 | + run: sudo snap install dart-sass |
27 | 42 | - name: Checkout |
28 | | - uses: actions/checkout@v5 |
| 43 | + uses: actions/checkout@v4 |
29 | 44 | with: |
30 | 45 | submodules: recursive |
31 | | - fetch-depth: 0 |
32 | | - - name: Setup Go |
33 | | - uses: actions/setup-go@v5 |
34 | | - with: |
35 | | - go-version: ${{ env.GO_VERSION }} |
36 | | - cache: false |
37 | | - - name: Setup Node.js |
38 | | - uses: actions/setup-node@v4 |
39 | | - with: |
40 | | - node-version: ${{ env.NODE_VERSION }} |
41 | 46 | - name: Setup Pages |
42 | 47 | id: pages |
43 | 48 | uses: actions/configure-pages@v5 |
44 | | - - name: Create directory for user-specific executable files |
45 | | - run: | |
46 | | - mkdir -p "${HOME}/.local" |
47 | | - - name: Install Dart Sass |
48 | | - run: | |
49 | | - curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
50 | | - tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
51 | | - rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
52 | | - echo "${HOME}/.local/dart-sass" >> "${GITHUB_PATH}" |
53 | | - - name: Install Hugo |
54 | | - run: | |
55 | | - curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" |
56 | | - mkdir "${HOME}/.local/hugo" |
57 | | - tar -C "${HOME}/.local/hugo" -xf "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" |
58 | | - rm "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" |
59 | | - echo "${HOME}/.local/hugo" >> "${GITHUB_PATH}" |
60 | | - - name: Verify installations |
61 | | - run: | |
62 | | - echo "Dart Sass: $(sass --version)" |
63 | | - echo "Go: $(go version)" |
64 | | - echo "Hugo: $(hugo version)" |
65 | | - echo "Node.js: $(node --version)" |
66 | 49 | - name: Install Node.js dependencies |
67 | | - run: | |
68 | | - [[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true |
69 | | - - name: Configure Git |
70 | | - run: | |
71 | | - git config core.quotepath false |
72 | | - - name: Cache restore |
73 | | - id: cache-restore |
74 | | - uses: actions/cache/restore@v4 |
75 | | - with: |
76 | | - path: ${{ runner.temp }}/hugo_cache |
77 | | - key: hugo-${{ github.run_id }} |
78 | | - restore-keys: |
79 | | - hugo- |
80 | | - - name: Build the site |
| 50 | + working-directory: ./exampleSite |
| 51 | + run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" |
| 52 | + - name: Build with Hugo |
| 53 | + working-directory: ./exampleSite |
| 54 | + env: |
| 55 | + HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache |
| 56 | + HUGO_ENVIRONMENT: production |
81 | 57 | run: | |
82 | 58 | hugo \ |
83 | | - --gc \ |
84 | 59 | --minify \ |
85 | | - --baseURL "${{ steps.pages.outputs.base_url }}/" \ |
86 | | - --cacheDir "${{ runner.temp }}/hugo_cache" |
87 | | - - name: Cache save |
88 | | - id: cache-save |
89 | | - uses: actions/cache/save@v4 |
90 | | - with: |
91 | | - path: ${{ runner.temp }}/hugo_cache |
92 | | - key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 60 | + --baseURL "${{ steps.pages.outputs.base_url }}/" |
93 | 61 | - name: Upload artifact |
94 | 62 | uses: actions/upload-pages-artifact@v3 |
95 | 63 | with: |
96 | | - path: ./public |
| 64 | + path: ./exampleSite/public |
| 65 | + |
| 66 | + # Deployment job |
97 | 67 | deploy: |
98 | 68 | environment: |
99 | 69 | name: github-pages |
|
0 commit comments