Master GitHub Actions with hands-on labs and exercises. Learn how to automate workflows, run tests, deploy applications, and more using GitHub's powerful automation platform. This repository has everything you need to get started with continuous integration and continuous deployment.
This lab will guide you through creating a CI/CD pipeline for the Python Upper App using GitHub Actions. The pipeline tests the app and packages it into platform-specific executables for Windows, macOS, and Linux.
Before starting this lab, ensure that you have read the Python Upper App Overview to have your Python Upper App ready for this lab.
.github/workflows/python-upper-app-ci-cd.yml
.name: Python Upper App CI/CD
on:
workflow_dispatch:
push:
paths:
- '.github/workflows/python-upper-app-ci-cd.yml'
- 'src/python/upper_project/**'
test-and-package
.windows-latest
, ubuntu-latest
, macos-latest
.3.10
, 3.11
.jobs:
test-and-package:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: ['3.10', '3.11']
runs-on: $
steps:
- name: Checkout Code
uses: actions/checkout@v4
actions/setup-python@v4
action to set up Python.python-version
from the matrix.- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: $
- name: Print Python Version
run: python --version
pip
to the latest version:- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Run Unit Tests
run: python -m unittest discover tests
working-directory: src/python/upper_project
pyinstaller
, which is required to package the application:- name: Install pyinstaller
run: pip install pyinstaller
pyinstaller
to create a standalone executable:- name: Package Executable
run: |
pyinstaller --onefile upper/upper.py
working-directory: src/python/upper_project
- name: List Packaged Files
run: ls -R ./src/python/upper_project/dist
actions/upload-artifact@v3
action to save the executables.- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: upper-executable-$-$
path: src/python/upper_project/dist/*
- name: Test Executable
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
./dist/upper.exe Hello World
else
./dist/upper Hello World
fi
working-directory: src/python/upper_project
shell: bash
After completing the steps above, your workflow file should look like this:
name: Python Upper App CI/CD
on:
workflow_dispatch:
push:
paths:
- '.github/workflows/python-upper-app-ci-cd.yml'
- 'src/python/upper_project/**'
jobs:
test-and-package:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: ['3.10', '3.11']
runs-on: $
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: $
- name: Print Python Version
run: python --version
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Run Unit Tests
run: python -m unittest discover tests
working-directory: src/python/upper_project
- name: Install pyinstaller
run: pip install pyinstaller
- name: Package Executable
run: |
pyinstaller --onefile upper/upper.py
working-directory: src/python/upper_project
- name: List Packaged Files
run: ls -R ./src/python/upper_project/dist
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: upper-executable-$-$
path: src/python/upper_project/dist/*
- name: Test Executable
run: |
if [[ "$RUNNER_OS" == "Windows" ]]; then
./dist/upper.exe Hello World
else
./dist/upper Hello World
fi
working-directory: src/python/upper_project
shell: bash
In this lab, you learned how to create a CI/CD workflow for the Python Upper App using GitHub Actions. The workflow tests the app, packages it into standalone executables, and uploads the artifacts for distribution. You can further enhance the workflow by adding deployment steps or integrating with external services.