This page describes the process for configuring automatic pulls when a push is made to a repository on ForgeJo. Uses forgejorunner and a script in .forgejo/workflows in the repository files.
Optional: Create a new user with a homefolder so the runner doesn't use the same SSH user as you.
- Copy and paste the following commands (Note: If using docker, change the podman commands and the socket to their docker equivalent):
mkdir forgerunner cd forgerunner mkdir data touch compose.yml echo "services: forgejo-runner: hostname: forgerunner image: code.forgejo.org/forgejo/runner:5.0.4 container_name: forgejorunner environment: DOCKER_HOST: unix:///var/run/podman/podman.sock user: 0:0 #Gives permission errors if not root. Can this be fixed somehow? volumes: - ./data:/data - /var/run/podman/podman.sock:/var/run/podman/podman.sock restart: unless-stopped command: forgejo-runner -c /data/config.yaml daemon" > compose.yml sudo podman-compose run --rm forgejo-runner 'forgejo-runner' 'generate-config' > data/config.yaml sudo podman-compose up -d sudo podman-compose run --rm forgejo-runner 'forgejo-runner' 'register'
- STOP and verify that something hasn't gone wrong at this step. Check the new config.yaml that was generated.
- Follow the prompts. Enter your forgejo url and runner token from YourRepo → Settings → Actions → Runners → Create new runner
- Check the runners list in your repository. It should show up as inactive.
- Navigate to your repo either in browser or locally and create a new file under .forgejo/workflows/ called “deploy.yml” (or name it whatever you prefer)
- Inside deploy.yml paste the following:
name: Auto Pull on: [push] #on: # push: # branches: # - 'main' jobs: deploy: runs-on: docker steps: - name: SSH Deploy uses: https://github.com/appleboy/ssh-action@v1 with: host: ${{ secrets.HOST_ADDRESS }} username: forgejo #$ {{ secrets.SSH_USER }} # key: ${{ secrets.SSH_PRIVATE_KEY }} script: | ls cd homeserver ${{ secrets.SCRIPT }}
- The variables used are stored in the settings of your repository under YourRepo → Settings → Actions → Secrets Make sure to create matching secrets or adjust the variables accordingly.
- Testing required: by commenting out the line “on: [push]” and un-commenting the lines beneath it, it should be possible to specify which branch is being checked for updates.
- Under “script: |” is the command line script that is run once an SSH connection is established. The SCRIPT secret contains the git pull command to update the repository locally. You can enter your credentials with this command by using the following syntax at the command line, replacing the capitalized words to whatever you need:
git pull https://USER:PASSWORD@forge.melm.xyz/USERNAME/REPONAME
Make sure your local repository is synced by pulling or pushing the changes. Now the script should automatically run on every push.