oss.zone

deploy your website with Forgejo Actions

  • by f1nn

while you can simply edit your site over ssh/sftp, it might be useful to automatically deploy your username.oss.zone site when you make changes to the git repo.

creating an SSH key#

the Forgejo workflow will need a dedicated SSH key to deploy changes to your user.

$ ssh-keygen -t ed25519

add ~/.ssh/id_ed25519.pub to your authorized SSH keys on id.oss.zone.

go to your repository on git.oss.zone and

DON'T use your actual SSH key and instead generate one specifically for Forgejo, as described above.

the workflow#

create a file called .forgejo/workflows/deploy.yaml in your git repo.

name: deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: set up SSH
        run: |
          mkdir -p ~/.ssh
          echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
          chmod 600 ~/.ssh/id_ed25519
          ssh-keyscan oss.zone >> ~/.ssh/known_hosts

      - name: deploy
        run: |
          ssh USERNAME@oss.zone << 'ENDSSH'
          set -e
          if [ -d ~/src/site ]; then
            git -C ~/src/site fetch origin
            git -C ~/src/site reset --hard origin/main
          else
            git clone https://git.oss.zone/USERNAME/REPO.git ~/src/site
          fi
          cd ~/src/site
          
          nix build
          
          rm -rf ~/public/html
          cp -rL result ~/public/html
          ENDSSH

obviously, replace USERNAME and REPO with proper values.

depending on your build setup, you might have to change the nix build command for whatever static site generator you use.

if you want to get some inspiration on how to build your site with nix, take a look at f1nn/blog.


you can commit the changes to your repo now and hopefully see the deployment succeed.