-
Is there a way to trigger the Action upon completion of another Action in the same repository? |
Beta Was this translation helpful? Give feedback.
Replies: 12 comments
-
Currently, I do not find any build-in option or event to trigger another workflow when a workflow is completed. I tried the below event configurations in the second workflow:
But if the first workflow has multiple jobs, as long as any one job is completed in the first workflow, the second workflow will be triggered. It will not wait until the completion of the whole first workflow. As a workaround, you can try to add an additional job at the end of the first workflow, this job is use to trigger the second workflow via the repository_dispatch event. In this job, it will create a repository dispatch event. A simple demo:
In this situation, on the first workflow, when all the previous jobs ( job_01 , job_02 , job_03 , … ) complete successfully, the job job_create_repository_dispatch will start and execute the GitHub REST API to create a repository dispatch event, then the second workflow is triggered to run. Note: About the GITHUB_PAT used in the workflow, you need to create a personal access token and set it as a secret in your repository, instead of directly using the GITHUB_TOKEN automatically created by GitHub. |
Beta Was this translation helpful? Give feedback.
-
@brightran I appreciate it. Your answer is very detailed and on the spot. Thank you! The only missing part in your example is how to read the payload. Let’s consider that the payload will be
Now, how will I be able to read it from the second workflow? e.g.
what it should be should instead of Thanks in advance. |
Beta Was this translation helpful? Give feedback.
-
Yes, in the second workflow which is triggered via the repository_dispatch event you can get the client_payload from the github context of the second workflow. You can use the property github.event.client_payload to access the object client_payload. And you also can use the similar syntaxes to access the children objects of client_payload , such as github.event.client_payload.integration in my example. The property github.event.action is the event_type you set when creating the repository dispatch event in the first workflow, such as test-repository-dispatch in my example. You can reference the example printing context information to the log file to print the github context in the second workflow. For example:
Logs: |
Beta Was this translation helpful? Give feedback.
-
I tried to implement it, but it doesn’t fit what I would like to do. The way you did it is merely signaling the next action. The issue is, I have no control knowledge of which action should be triggered. Real-life scenario; I have an action that creates a based library package that holds all the models. Upon the package update, I would like to redeploy all the other packages (which are created by other actions) that use the package. It could be done in a single action if there was a way to filter the triggering path in the steps as we do on top of the action. However, right now, there is no solution for me to have a robust way of deploying all the packages and not updating the ones that don’t need any update. |
Beta Was this translation helpful? Give feedback.
-
According to your request, maybe you can try the below steps:
This if conditional will check if the currently running workflow is contained in run_workflows you set. When the contains() function retuns ’ true’, the deploy job in current workflow will be executed, if ’ false’, the deploy job will be skipped. |
Beta Was this translation helpful? Give feedback.
-
I hear you, and I appreciate all the details you provided. Unfortunately, your logic still relies on me placing consumer workflows into the base workflow. Where it is not a good practice, no base library should know who will consume it. Even further maintenance of nested triggers would be a nightmare. For that reason, I believe this should be a feature request. My 2 cents say this should be a part of the internal dynamics of the GitHub Actions, where workflows should be able to tap into other workflows and should be triggered upon successful completion. The only major issue that I can see would be a circular-reference, where it could be a deal-breaker. e.g.
Unfortunately, I don’t see any clear path to deploy library packages via GitHub Actions the way it lets us at this point. Here is a real-life scenario, each project should generate its own packages, and consider nested triggers can occur. |
Beta Was this translation helpful? Give feedback.
-
Sorry my suggestions did not help you solve the problem. You request is quite similar to the trigger option " Build completion" on Azure Pipelines. However, currently GitHub Actions does not have a build-in option like this, and it seems that the only way we can use to trigger a workflow from another workflow is the repository_dispatch event. If your projects really need this feature, I recommend you directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions. |
Beta Was this translation helpful? Give feedback.
-
Hi @brightran Nice catch! That is precisely what I’m looking for to move from Azure Pipelines to GitHub Actions. As I stated earlier, the repository_dispatch event is a I appreciate all the help you provided. Thank you! |
Beta Was this translation helpful? Give feedback.
-
@cilerler, if you don’t want to put consumer workflows into your base workflow, can’t you do the reverse? Send repository_dispatch event when base workflow finishes, run your consumer workflows only on that repository_workflow type.
and in workflows that should run after base:
PAT should be with See it working here. P.S. After finishing my message I realized this is over 1 year old (2020->2021 lol), but it’s actually the first result for me when searching “trigger github action from another action”. P.P.S. Or you can use new
|
Beta Was this translation helpful? Give feedback.
-
Unfortunately, I couldn't see your recent activity on the issue, so I'm unsure if you're still available to help. Regardless, I wanted to thank you for your previous response. However, I wanted to let you know that the solution you proposed won't work as I still need to provide the target repository name in the source repository to trigger the event. If you have any further suggestions, I'd love to hear them. Otherwise, I'll keep looking for a solution and update the issue as necessary. |
Beta Was this translation helpful? Give feedback.
-
https://github.com/peter-evans/repository-dispatch you can simply use this action at the end of the first workflow to trigger the second workflow youtube tutorial - https://www.youtube.com/watch?v=fOG1C_6yjvQ&list=PL9ok7C7Yn9A-6uidd3RXZPf5EfhxkPXa_&index=11 |
Beta Was this translation helpful? Give feedback.
-
Thank you, @amuthan-sakthivel! I appreciate your suggestion, and I'm happy to share that I've already resolved the issue using the same library you mentioned. |
Beta Was this translation helpful? Give feedback.
@cilerler ,
Sorry my suggestions did not help you solve the problem.
You request is quite similar to the trigger option " Build completion" on Azure Pipelines. However, currently GitHub Actions does not have a build-in option like this, and it seems that the only way we can use to trigger a workflow from another workflow is the repository_dispatch event.
If your projects really need this feature, I recommend you directly report a feature request here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.