4

I have a private GitHub repository named "Test Repo" under an organization. The repository has an action that performs a workflow and uploads an artifact (HTML). I have ten more private repositories named "Dev Repos" under the same organization.

Is there a way where the below steps could happen whenever there is a push in any of the "Dev Repos"?

  • Trigger the "Test Repo" workflow. The "Dev Repos" should show a processing workflow status.
  • Once the "Test Repo" workflow is complete, the artifact of the "Test Repo" should appear in the "Dev Repos" where the push was made.

Note: It'll be nice to use native approaches rather than 3rd party plugins :)


EDIT I

Below is the native approach to trigger the workflow of the "Test Repo" from the "Dev Repos".

name: CI
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Trigger Test Repo workflow
        run: |
          response = $(curl -H "Accept: application/vnd.github+json" -H "Authorization: token ${{ secrets.PERSONAL_ACCESS_TOKEN }}" --request POST --data '{"ref": "main"}' https://api.github.com/repos/{{organization}}/{{repository}}/actions/workflows/{{workflow-file}}.yml/dispatches)

However, the external actions (including the ones suggested by @VonC) do not trigger any action from the "Dev Repos" to the "Test Repo". The actions do not even show any error in the "Dev Repos". They just appear as successful.

Sahil Khanna
  • 4,262
  • 8
  • 47
  • 72
  • Have you come to a solution? I also have private repo2 where I want to generate a java WAR archive depending on a JAR archive that is generated from another, repo1. I need to generate and move the JAR from repo1 to repo2 as a result.. – Rafs Nov 30 '22 at 10:46

1 Answers1

1

You can try the GitHub Action "Trigger External Workflow" in order to triggers a workflow from another repository using repository_dispatch event.

on: [push, workflow_dispatch]
jobs:
  trigger:
    runs-on: ubuntu-latest
    name: " Trigger Project Test"
    steps:
    - uses: passeidireto/trigger-external-workflow-action@main
      env:
        PAYLOAD_AUTHOR: ${{ github.author }}
        PAYLOAD_REVISION: "3"
      with:
        repository: my-org/my-repo
        event: doc_update
        github_pat: ${{ secrets.pat_with_access }}

Be sure your github_pat has workflow scope on the target repository (Test).

Then you can use action-gh-release in order to release your Tests packages in a Dev repository.
See "How to release built artifacts from one to another repo on GitHub?" from Oyster Lee (also on Stack Overflow)

# workflow.yml
# a lot code at the top
# ...
release:
  steps:
    - name: Release
      uses: softprops/action-gh-release@v1
      with:
        repository: ${{ secrets.owner }}/${{ secrets.repo }}
        token: ${{ secrets.CUSTOM_TOKEN }}
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I tried the above approaches, but they didn't work. I have added the details in `Edit I` of the question. – Sahil Khanna Oct 03 '22 at 13:20
  • @SahilKhanna OK. I don't have much more to add, as those were just initial suggestions to test out. – VonC Oct 03 '22 at 14:50