Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trigger downstream package CI jobs on new releases #207

Open
jjjermiah opened this issue Jan 30, 2025 · 1 comment
Open

trigger downstream package CI jobs on new releases #207

jjjermiah opened this issue Jan 30, 2025 · 1 comment

Comments

@jjjermiah
Copy link
Contributor

to avoid bugs in this package going unnoticed in downstream packages i.e #205 should find use gha dispatching to trigger the CI pipelines in the other packages, would make it a lot easier to catch bugs early

@jjjermiah
Copy link
Contributor Author

shoutout chatgpt:

name: Dispatch to Downstream Repos

on:
  release:
    types: [published]

jobs:
  notify_downstream:
    runs-on: ubuntu-latest
    steps:
      - name: Send repository dispatch to downstream projects
        env:
          GH_TOKEN: ${{ secrets.REPO_DISPATCH_TOKEN }}
        run: |
          repos=("downstream-repo1" "downstream-repo2" "downstream-repo3")
          for repo in "${repos[@]}"; do
            curl -X POST -H "Accept: application/vnd.github.v3+json" \
              -H "Authorization: token $GH_TOKEN" \
              https://api.github.com/repos/your-org/$repo/dispatches \
              -d '{"event_type": "core_package_release"}'
          done

Explanation:
• Runs when a new release is published.
• Sends a repository dispatch event to each downstream repo.
• Uses a GitHub personal access token (PAT) stored as REPO_DISPATCH_TOKEN.

  1. Set Up the GitHub PAT (REPO_DISPATCH_TOKEN)
    • Create a Personal Access Token (PAT) with repo scope.
    • Add it as a secret in the core package repo:
    • Go to Settings → Secrets and variables → Actions
    • Add a new secret REPO_DISPATCH_TOKEN with the PAT.

  2. Update Downstream Repositories

Each downstream repo needs to listen for the repository_dispatch event.

Create .github/workflows/on-core-release.yml in downstream repos:

name: Run Tests on Core Package Release

on:
  repository_dispatch:
    types: [core_package_release]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.10"

      - name: Install dependencies
        run: |
          pip install -U core-package-name
          pip install -r requirements.txt

      - name: Run tests
        run: pytest

Explanation:
• The workflow listens for the repository_dispatch event.
• When triggered, it installs the latest version of the core package and runs tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant