google / docsy

A set of Hugo doc templates for launching open source content.
https://docsy.dev
Apache License 2.0
2.62k stars 904 forks source link

Deployment on GitHub Pages with Workflow action fails #1975

Closed benjaminpope closed 6 months ago

benjaminpope commented 6 months ago

Environment

Problem

I am trying to deploy this website, which is a clone of the example site, to GitHub Pages using the officially recommended hugo.yaml workflow. I have added the following lines to the workflow to try and match the instructions:

    steps:
      - name: install npm
        run: |
          npm install --save-dev autoprefixer
          npm install --save-dev postcss-cli
          npm install -D postcss

hugo server builds locally just fine on my M1 MacBook Pro, but when I push to GitHub I get the following error in the workflow:

hugo: downloading modules …
hugo: collected modules in 11142 ms
Start building sites … 
hugo v0.125.4-cc3574ef4f41fccbe88d9443ed066eb10867ada2+extended linux/amd64 BuildDate=2024-04-25T13:27:26Z VendorInfo=gohugoio
Total in 14208 ms
Error: error building site: POSTCSS: failed to transform "/scss/main.css" (text/css). Check your PostCSS installation; install with "npm install postcss-cli". See https://gohugo.io/hugo-pipes/postcss/: binary with name "npx" not found
Error: Process completed with exit code 1.

If I downgrade to v0.9.1 and try again, I get a different error

hugo: downloading modules …
hugo: collected modules in 22735 ms
Start building sites … 
hugo v0.125.4-cc3574ef4f41fccbe88d9443ed066eb10867ada2+extended linux/amd64 BuildDate=2024-04-25T13:27:26Z VendorInfo=gohugoio
ERROR render of "home" failed: "/tmp/hugo_cache_runner/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.1/layouts/_default/baseof.html:4:7": execute of template failed: template: home.html:4:7: executing "home.html" at <partial "head.html" .>: error calling partial: execute of template failed: html/template:partials/head.html:53:[16](https://github.com/aew10/website/actions/runs/8908963883/job/24465502306#step:8:17): no such template "_internal/google_analytics_async.html"
ERROR render of "section" failed: "/tmp/hugo_cache_runner/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.1/layouts/_default/baseof.html:4:7": execute of template failed: template: _default/list.html:4:7: executing "_default/list.html" at <partial "head.html" .>: error calling partial: execute of template failed: html/template:partials/head.html:53:16: no such template "_internal/google_analytics_async.html"
Total in 22793 ms
Error: error building site: render: failed to render pages: render of "404" failed: "/tmp/hugo_cache_runner/modules/filecache/modules/pkg/mod/github.com/google/docsy@v0.9.1/layouts/_default/baseof.html:4:7": execute of template failed: template: 404.html:4:7: executing "404.html" at <partial "head.html" .>: error calling partial: execute of template failed: html/template:partials/head.html:53:16: no such template "_internal/google_analytics_async.html"

What is going on? Is there a workflow that anyone has that will just work for a GitHub Action?

deining commented 6 months ago

What is going on? Is there a workflow that anyone has that will just work for a GitHub Action?

To run docsy with latest hugo version 0.125.4, some tweaking is needed, see #1973 for details. I authored this PR which hopefully solves your problem. Can you give it a try, please?

benjaminpope commented 6 months ago

Thank you - really appreciate your help!

Merged the PR - the workflow still fails. We get the error message about npx again:

Run hugo \
hugo: downloading modules …
hugo: collected modules in 24199 ms
Start building sites … 
hugo v0.125.4-cc3574ef4f41fccbe88d9443ed066eb10867ada2+extended linux/amd64 BuildDate=2024-04-25T[13](https://github.com/aew10/website/actions/runs/8918256442/job/24492572389#step:8:14):27:26Z VendorInfo=gohugoio

Total in 27202 ms
Error: error building site: POSTCSS: failed to transform "/scss/main.css" (text/css). Check your PostCSS installation; install with "npm install postcss-cli". See https://gohugo.io/hugo-pipes/postcss/: binary with name "npx" not found
Error: Process completed with exit code 1.

I can't see any Actions run on your fork - did it work for you?

deining commented 6 months ago

I revisited this issue and I was able to make it work by simply adding actions/setup-node to the workflow. See my second, improved pull request and my successful action run in my own repo. Also, have a look at the deployed site and enjoy!

benjaminpope commented 6 months ago

Thank you - it works perfectly! This is really helpful! Perhaps would be of general interest to GitHub Actions users.

deining commented 6 months ago

Thank you - it works perfectly! This is really helpful!

Glad I could help out.

Perhaps would be of general interest to GitHub Actions users.

Yes indeed. I addressed this with my PR #1435, which has an approval already. This PR is waiting for merging for more than one year already 😞. Please note that this PR takes a different approach (which is more straightforward IMO).