iTranslated by AI
Cross-Repository Integration with GitHub Actions (Self-hosted Runner + GitHub App)
Overview
I have implemented a configuration that allows invoking Actions in an IaC repository from an application repository's Actions in an environment where application repositories and IaC repositories are managed separately within an Organization.
Environment
- GitHub Organization (multiple repositories)
- Self-hosted Runner (Docker container on a private server)
- Workflow invocation from an application repository to an IaC repository is required
Conclusion First
✅ What I did
- Created a Runner Group at the Organization level to centralize runners
- Achieved cross-repository invocation using
workflow_call - Solved the checkout issue for external repositories by issuing a token using a GitHub App
✅ Benefits
- Freed from repository-level runner management
- Deployment workflow became simpler, improving work efficiency
Goal
[App Repository] [IaC Repository]
| |
| workflow_call |
+-------------------------->|
| Execute deployment process
v
[Production Server]
After the application build is complete, I want to automatically trigger the deployment workflow in the IaC repository.
Challenge 1: Complex Runner Management
Symptoms
Management was becoming complex because I had registered individual Self-hosted Runners in each repository.
- Adding/removing runners had to be done in each repository
- Secrets were duplicated across multiple repositories
Solution
Create a Runner Group at the Organization level
- Go to Organization Settings → Actions → Runner groups to create a new group
- Associate Self-hosted Runners with that group
- Update the
runs-onproperty in the workflow
# Before: Repository-level runner
runs-on: [self-hosted, Linux, X64]
# After: Specifying Organization Runner Group
runs-on:
group: your-runner-group-name
labels: [self-hosted, Linux, X64]
I also migrated Secrets from repository-level to Organization Secrets.
Challenge 2: Cannot checkout a different repository with workflow_call
Symptoms
When invoking a workflow in the IaC repository using workflow_call, the issue occurred where the caller application repository was cloned.
# App repository side
jobs:
deploy:
uses: org/iac-repo/.github/workflows/deploy.yaml@master
secrets: inherit
When actions/checkout@v4 is executed in the IaC repository's workflow, the application repository is cloned instead of the IaC repository...
Cause
When invoked via workflow_call, the GITHUB_TOKEN only has the scope of the caller repository.
Therefore, even if you explicitly specify the IaC repository, checkout fails because there are no access permissions.
Solutions Considered
| Method | Evaluation |
|---|---|
| PAT (Personal Access Token) | ❌ Not recommended as it is tied to an individual |
| Deploy Key | △ Possible for 1-on-1, but management is complex for multiple repos |
| GitHub App | ✅ Recommended. Fine-grained permission control, auditable |
Solution: Create a GitHub App
1. Create a GitHub App in the Organization
- Repository permissions → Contents: Read-only
- Webhook is not required, so turn it OFF
- Install it in the target repositories
2. Issue a token in the workflow and checkout
steps:
- name: Generate installation access token
id: generate_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
repositories: iac-repo # Repository you want to checkout
- name: Checkout IaC repository
uses: actions/checkout@v4
with:
repository: org/iac-repo
token: ${{ steps.generate_token.outputs.token }}
This allows you to checkout the correct repository even via workflow_call.
Final Configuration
[App Repo: Actions Trigger]
|
| workflow_call
v
[IaC Repo: Deployment Workflow]
|
| Issue token with GitHub App
| → Checkout IaC repo
v
[Execute deployment process]
|
v
[Deploy to server]
Key Points
- Share runners across the entire Organization with Runner Groups
- Secure cross-repository access with GitHub Apps
- Inherit caller's Secrets with
secrets: inherit
Results
- The deployment flow has become simpler
- The execution time of Actions remains the same, but management and operation have become easier
- Runners can now be managed centrally
Lessons Learned
-
Understand the scope of
GITHUB_TOKEN- In
workflow_call, it becomes the scope of the caller repository - Separate authentication is required to access other repositories
- In
-
GitHub Apps are safer than PATs
- Not tied to individuals
- Easy to apply the principle of least privilege
- Appears in audit logs
-
Centralize management with Runner Groups
- Managing runners at the repo level is painful
- It is easier to aggregate them at the Organization level
Notes
Don't forget to organize old resources after the migration.
- Repository-level Secrets → After migrating to Org Secrets, delete old Secrets
- Repository-level Runners → After migrating to Organization Runner Groups, delete old Runners
If you leave them, it becomes unclear which is actually being used in production, leading to management confusion. Perform cleanup promptly after the migration is complete.
Closing
There is little information available on cross-repository coordination in Self-hosted Runner environments, so it involved a lot of trial and error.
Ideally, there might have been a simpler configuration, but it was a good experience to be able to realize efficiency gains with minimal changes while leveraging the existing environment.
I need to re-acknowledge the importance of "finding the optimal solution within constraints."
Discussion