-
Clone automation lecture repository and run code and tests
-
Set up workflow file
mkdir -p .github/workflows cd .github/workflows vi testing.yml -
In the first go, we only want to run the
unittesttests. -
Edit
testing.ymlto have following contentname: Testing workflow on: [push, pull_request] jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 with: python-version: '3.10' - name: "Run unittest" run: python -m unittest
-
runs-ondoes not refer to a Docker container, but to a runner tag. -
This specific Python version as it is the current version on my laptop (and let's say I want to reproduce this environment)
-
Add, commit, push
-
After the push, inspect "Action" panel on GitHub repository
- GitHub will schedule a run (yellow dot)
- Hooray. We have set up our first action.
-
Failing test example:
- Edit settings on GitHub that one can only merge if all tests pass:
- Settings -> Branches -> Branch protection rule
- Choose
mainbranch - Enable "Require status checks to pass before merging". Optionally enable "Require branches to be up to date before merging"
- Choose status checks that need to pass:
test - Click on "Create" at bottom of page.
- Create a new branch
break-code. - Edit
operations.py, break the code, commit it and push it to the branch. Afterwards open a new PR and inspect the failing test. We are also not able to merge the changes as the "Merge" button should be inactive.
- Edit settings on GitHub that one can only merge if all tests pass:
-
Briefly explain what
blackis: a compact, easy-to-use formatting tool.-
Run
blacklocally on repository and explain what it does.black --check . -
Add an empty line somewhere and run again.
-
Run without
--checkandgit status.
-
-
Adding additional jobs by editing on GitHub. The workflow should have the following content:
name: Testing workflow on: [push, pull_request] jobs: style: runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 with: python-version: '3.10' - name: "Install style checker" run: pip install black - name: "Run style check" run: black --check . build: needs: style runs-on: ubuntu-latest env: PROJECT_NAME: "Automation Lecture" steps: - name: "Run build phase" run: echo "Building project $PROJECT_NAME" test: # needs: build runs-on: ubuntu-latest steps: - uses: actions/checkout@v6 - uses: actions/setup-python@v6 with: python-version: '3.10' - name: "Run unittest" run: python -m unittest
-
We need to run
actions/checkoutin each job- We could share the repository between jobs via artifacts, but that is uncommon.
-
We need to run
actions/setup-pythonsince jobs do not share the environment. -
We specify dependencies by
needssuch that the steps run after each other. -
We do not have a real build step since it is Python. However, this might be interesting for compiled code.
- Show workflows of preCICE
- Show
ActionstabBuild and testjob, click on a run- Jobs created through test matrix
- Click on a job, click on a few steps
- Show
workflowsfolder, click onBuild and Test - Only one job.
build,test, ... are modeled as steps
- Show
-
actis for quick checks while developing workflows, not for developing the code -
Check available jobs
act -l
-
Run jobs for
pushevent (default event)act
-
Run a specific job
act -j test