staticgen icon indicating copy to clipboard operation
staticgen copied to clipboard

Usage in CI tools

Open jaymakes11 opened this issue 4 years ago • 5 comments

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.

jaymakes11 avatar Dec 08 '20 15:12 jaymakes11

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

tj avatar Dec 09 '20 12:12 tj

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.

jaymakes11 avatar Dec 10 '20 12:12 jaymakes11

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

tj avatar Dec 11 '20 10:12 tj

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?

jaymakes11 avatar Dec 11 '20 14:12 jaymakes11

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

tj avatar Dec 14 '20 11:12 tj