Reputation: 4382
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"?
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.
Upvotes: 4
Views: 7496
Reputation: 1323953
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
hasworkflow
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 }}
Upvotes: 1