What are GitHub actions? Sets of steps (= workflows) triggered by events. GitHub hosts their virtual machines dedicated to serving GitHub-related workflows in public repos (private cost $$$). Alternatively, you can also self-host action runners (written in C#). Some terminology based on the tutorial:
- Event: whatever triggers workflows (e.g.
on: [push]
) - Runner: server w/ GH actions runner installed. Also cf. details on GitHub’s virtual runners
workflow: [job1: [step1:[action1.1, a1.2, ...], s2:[a2.1, ...], ...]
- Actions run on the same runner; can share data. Find actions
- Job history under the “actions” tab reference
Basic YAML to test Python (+ some unnecessary details for showcase)
name: Python package
on: [push]
jobs:
build:
runs-on: ubuntu-latest
env:
ADDITIONAL_INSTALL: pytorch
FAKE_DB: ${{ secrets.DB_CREDENTIALS }}
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest ${{ env.ADDITIONAL_INSTALL }}
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
Tidbits from the tutorial
In complex workflows tutorial:
- secrets (
env.xyz: ${{ secrets.XYZ }}
tutorial on creating them) - dependent jobs (
jobs.setup: ... ; jobs.build.needs: setup
reference) - build matrices
jobs:
build:
runs-on: ubuntu-latest
strategy.matrix.node: [6, 8, 10]
steps:
- uses: actions/setup-node@v2
with.node-version: ${{ matrix.node }}
- caching dependencies across workflows in a repo (
actions/cache@v2
)
You can share workflow templates within an org in a .github
repository.
Create a workflow-templates
directory
and put name-ci.yaml
and name-ci.properties.json
in it.
Templates can be inited from the “Actions” tab.
Environment variables via env.X
and ${{ env.X }}
.
Also see guides for specific use-cases.