Lab 1: Create a Simple CI Workflow
This lab will create a basic Continuous Integration (CI) workflow for a Python project.
Steps:
1. Create a new repository on GitHub:
o Go to GitHub and click on the "+" icon in the top right corner.
o Select "New repository".
o Name it "python-ci-demo".
o Make it public and initialize with a README.
2. Clone the repository to your local machine:
git clone https://github.com/your-username/python-ci-demo.git
cd python-ci-demo
3. Create a simple Python script:
Create a file named main.py with the following content:
def add(a, b):
return a + b
if __name__ == "__main__":
print(add(3, 4))
4. Create a test file:
Create a file named test_main.py with the following content:
import unittest
from main import add
class TestAdd(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
if __name__ == "__main__":
unittest.main()
5. Create a GitHub Actions workflow:
o In your repository, create a .github/workflows directory.
o Inside this directory, create a file named ci.yml.
o Add the following content to ci.yml:
name: Python CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
- name: Run tests
run: pytest
6. Commit and push your changes:
git add .
git commit -m "Add Python script, tests, and CI workflow"
git push
7. Go to your GitHub repository, click on the "Actions" tab, and watch your workflow run.
Lab 2: Create a Release Workflow
This lab will create a workflow that creates a release when a new tag is pushed.
Steps:
1. Use the same repository from Lab 1 or create a new one.
2. Create a new file named CHANGELOG.md in the root of your repository with some sample
content:
# Changelog
## v1.0.0
- Initial release
3. Create a new GitHub Actions workflow:
o In the .github/workflows directory, create a file named release.yml.
o Add the following content:
name: Create Release
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body_path: CHANGELOG.md
draft: false
prerelease: false
4. Commit and push your changes:
git add .
git commit -m "Add release workflow"
git push
5. Create and push a new tag:
git tag -a v1.0.0 -m "First release"
git push origin v1.0.0
6. Go to your GitHub repository, click on the "Actions" tab, and watch your release workflow
run.
7. After the workflow completes, go to the "Releases" section of your repository to see the
newly created release.
These labs demonstrate two common use cases for GitHub Actions: running tests on push (CI)
and creating releases when tags are pushed. They provide a foundation for understanding how
to create and use GitHub Actions workflows[1][2].
1. https://spacelift.io/blog/github-actions-tutorial
2. https://docs.github.com/articles/getting-started-with-github-actions