Sometimes cloning a repository doesn't require a complex dependency tree. Plain git is enough!
It's possible to leverate the forgejo context for the information needed to clone. The gotcha is that forgejo.server_url contains the protocol (ie. https://). You need to strip that before passing to Git:
- name: Checkout
run: |
SERVER="${{ forgejo.server_url }}"
git clone --depth=1 --branch "${{ forgejo.ref_name }}" \
"https://x-access-token:${{ secrets.FORGEJO_TOKEN }}@${SERVER#https://}/${{ forgejo.repository }}" .
Gladly, I run a self-hosted forgejo-runner configured through NixOS1. I have added a FORGEJO_DOMAIN environment variable to avoid having to strip the protocol out of FORGEJO_SERVER_URL every time:
services.forgejo-runner = {
instances.joan = {
# ...
settings = {
runner = {
# ...
envs = {
# hardcode it or pick the domain from the forgejo configuration `config.services.forgejo.settings.server.DOMAIN`.
FORGEJO_DOMAIN = "git.example.com";
};
};
};
};
};
Checking out gets a bit simpler:
- name: Checkout
run: |
git clone --depth=1 --branch "${{ forgejo.ref_name }}" \
"https://x-access-token:${{ secrets.FORGEJO_TOKEN }}@$FORGEJO_DOMAIN/${{ forgejo.repository }}" .