peaceiris / actions-gh-pages

GitHub Actions for GitHub Pages 🚀 Deploy static files and publish your site easily. Static-Site-Generators-friendly.
https://github.com/marketplace/actions/github-pages-action
MIT License
4.65k stars 368 forks source link

support: Actions/cache for Hugo modules with Hugo v0.127.0 #1081

Closed Zer0xxxx closed 3 months ago

Zer0xxxx commented 3 months ago

Checklist

Describe your question

Hello!

I'm running on Hugo v0.127.0 And I'm also using a Hugo module (Blowfish).

From the docs of this GitHub Action:

    path: /home/runner/.cache/hugo_cache    # <-- with hugo version v0.116.0 and above
    # path: /tmp/hugo_cache                 # <-- with hugo version < v0.116.0

But, I've checked both folders in my CI, and don't find any of them. I've even fired a ls -R /home/runner/ And a ls -R .

And I don't find any "hugo_cache"

It's weird, since I'm not using the --gc flag at the build of my Hugo website. I did everything exactly as it is documented.

Also, this is quite annoying, because the download of the module is likely 78% of the duration of my CI/CD...

hugo: collected modules in 17347 ms

Also:

ls: cannot access '/home/runner/.cache/hugo_cache': No such file or directory ls: cannot access '/home/runner/.cache': No such file or directory

And ls /tmp gives:

clr-debug-pipe-1618-22959-in
clr-debug-pipe-1618-22959-out
clr-debug-pipe-1635-23181-in
clr-debug-pipe-1635-23181-out
clr-debug-pipe-592-844-in
clr-debug-pipe-592-844-out
dotnet-diagnostic-1618-22959-socket
dotnet-diagnostic-1635-23181-socket
dotnet-diagnostic-592-844-socket
hugo_cache_runner
snap-private-tmp
systemd-private-400d24fb912f435db1794cbdf1e0ff7c-chrony.service-PXMl8E
systemd-private-400d24fb912f435db1794cbdf1e0ff7c-haveged.service-QZT8c2
systemd-private-400d24fb912f435db1794cbdf1e0ff7c-systemd-logind.service-E0KxuY
systemd-private-400d24fb912f435db1794cbdf1e0ff7c-systemd-resolved.service-ZNa6Mx
www-data-temp-aspnet-0

There is a hugo_cache_runner here, but it seems to be pointless in this context...

Any clue?

Relevant links

Public repository: https://github.com/chill-utility/chill-utility.github.io YAML config: https://github.com/chill-utility/chill-utility.github.io/blob/main/.github/workflows/deploy.yml Hugo's forum topic: https://discourse.gohugo.io/t/how-to-cache-hugo-modules-in-a-github-action/50334

Relevant log output

No response

Additional context.

No response

Zer0xxxx commented 3 months ago

Oh, okay, finally found the right way to do it. Just defining the env variable and rely on it seems to be perfectly safe.

name: GitHub Pages

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

jobs:
  deploy:
    runs-on: ubuntu-latest
    env:
      HUGO_VERSION: 0.127.0
      HUGO_CACHEDIR: /tmp/hugo_cache
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v4
      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: ${{ env.HUGO_VERSION }}

      - uses: actions/cache@v4
        with:
          path: ${{ env.HUGO_CACHEDIR }}
          key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-hugomod-

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        if: github.ref == 'refs/heads/main'
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./public
peaceiris commented 3 months ago

Looks good 👍

Hugo can define its cache directory by HUGO_CACHEDIR env. https://gohugo.io/getting-started/configuration/#configure-cachedir

Zer0xxxx commented 3 months ago

Looks good 👍

Hugo can define its cache directory by HUGO_CACHEDIR env. https://gohugo.io/getting-started/configuration/#configure-cachedir

I think the documentation snippet (from the ⭐️ Caching Hugo Modules tips section) should be updated with the HUGO_CACHEDIR env parameter directly set to some path, in order to harmonize all of this and avoid confusion about the use of the action. What are your thoughts?

peaceiris commented 3 months ago

I agree! Could you open your PR to fix the section on https://github.com/peaceiris/actions-hugo?

Zer0xxxx commented 3 months ago

I agree! Could you open your PR to fix the section on https://github.com/peaceiris/actions-hugo?

At your service :orange_heart: