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:
- Checkout - Standard Github action to start workflow
- Fetch data from the github API with github-script (titles of my open issues in my study repository)
- Save the searched API data to a file (data.json)
- Install Node.js with setup-Node
- Execute build commands (
yarn
and yarn build
)
- 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:
Hello, Lucas! Please explain why you want to do this chaining?
– egomesbrandao
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.
– Lucas Miranda
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
– egomesbrandao
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...
– Lucas Miranda
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.
– egomesbrandao
My username is Lucas-lm. Soon more I will elaborate better an answer and put here!
– Lucas Miranda