In GitHub Actions, how can I reuse workflows across multiple repositories? #175466
Select Topic AreaQuestion BodyI’m setting up GitHub Actions CI/CD pipelines for several repositories in my organization. Right now, each repository has almost the same workflow file (build, test, lint, etc.), and I’d like to avoid repeating the same YAML code in every repo. I read that it might be possible to create reusable workflows or templates, but I’m not fully sure how to configure them or how to reference them across different repositories. Can someone explain the correct way to:
Thanks in advance! 🙏 |
Replies: 4 comments 1 reply
|
You can reuse workflows by creating a reusable workflow in one repository and then calling it from others.
# .github/workflows/ci.yml
on:
workflow_call: # 👈 makes it reusable
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo "Running shared build..."
|
|
Great, Thanks for your reply! |
|
Its just annoying to have to see empty skeleton workflows on each repositories. It would be good if there was settings such as rulesets where PR workflows can be set at org level. |
|
✅ Step 1: Create a reusable workflow name: Reusable Workflow on: jobs: ✅ Step 2: Call the reusable workflow from another repository name: Use Reusable Workflow on: jobs: The reusable workflow repository must be public or in the same organization (with proper permissions). |
You can reuse workflows by creating a reusable workflow in one repository and then calling it from others.