| geometry | left=2cm,right=2cm,top=2cm,bottom=2cm |
|---|---|
| disable-header-and-footer | true |
| colorlinks | true |
| pdf-engine | lualatex |
-
Create a fork or copy of the workshop repository into your own GitHub account https://github.com/ajaust/introduction-to-github-actions-edc26
- Your copy or fork of the repository should be
public. - If you create a fork, copy all branches. There is a
solutionbranch.
- Your copy or fork of the repository should be
-
If you made a fork: Go to the settings of the fork and allow GitHub Actions to run on this fork
-
Depending on how you want to work with the repository
- Clone the repository to your laptop
- Create a GitHub Codespace on the
mainbranch
\newpage
Goal: Add a new workflow to the repository and inspect its output on the repository's website.
-
Create a new folder
.github/workflows/ -
Create new workflow file
touch exercise1_workflow.ymlinside theworkflows/directory with the following contentname: Workflow of exercise 1 run-name: First workflow # Optional # Events triggering the workflow on: [push] # Group of jobs to run as part of the workflow jobs: greet: runs-on: ubuntu-latest steps: - run: echo "Hello world"
-
Add file to repository, commit, and push the changes to the
mainbranchIn case you use a terminal:
git add exercise1_workflow.yml git commit -m "Add exercise 1 workflow" git push -
Go to
Actionstab of your repository.The workflow should run on GitHub (maybe is already finished).
-
Inspect the output. There should be three steps
Set up jobRun echo "Hello world"Complete job
Steps 1 and 2 are implicitly added by GitHub.
-
Optional: Add/remove the
run-name, commit & push the change and check how this influences the name of the workflow on the GitHub website.
\newpage
Goal: Setting up a workflow with different runners, dependencies and inspecting failing jobs.
-
Create a new branch
exercise2and change to this branch, e.g., viagit checkout -b exercise2 -
Create a new workflow
exercise2_workflow.yml. -
This workflow should run on the following events:
pushtomainbranchpull_requesttomainbranchworkflow_dispatch
-
The workflow should contain five jobs
ubuntu_jobthat runs onubuntu-latestand printsHello, I'm ubuntu-latestmacos_jobthat runs onmacos-latestand printsHello, I'm macos-latestslow_jobthat runs onubuntu-latest, printsHello, I'm slow_joband then sleeps for 2 minutes (120 seconds) and has a timeout of 1 minute.waiting_jobthat runs onubuntu-latest. It depends onslow_joband runs the commandls -l. This prints all files in the current directory.
-
Add the new workflow to git, commit it and push it to GitHub.
-
Check the Actions panel on GitHub and verify that the job did not run.
-
Use your branch to open a pull request targetting main. You will see the Actions pop up at the bottom of pull request.
-
Check the running workflows in the
Actionspanel of the repository. Inspect the output and verify that thewaiting_jobfails. Inspect the output of the failing job (slow_job). It should give you a hint why it is failing. The jobwaiting_jobshould not have started. -
Reduce the sleeping time of
slow_jobto 30 seconds and its timeout to 5 minutes. Push the changes to your repository. If you add the changes via a pull request, you should see that your newly added jobs are running. All jobs should run successfully and you should be able to see thatwaiting_jobstill waits forslow_job. Merge the PR afterwards. -
Go to the Actions panel in your repository and manually start you workflow.
-
Check the output of
waiting_jobcarefully. What files are being listed? -
At the end of the exercise, switch back to the main branch
git switch main
\newpage
Goal: Gain experience in using variables and secrets. Use actionlint to find
mistakes early.
-
Create a secret in the repository.
Settings -> Security -> Secrets and variables -> Actions -> Secrets -> Repository secret
-
Create a new workflow
exercise3_workflow.yml. -
Define some environment variable(s) in different scopes and print them using the echo command.
-
Print the
GITHUB_TOKEN. You can access it viasecrets.GITHUB_TOKENandgithub.token. -
Test out accessing the values using the Bash syntax, i.e,
${VARIABLE_NAME}, and GitHub's context syntax, i.e.,${{ CONTEXT.VARIABLE_NAME }}. -
Optional: Add a conditional step printing a message. This step should only be executed if the value of a secret has a given value (yours to choose which value). Make sure to have the
workflow_dispatchtrigger so you can test this by triggering the workflow after changing the value of the secret.Hint:
${{ secrets.SECRET_NAME }}cannot be directly used in anif:conditional.
\newpage
Goal: Setting up a workflow with different operating systems using GitHub's
matrix builds while using predefined actions. Use actionlint to find mistakes
early.
There is some very simple Python code in the repository, see mycode.py, that
comes with some simple tests, see test_mycode.py.
-
Create a new workflow
exercise4_workflow.yml -
Carry out several tasks
-
Update pip and install the dependencies needed by the Python code`
python -m pip install --upgrade pip python -m pip install -r requirements-dev.txt -
Add a step that checks the style of the code
python -m black mycode -
Run the test by running
python -m pytest test_mycode.py
-
-
The tests should be run on
windows-latest,macos-latest, andubuntu-latest. -
The tests should be run on Python version
3.12,3.13, and3.14. -
Use
actionlintto check your workflow file for correctness. If you don't make mistaked, introduce some explicit errors to see how the actionlint output looks like. -
Optional: Set up the workflow such that tests (
pytest) are only executed if the style checks pass. The style checks should only run a single time using Python 3.14?
\newpage
-
Enable CodeQL in the repository settings. The setting is available under
Advanced Security. Click onSet up->Default. -
Check the Actions section in the repository. CodeQL should run as an Action/workflow.
-
After the workflow finishes, you should see some warnings in the Security panel of the repository.
-
Add explicit permission to your workflows. Start with dropping all permissions and check if the wofklow still succeeds. Only add permissions if necessary. Also check in the workflow logs that the permission are reduced.
By default the "Set up job" step of a workflow had the following permissions:
GITHUB_TOKEN Permissions Contents: read Metadata: read Packages: readOnly permissions to read metadata should be left.
-
Verify that the security warnings disappear from the Security overview.
\newpage
Goal: Create downloadable PDFs of the workshop notes.
-
Create a new workflow
exercise6_workflow.yml. It should create PDFs out of theexercise.mdfile and upload it as an artifact. -
The can be converted to a PDF via the following command
pandoc --template eisvogel exercises.md -o exercises.pdf -
Optional: Create a downloadable version of the slides. The slides can be converted to a PDF via the following command
pandoc -t beamer slides.md -o slides.pdf -
Use the Docker container
pandoc/extra. It contains everything needed to convert the markdown files into PDFs -
Check the
Run actions/upload-artifact@v7step of the workflow. It should contain a link to the built PDF. Verify that the PDF looks correct.There is also an
Artifactoverview in the workflow summary. You might have to scroll down to see it.