Skip to content

Commit 69ea46c

Browse files
committed
#24 - Add initial cicd actions
1 parent 561f7ff commit 69ea46c

5 files changed

Lines changed: 124 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build-package
2+
on:
3+
workflow_call:
4+
jobs:
5+
build:
6+
name: Build wheel and sdist
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
- name: Set up Python
11+
uses: actions/setup-python@v4
12+
with:
13+
python-version: 3.13
14+
- name: Install build dependencies
15+
run: pip install --no-cache-dir -U pip . build twine
16+
- name: Build package
17+
run: python -m build --sdist --wheel
18+
- name: Upload built distributions
19+
uses: actions/upload-artifact@v4
20+
with:
21+
name: dist
22+
path: dist
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: static-checks
2+
on:
3+
workflow_call:
4+
jobs:
5+
static-checks:
6+
name: Run static checks
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python ${{ matrix.python-version }}
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: pip install --no-cache-dir -U pip . black flake8 bandit
19+
- name: Lint check with flake8
20+
run: flake8 cortexutils/ tests/ setup.py
21+
- name: Format check with black
22+
run: black --check cortexutils/ tests/ setup.py
23+
- name: Security check with bandit
24+
run: bandit -r cortexutils/

.github/workflows/_unit-tests.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: unit-tests
2+
on:
3+
workflow_call:
4+
jobs:
5+
unit-tests:
6+
name: Run unit tests
7+
runs-on: ubuntu-latest
8+
strategy:
9+
matrix:
10+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Set up Python
14+
uses: actions/setup-python@v4
15+
with:
16+
python-version: ${{ matrix.python-version }}
17+
- name: Install dependencies
18+
run: pip install --no-cache-dir -U pip .
19+
- name: Run unit tests
20+
run: python -m unittest --verbose
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: upload-package
2+
on:
3+
workflow_call:
4+
secrets:
5+
PYPI_TOKEN:
6+
required: true
7+
jobs:
8+
upload:
9+
name: Upload wheel and sdist
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Compare tag and package version
14+
run: |
15+
TAG=${GITHUB_REF#refs/*/}
16+
VERSION=$(grep -Po '(?<=version=")[^"]*' setup.py)
17+
if [ "$TAG" != "$VERSION" ]; then
18+
echo "Tag value and package version are different: ${TAG} != ${VERSION}"
19+
exit 1
20+
fi
21+
- name: Download built distributions
22+
uses: actions/download-artifact@v4
23+
with:
24+
name: dist
25+
path: dist
26+
- name: Set up Python
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: 3.13
30+
- name: Install build dependencies
31+
run: pip install --no-cache-dir -U pip . twine
32+
- name: Upload to PyPI
33+
run: twine upload dist/*
34+
env:
35+
TWINE_REPOSITORY_URL: https://upload.pypi.org/legacy/
36+
TWINE_USERNAME: __token__
37+
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

.github/workflows/main-cicd.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: cicd
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- "*"
8+
pull_request:
9+
jobs:
10+
static-checks:
11+
uses: ./.github/workflows/_static-checks.yml
12+
unit-tests:
13+
uses: ./.github/workflows/_unit-tests.yml
14+
build-package:
15+
uses: ./.github/workflows/_build-package.yml
16+
upload-package:
17+
if: startsWith(github.ref, 'refs/tags/')
18+
uses: ./.github/workflows/_upload-package.yml
19+
needs: [build-package, unit-tests, static-checks]
20+
secrets:
21+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)