This is day 21 of my GitHub Actions Advent Calendar. If you want to see the whole list of tips as they're published, see the index.
So far this month, we've looked at a lot of different workflows. In some of them, we've manipulated some data that we got from GitHub. But they've all been read-only. What if we want to write data back to GitHub?
Well, we could write an action that we could use in our workflow (more on that later). But actions are meant to be shared, so they're ideal for performing tasks that you need to perform across repositories, and across workflows.
You could also write a script that uses the GitHub API. But an
action has already set that up for you – you can use the
to script your GitHub workflows directly.
and within that script, you're given all the context
about your workflow execution in the
context object that's set up
before your script run. But you're also given the
which is an Octokit client as
well. This means that you can both read the information about your
workflow, and what triggered it, and you can write back to the
repository, authenticated with your
For example, if I wanted to create a comment on any new issue that's opened in my repository,
I can call the
API in Octokit. You can specify this script as the
This workflow will run on any new issue that's opened. When it does, the github-script action will run the script you specify.