Publish your Netlify site with Sourcehut builds

2020-05-27 on

Sourcehut is a great development tool. Unfortunately, Sourcehut does not yet provide static website hosting. Until they do, the second-best option for static website hosting is Netlify.

Update (2021-02-21): Sourcehut now provides static website hosting.

Netlify only offers easy integration with GitHub, GitLab, and Bitbucket. However, we can leverage Sourcehut's builds service to automatically build and publish our website on Netlify.

1. Create a Netlify access token

Go to your Netlify settings by clicking on your profile photo. Press Applications and create a new personal access token.

2. Add the access token to your Sourcehut builds secrets

Go to Sourcehut builds. Press Manage Secrets, then add a new secret. Paste in your Netlify access token. Choose the File secret type, then choose "~/.netlify_token" as the file path.

3. Add a build manifest to your repository

This build manifest builds the site with Hugo.

# .build.yml
image: alpine/edge
- curl
- hugo
- zip
# The id of your Netlify token build secret
- netlify-token-secret-id
# The repository of your site
# Build the site
# Put instructions for building your site here
- build: |
    cd site
# Zip up the site before uploading
- zip: |
    zip -r site/public
# Upload the site zip with the Netlify API
# Make sure to replace with your site subdomain
- upload: |
    curl -f \
      -H "Content-Type: application/zip" \
      -H "Authorization: Bearer $(cat .netlify_token)" \
      --data-binary "" \

Push your changes and your site should start building automatically.