|
1 | | -# Sample workflow for building and deploying a Hugo site to GitHub Pages |
2 | | -name: Deploy Hugo site to Pages |
3 | | - |
| 1 | +name: Hugo Build and deploy |
4 | 2 | on: |
5 | | - # Runs on pushes targeting the default branch |
6 | 3 | push: |
7 | | - branches: ["main"] |
8 | | - |
9 | | - # Allows you to run this workflow manually from the Actions tab |
| 4 | + branches: |
| 5 | + - main |
10 | 6 | workflow_dispatch: |
11 | | - |
12 | | -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
13 | 7 | permissions: |
14 | 8 | contents: read |
15 | 9 | pages: write |
16 | 10 | 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. |
20 | 11 | concurrency: |
21 | | - group: "pages" |
| 12 | + group: pages |
22 | 13 | cancel-in-progress: false |
23 | | - |
24 | | -# Default to bash |
25 | 14 | defaults: |
26 | 15 | run: |
27 | 16 | shell: bash |
28 | | - |
29 | 17 | jobs: |
30 | | - # Build job |
31 | 18 | build: |
32 | 19 | runs-on: ubuntu-latest |
33 | 20 | env: |
34 | | - HUGO_VERSION: 0.148.0 |
| 21 | + DART_SASS_VERSION: 1.93.2 |
| 22 | + GO_VERSION: 1.25.1 |
| 23 | + HUGO_VERSION: 0.151.0 |
| 24 | + NODE_VERSION: 22.18.0 |
| 25 | + TZ: Europe/Oslo |
35 | 26 | 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 |
42 | 27 | - name: Checkout |
43 | | - uses: actions/checkout@v4 |
| 28 | + uses: actions/checkout@v5 |
44 | 29 | with: |
45 | 30 | 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 }} |
46 | 41 | - name: Setup Pages |
47 | 42 | id: pages |
48 | 43 | uses: actions/configure-pages@v5 |
49 | | - - name: Setup Node.js |
50 | | - uses: actions/setup-node@v4 |
| 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 | + - 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 |
| 81 | + run: | |
| 82 | + hugo \ |
| 83 | + --gc \ |
| 84 | + --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 |
51 | 90 | with: |
52 | | - node-version: '20' |
53 | | - cache: 'npm' |
54 | | - - name: Install dependencies |
55 | | - run: npm ci |
56 | | - - name: Build with npm |
57 | | - env: |
58 | | - HUGO_CACHEDIR: ${{ runner.temp }}/hugo_cache |
59 | | - HUGO_ENVIRONMENT: production |
60 | | - HUGO_BASEURL: ${{ steps.pages.outputs.base_url }}/ |
61 | | - run: npm run build |
| 91 | + path: ${{ runner.temp }}/hugo_cache |
| 92 | + key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
62 | 93 | - name: Upload artifact |
63 | 94 | uses: actions/upload-pages-artifact@v3 |
64 | 95 | with: |
65 | | - path: ./exampleSite/public |
66 | | - |
67 | | - # Deployment job |
| 96 | + path: ./public |
68 | 97 | deploy: |
69 | 98 | environment: |
70 | 99 | name: github-pages |
|
0 commit comments