A transparent, extensible static site generator
Automatic Deployment With Sourcehut and Netlify
This website is source-hosted on Sourcehut, and the site itself is served by Netlify. I’ve just added a Sourcehut [Build Manifest][manifest] which will automatically generate the site using Bagatto and deploy it, without my having to maintain a repo of the generated files.
The build file in my Sourcehut Repo.
image: archlinux
packages:
- curl
- netlify
- htmlmin
- yuicompressor
sources:
- https://git.sr.ht/~subsetpark/bagatto
secrets:
- {{SOURCEHUT SECRET UUID}}
environment:
NETLIFY_SITE_ID: {{NETLIFY SITE API ID}}
tasks:
- bag: |
curl https://bagatto.co/builds/bag-x86_64-static.v0-6-1.tar.gz -o bag.tar.gz
tar -xvf bag.tar.gz
mv bag {{REPO NAME}}/
- build: |
cd {{REPO NAME}}
./bag {{INDEX MODULE}}.janet
- deploy: |
cd {{REPO NAME}}
# Only deploy on master.
if [ "$(git rev-parse origin/master)" != "$(git rev-parse HEAD)" ]; then \
complete-build; \
fi
# Source the secrets in ~/.buildsecrets as environment variables.
{
set +x
. ~/.buildsecrets
set -x
}
# Set the Netlify environment variable.
export NETLIFY_AUTH_TOKEN
# Call the deploy.
netlify deploy --site=$NETLIFY_SITE_ID --dir={{OUTPUT DIRECTORY}} --prod
Sourcehut has pretty solid build documentation, so I won’t explain the overall format of the file. Rather, I’ll touch on the parts specific to deploying a Bagatto site.
htmlmin
and yuicompressor
are called by this site’s index module. If you’re adapting this build manifest, you don’t necessarily need them. netlify
, on the other hand, is the Netlify command line client, and curl
is used to download the Bagatto binary.
This site includes documentation from the main Bagatto repo. You may not need to specify any other sources to build your site.
I have a Sourcehut Secret which contains my Netlify Personal Access Token. This is a necessary step for being able to execute the Netlify command line tool.
~/.buildsecrets
, though you can name it whatever you like.NETLIFY_AUTH_TOKEN=<your token value>
. The netlify CLI application will look for this environment variable when it runs.secrets
section of your build file.Once you’ve done this once, you can simply refer to ~/.buildsecrets
in all of your Bagatto builds; you will reuse the same auth token for all Netlify commands.
Get the API ID of your Netlify site in the Site Information section of the general settings. This you can include as an environment variable in your build file.
The tasks
section downloads the bagatto binary, generates a site, and then deploys it using Netlify. It also includes a git branch check so that deployment only happens on master
.
You should be able to use this as a template for your own build file. Simply ensure that you’re referring to the correct Sourcehut repo name, index module filename, and output directory name, according to your settings.