tj / staticgen

Static website generator that lets you use HTTP servers and frameworks you already know
MIT License
721 stars 13 forks source link

Usage in CI tools #17

Open jaymakes11 opened 3 years ago

jaymakes11 commented 3 years ago

This may be a dumb question, but is it possible to use staticgen to build sites within CI (continuous integration) tools, such as Netlify builds and/or Github Actions? It's non-obvious to me since it requires the site be to be accessible via a URL.

tj commented 3 years ago

yep! Basically staticgen will run the command you've configured, wait for your server to listen on the url (or port 3000 by default), and then start crawling and shut everything down after.

I believe there is some kind of race-condition though, at least with my site it gets stuck sometimes but worth a try! I haven't looked into that yet since I don't use CI at the moment

jaymakes11 commented 3 years ago

yep! Basically staticgen will run the command you've configured, wait for your server to listen on the url (or port 3000 by default), and then start crawling and shut everything down after.

Great to hear! Thanks for confirming.

Being able to install staticgen via NPM would also help with using it in CI/CD contexts. I'm not a Go developer, but I know this is possible with esbuild (which is also written in Go). I think this would make for a nice enhancement.

tj commented 3 years ago

ahh you don't need NPM or Go installed, just curl which is already on most systems:

curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | sh

It pulls down a binary of staticgen

jaymakes11 commented 3 years ago

Yes, that works, but at at least in the context of Netlify, requires some creative thinking. The best I've so far to come up with:

[build]
   command = "curl -sf https://gobinaries.com/tj/staticgen/cmd/staticgen | PREFIX='.' sh && mv staticgen node_modules/.bin && npm run build"

That took a lot of trial and error (e.g. logging in the Netlify build output to see what the path is at different points in the build process). There may very well be a cleaner way.

If a project is already using NPM to manage dependencies (nearly all of mine do), being able to npm install staticgen would be much cleaner/simpler. Is this something you'd consider supporting, @tj?

tj commented 3 years ago

ahh yeah I guess if you're using it from NPM scripts that's more of a pain, I'd just use it stand-alone personally but I'm not against having an npm package as well