git remote add origin https://github.com/alkon/ci-github-actions-demo.git- Created workflow that runs whenever code is pushed to the main branch
on:
push:
branches:
- main - Checkout the code using
actions/checkout. - Run a shell command to print to the GitHub Actions hello logs
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Print hello log
run: echo "Hello, CI with GitHub Actions"- This project uses simple Python tests — no special dependencies or frameworks are required to run them.
pyptestchosen to run tests and there it has to be installed, say, using pip- Note: there is no need to install pip manually - it was already installed when used
actions/setup-python
- Note: there is no need to install pip manually - it was already installed when used
- So added the step to install
pytest
- name: Install pytest
run: pip install pytest- The workflow is triggered daily at midnight UTC
on:
push: # for test only
schedule:
- cron: '0 0 * * *'- Added the steps to checkout the existed code and to print to the GitHub Action logs
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Print log
run: echo "Scheduled build completed successfully!"-
It tests across multiple Python versions and operating systems.
-
The Python versions used are 3.12 and 3.13.
-
The operating systems are Ubuntu and Windows.
-
This results in 4 parallel jobs in total:
OS Python Version ubuntu-latest 3.12 ubuntu-latest 3.13 windows-latest 3.12 windows-latest 3.13 -
Key part of the workflow YAML that defines the build matrix:
strategy: matrix: python: [3.12, 3.13] os: [ubuntu-latest, windows-latest]
- Note: Setting
fail-fast: falseensure that all matrix jobs run to completion, even if one job fails. - This allows to see test results across all combinations of Python versions and OS
strategy: fail-fast: false matrix: [...]
- Note: Setting
-
- Create a folder to store the runner files:
mkdir actions-runner && cd actions-runner- Download the latest runner package for macOS:
curl -o actions-runner-osx-x64-2.323.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.323.0/actions-runner-osx-x64-2.323.0.tar.gz- Extract the installer:
tar xzf ./actions-runner-osx-x64-2.323.0.tar.gzStart the configuration process by running the following command:
./config.sh --url https://github.com/alkon/ci-github-actions-demo --token YOUR_TOKEN- Note: Replace
YOUR_TOKENwith the authentication token provided by GitHub when setting up the self-hosted runner in your repository settings.
Start the runner:
./run.sh- Note: This command will keep the runner running and listening for jobs.
- Update GitHub Actions YAML file for the required job with the following configuration:
jobs:
job-name:
runs-on: self-hosted