This uses the Forgejo API to let a workflow in one repo (the from
repo) to dispatch a workflow in another (the to
repo).
Setup requirements
Generate an access token scoped with write privileges to the repo.
Secrets
Create the following repository secrets in the from
repo:
Secret Name | Description | Example |
---|---|---|
REPO_NAME | The owner and name of the to repo (the path) | john/my_repo |
REPO_REF | Name of the branch in the to repo | main |
WORKFLOW_FILE | File name of the workflow to execute in the to repo | target_workflow.yaml |
REPO_TOKEN | The access token generated above | abc123 |
”from” workflow
# .forgejo/workflows/trigger.yaml
name: Trigger remote workflow
on:
push: # triggers for all pushes, adjust as needed
defaults:
run:
shell: bash
jobs:
trigger:
runs-on: docker
steps:
- name: Remote trigger
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.REPO_TOKEN }}" \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
"https://forgejo.example.com/api/v1/repos/${{ secrets.REPO_NAME }}/actions/workflows/${{ secrets.WORKFLOW_FILE }}/dispatches" \
-d '{"ref": "{{ secrets.REPO_REF}}"}'
”to” workflow
# .forgejo/workflows/target_workflow.yaml
name: Workflow which is triggered remotely
on:
repository_dispatch: # triggers from API dispatches
defaults:
run:
shell: bash
jobs:
execute:
runs-on: docker
steps:
- name: remotely triggered run
run: |
echo "repository_dispatch triggered"
See also: