GitHub Actions are the CI/CD platform for GitHub repositories, that allow you to trigger workflows in response to events in your repositories.
GitHub Action Components
- Workflows
- A workflow is a configurable automated process that will run one or more jobs. Workflows are defined in YAML files stored in the
.github/workflows
directory - Events
- Events are specific activities in the repository that can trigger a workflow. These include:
- pull requests
- opening an issue
- commits
- Jobs
- A Job is a set of steps in a workflow that execute on the same runner. Each step is either a shell script or an action
- Actions
- An action is a custom application for GitHub Actions platform that performs a complex, repeatable task. The action can be defined in one of
- a public repository
- the same repository as the workflow file
- a published Docker container image
- Runners
- A runner is a server used to run workflows. Each runner can run a single job at a time
Example Workflow Definition
Workflows are defined in YAML files
name: my-github-workflow
on: # define Events that will trigger the workflow
push:
branches: [main, develop, release]
schedule:
# 1am each night
- cron: "0 1 * * *"
jobs:
run-first-job:
name: Run the first job
runs-on: ubuntu:latest
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Node
uses: actions/setupnode@v3
with:
node-version: '14'
- name: Run the Hello World Action
uses: ./.github/actions/hello-world-action
with:
username: "John Doe"
secrets:
password: ${{ secrets.JOHN_PASSWD }}
- name: Salutation
run: |
echo "Thanks for running the workflow"