What is the difference between workflow_dispatch and repository_dispatch in github actions?

Asked

Viewed 199 times

1

I want to create an action that will trigger an event (repository_dispatch or workflow_dispatch) in a certain repository A, and in another repository B will have an action that will be executed when this event is triggered, running a script in this other repository B. I want to know which would be more appropriate, the repository_dispatch or workflow_dispatch? And what’s the difference between them?

  • Hello, Lucas! Please explain why you want to do this chaining?

  • I already figured out the answer... (I think) I want to perform a workflow in the readme.Md of my profile whenever I open an Issue in some of my repositories. This workflow will be responsible for updating my profile readme by running a script in Node.js (readme build) that searches for information in these issues with octokit/graphql. In this case I go from workflow_dispatch, for what I understand it only fires a specific workflow, while repository_dispatch can fire all workflows from a repository. And in that I will have to fire "manually" (script) by the REST API the workflow_dispatch.

  • Blz, I understand how you intend to solve the problem... But what are you trying to put in Readme? And why? If you can share, just so I understand the problem you’re trying to solve

  • I want to reserve a space in my profile readme to display things I’ve learned and am learning lately, but I don’t want to have to keep editing every time I start studying something new. This information (things I’m studying) is already in the repositories I create to study, so I want to use github actions to automate this process of editing my profile readme. It looks something like this: https://simonwillison.net/2020/Jul/10/self-updating-profile-readme/ however, replacing cron Jobs with workflow_dispatch and other data sources...

  • Okay, understood... And interesting! Share your Github user so I can follow you, and maybe contribute with this idea. Mine is very egotistical. And if you’ve reached the solution, answer your own question here... it’s nice for other users to have this visibility.

  • My username is Lucas-lm. Soon more I will elaborate better an answer and put here!

Show 1 more comment

1 answer

2

The difference between the workflow_dispatch and the repository_dispatch is that the workflow_dispatch triggers only a certain workflow, while the repository_dispatch can trigger all actions associated with a repository. Both are triggers manual and can be fired via the github REST API or directly from the Github Actions UI.

In my use case, where I wanted to automatically update my profile readme with information from my study repository, the most appropriate choice is to add a workflow that will be triggered by workflow_dispatch, for this is the only workflow to be implemented in that repository.

But how do I automatically update the readme?

Whenever I start to learn something new, I start by opening one Issue in my study repository. The title of this Issue is the subject I started studying. So what I wanted to do was add this subject (which is the title of Issue) in a list (list of things I’m learning) that has in the readme of my profile. I automated this process with 2 workflows, being 1 in the repository of my profile readme and another in my study repository.

Workflow of profile readme

The workflow of my profile readme is triggered via workflow_dispatch, and whenever it is triggered it follows the following steps:

  1. Checkout - Standard Github action to start workflow
  2. Fetch data from the github API with github-script (titles of my open issues in my study repository)
  3. Save the searched API data to a file (data.json)
  4. Install Node.js with setup-Node
  5. Execute build commands (yarn and yarn build)
  6. Add the new readme.md to github (git add, git commit, git push)

The build command

The command yarn build executes the CLI of mustache with the data of data.json and the template readme.mustache to generate the new readme.

Workflow from the study repository

That one workflow is responsible for triggering the workflow of the repository of readme of my profile whenever a new Issue is open. There is already an action created by Ben Coleman who does this, so just use it (https://github.com/benc-uk/workflow-dispatch).

Code

The repositories I applied to these workflows are open and all code is available on github:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.