skip to Main Content

I have an GitHub organization with free-to-use plan. I want to reuse some of the workflows in every repository. Thus I created a public repository in the organization named .github. I added this workflow for example:

name: PR Title Checker

on:
  pull_request_target:
    types:
      - opened
      - edited
      - synchronize
      - labeled
      - unlabeled

jobs:
  check:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Debug Message
        run: echo "Workflow is running..."

      - name: PR Title Checker
        uses: thehanimo/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          pass_on_octokit_error: false
          configuration_path: .github/pr-title-checker-config.json

I expected to see this running whenever I create a pull request on any other repositories in the organization. Isn’t that how it supposed to work?

For another example, I added a pull_request_template.md file into the .github repository and I’m able to see that pull request template when I try to create a PR on my other repository.

I checked the Actions Settings in the Organization Settings and they’re all enabled.
Any ideas?

2

Answers


  1. So the workflows in the .github repository won’t run automatically in other repositories unless they are referenced. You should use the workflow_call event in the reusable workflow definition and call it in other repositories. For example, this is how the workflow would look like in .github repo:-

    name: PR Title Checker
    
    on:
      workflow_call:
    
    jobs:
      check:
        runs-on: ubuntu-latest
    
        steps:
          - name: Checkout code
            uses: actions/checkout@v2
    
          - name: Debug Message
            run: echo "Workflow is running..."
    
          - name: PR Title Checker
            uses: thehanimo/[email protected]
            with:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
              pass_on_octokit_error: false
              configuration_path: .github/pr-title-checker-config.json
    

    and then the above workflow is called in other repos like <repo>/.github/workflows/pr-title-checker-caller.yml:-

    name: PR Title Checker
    
    on:
      pull_request_target:
        types:
          - opened
          - edited
    
    jobs:
      call-pr-title-checker:
        uses: <your-org>/.github/.github/workflows/pr-title-checker.yml@main
        secrets: inherit
    

    If you have any secrets need those can be inherited from parent workflow.

    Login or Signup to reply.
  2. Using Branch and Tag Rulesets you can configure required workflows to run, but only on push and pull_request triggers. You can configure a ruleset at the organization level for GitHub Enterprise and then have that ruleset apply to as many repos as you want. Unfortunately, for now, this only includes workflows that would trigger when something is pushed into a repo and none of the other triggers will work.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search