Reusable Workflows — reusing workflows across repositories.
Reusable workflow (in the infra repository):
1name: Deploy to K8s2on:3 workflow_call:4 inputs:5 environment:6 required: true7 type: string8 image_tag:9 required: true10 type: string11 secrets:12 kubeconfig:13 required: true1415jobs:16 deploy:17 runs-on: ubuntu-latest18 steps:19 - run: |20 echo "${{ secrets.kubeconfig }}" > kubeconfig21 export KUBECONFIG=kubeconfig22 kubectl set image deployment/myapp myapp=myapp:${{ inputs.image_tag }} -n ${{ inputs.environment }}
Calling from another repository:
1jobs:2 deploy:3 needs: build4 uses: org/infra/.github/workflows/deploy.yml@main5 with:6 environment: production7 image_tag: ${{ needs.build.outputs.image_tag }}8 secrets:9 kubeconfig: ${{ secrets.KUBECONFIG }}
Advantages: DRY, centralized logic, easy updates.