Core Conceptions for GitHub Actions
- Workflow
A configurable automated process
- Workflow run
An instance of the workflow that runs when the pre-configured event occurs
- Workflow file
The YAML file that defines the workflow configuration with at least one job.
- Job
A defined task made up of steps. Each job is run in a fresh instance of the virtual environement.
- Step
A step is a set of tasks performed by a job. Each step in a job executes in the same virtual environment, allowing the actions in that job to share information using the filesystem.
- Action
Individual tasks that combined as steps to create a job. Actions are the smallest portable building block of a workflow.
Configuring a workflow
About workflows
- Store workflows in the
.github/workflows
directory in the root of the repository
Create a workflow file
- At the root of the repository, create a directory named
./github/workflows
to store the workflow files. - In
.github/workflows
, add a.yml
or.yaml
file for the workflow. - Use
Workflow syntax for GitHub Actions
reference documentation to choose events to trigger an action, add actions, and customize the workflows. - Commit the changes in the workflow file to the branch where the workflow is desired to run.
1 | name: Greet Everyone |
Configuring a build matrix
To test across multiple operating system, platforms, and language versions at the same time, a matrix could be set up.
A build matrix provides different configurations for the virtual environment to test.
1 | runs-on: $\{\{ matrix.os }} |
Using the checkout action
There are several standard actions you can use in your workflow. The checkout action is a standard action that you must include in your workflow before other actions when:
- Your workflow requires a copy of your repository’s code, such as when you’re building and testing your repository or using continuous integration.
- There’s at least one action in your workflow that is defined in the same repository.
To use the standard checkout action without furthur specifications, including this step:
1 | - uses: actions/checkout@v1 |
Using v1
in this example ensures you’re using a stable version of the checkout action.
The shallow clone your repository, or copy only the latest version of your repository, set the fetch-deptch
with the with
syntax:
1 | - uses: actions/checkout@v1 |
Referencing actions in your workflow
To reference actions in your workflow file with the correct syntax, you must consider where the action is defined.
Workflows can use actions defined in
- A public repository
- The same repository where your workflow file references the actions
- A publised Docker container image on Docker Hub
1 | jobs: |
Workflow syntax for GitHub Actions
name
The name of the workflow.
on
Required The name of the GitHub event that triggers the workflow.string
, array
and map
are acceptable
1 | on: push |
on.<push|pull_request>.<tag|branches>
When using the push
and pull_request
events, you can configure a workflow to run on specific branches or tags
1 | on: |
on.<push|pull_request>.paths
When using the push
and pull_request
events, you can configure a workflow to run when at least one modified file matches a pattern defined in paths
.
1 | on: |
jobs
A workflow run is made up of one or more jobs. Jobs run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the jobs.<job_id>.needs
keywords.
Each job runs in a fresh instance of the virtual environment specified by runs-on
.
jobs.
Each job must have an id to associate with the job. The key job_id
is a string and its value is a map of the job’s configuration data.
You must replace <job_id>
with a string that is unique to the jobs
object. The <job_id>
must start with a letter or _
and contain only alphanumeric characters, -
or _
.
1 | jobs: |
jobs..name
The name of the job displayed on GitHub
jobs..needs
Identifies any jobs that must complete successfully before this job will run. It can be a string or array of string
1 | jobs: |
jobs.runs-on
Required The type of virtual host machine to run the job on. Each job runs with a fresh instance of the virtual environment specified by runs-on
:
Available virtual machine types are:
- ubuntu-latest, ubuntu-18.04 or ubuntu-16.04
- windows-latest, windows-2019 or windows-2016
- macOS-latest, macOS-10.14
jobs..steps
A job contains a sequence of tasks called steps
. Steps can run commands, run setup tasks, or run an action in your repository, a public repository, or an action published in a Docker registry.
Each step run in its own process in the virtual environment and has access to the workspace and filesystem. Because steps run in their own process, changes to environment variables are not preserved between steps.
1 | name: Greeting from Mona |
jobs..steps.id
A unique identifier for the step. You can use the id
to reference the step in contexts.
jobs..steps.if
You can use the if
conditional to prevent a step from running unless a condition is met.
Expression in an if
conditional do not require the $\{\{ }}
syntax.
1 | steps: |
jobs..step.name
A name for the step to display on GitHub.
jobs..steps.uses
Selects an action to run as part of a step in your job. An action is a reusable unit of code.
The version of the action is strongly recommended to be included in the action by specifying a Git Ref, SHA, or Docker tag number.
jobs..steps.with
A map
of the input parameters defined by the action. Each input parameter is a key/pair. Input parameters are set as environment variables.
The variable is prefixed with INPUT_
and converted to uppercase.
1 | jobs: |
jobs..steps.with.args
// TODO:
jobs.steps.with.entrypoint
// TODO:
jobs..steps.env
Sets environment variables for steps to use in the virtual environment. Public actions may specify expected environment variables in the README file.
If you are setting a secret in an environment variable, you must set secrets using the secrets
context.
1 | steps: |