~adnano/adnano.co

ref: 4783f9fe192c637cdec61d4a06cf69ec7343ad11 adnano.co/content/2020-05-27-sourcehut-netlify.gmi -rw-r--r-- 1.8 KiB
4783f9feAdnan Maolood Fix content titles 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
---
title: Publish your Netlify site with Sourcehut builds
---

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.

```yml
# .build.yml
image: alpine/edge
packages:
	- curl
	- hugo
	- zip
secrets:
	# The id of your Netlify token build secret
	- netlify-token-secret-id
sources:
	# The repository of your site
	- https://git.sr.ht/~user/site
tasks:
	# Build the site
	# Put instructions for building your site here
	- build: |
			cd site
			hugo
	# Zip up the site before uploading
	- zip: |
			zip -r website.zip site/public
	# Upload the site zip with the Netlify API
	# Make sure to replace site.netlify.com with your site subdomain
	- upload: |
			curl -f \
				-H "Content-Type: application/zip" \
				-H "Authorization: Bearer $(cat .netlify_token)" \
				--data-binary "@website.zip" \
				https://api.netlify.com/api/v1/sites/site.netlify.com/deploys
```

Push your changes and your site should start building automatically.