How to mirror from SourceHut to GitHub
Published
2 minutes readLast year I started to use SourceHut for all my personal projects and I also use its build-system for my CI/CD. But I'm not ready to say goodbye to GitHub yet, we use GitHub at work and stuff like my Deno modules rely on GitHub. The way I mirrored some of my repos up until now is by having multiple push-urls, but when I go to another computer I have to remember to setup all of those urls again.
How to setup a mirror
There aren't that many steps involved, so I'll be breif:
- Initialize a repository on SourceHut, or use an existsing one.
- Generate a new SSH-key, example:
ssh-keygen -t ed25519 -C "sourcehut"
- Copy the contents of your private key. On macOS:
cat ~/.ssh/sourcehut | pbcopy
- Go to builds.sr.ht/secrets.
- Add a new secret, give it a name "sourcehut ssh key", paste the private key in the secret field and specify that the secret is a "SSH key".
- Copy the hash of the generated secret.
- Add a new file to your repository,
.build.yml
.
Within your .build.yml
, add the following:
image: alpine/edge
secrets:
- <your-hashed-secret>
sources:
- git+ssh://git@git.sr.ht/~<username>/<repo>
tasks:
- check: |
cd <repo>
if [ "$(git rev-parse origin/main)" != "$(git rev-parse HEAD)" ]; then \
complete-build; \
fi
- mirror: |
cd <repo>
git remote add github git@github.com:<github_username>/<github_repo>.git
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
git push github main
Remember to change:
<your-hashed-secret>
<username>
<repo>
<github_username>
<github_repo>
The check
-task is there to ensure that we only mirror stuff commited to the
main
-branch, but this step is entirely optional – so you can remove that task
if you want.