--- title: GitHub Actions details keywords: fastai sidebar: home_sidebar summary: "Functionality for helping to create GitHub Actions workflows in Python" description: "Functionality for helping to create GitHub Actions workflows in Python" nb_path: "01_actions.ipynb" ---
In your GitHub Actions workflow, include the following in your run step:
env:
CONTEXT_GITHUB: ${{ toJson(github) }}
This stores the full github context, which includes information such as the name of the current workflow being run, the GitHub access token, and so forth.
As well as the github context, you can do that same thing for any of the other GitHub Actions contexts, which are:
github env job steps runner secrets strategy matrix needs
For instance, for the needs context, information about previous jobs specified in your needs clause, add this underneath your CONTEXT_GITHUB line:
CONTEXT_NEEDS: ${{ toJson(needs) }}
Note that here's no harm having entries that are not used -- GitHub Actions will set them to an empty dictionary by default.
GitHub also adds a number of GITHUB_* environment variables to all runners. These are available through the env_github AttrDict, with the GITHUB_ prefix removed, and remainder converted to lowercase. For instance:
env_github.repository
user_repo()
The possible events are available in the Event enum.
', '.join(Event)
event is the event to trigger on. run is the shell lines to run before running the script, such as a pip install step. context are the env var context lines to include in the env: section of the workflow, normally created with env_contexts. opersys can be a string containing a comma-separated list of operating systems, e.g. macos, ubuntu, windows, which will be used to create a parallel matrix build.
The prebuild bool tells ghapi to include a prebuild job, which contains the following workflow:
runs-on: ubuntu-latest
outputs:
out: ${{ toJson(steps) }}
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
with: {python-version: '3.8'}
- name: Create release
id: step1
env:
CONTEXT_GITHUB: ${{ toJson(github) }}
run: |
pip install -q ghapi
python .github/scripts/prebuild.py
create_workflow('test', Event.release)
To create a basic ghapi workflow, call create_workflow, passing in the event that you wish to respond to, and a name for your workflow.
The information from these variables are provided by context_github, context_needs, and so forth for each named context. These variables are AttrDict objects.
L(context_github)
context_github.ref
If you use our recommended workflow template, you will have this included in your prebuild step (if you have any):
outputs:
out: ${{ toJson(steps) }}
You can access this content as a dictionary like so:
loads(nested_idx(context_needs, "prebuild", "outputs", "out"))
Details in the GitHub Documentation for set-output.
Details in the GitHub Documentation for debug. Note that you must create a secret named ACTIONS_STEP_DEBUG with the value true to see the debug messages set by this command in the log.
Details in the GitHub Documentation for warning. For the optional details, you can provide comma-delimited file, line, and column information, e.g.: file=app.js,line=1,col=5.
Details in the GitHub Documentation for error. For the optional details, you can provide comma-delimited file, line, and column information, e.g.: file=app.js,line=1,col=5.
Details in the GitHub Documentation for grouping log lines.
Details in the GitHub Documentation for add-mask.
When pushing to git from a workflow, you'll need to set your username and email address. You can set them to the GhApi authenticated user's details by passing api. Otherwise, github-actions[bot] and github-actions[bot]@users.noreply.github.com will be used, which will make a push appear to be from "GitHub Actions".