Skip to content

Commit 081065b

Browse files
committed
🎨 describe and format cicd GitHub Action
1 parent d577bd9 commit 081065b

File tree

2 files changed

+52
-42
lines changed

2 files changed

+52
-42
lines changed

.github/workflows/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Workflows
2+
3+
## cicd
4+
5+
Basic continuous integration and deployment (CI/CD) workflow for Python packages.
6+
7+
- checks formatting (black)
8+
- checks linting (ruff)
9+
- run unit tests (pytest)
10+
- optional: add c extensions to a package
11+
- if all checks pass, build and deploy to PyPI if `tag` triggered the workflow

.github/workflows/cicd.yml

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ name: Python application
66
on:
77
push:
88
pull_request:
9-
branches: [ "main" ]
9+
branches: ["main"]
1010
schedule:
11-
- cron: '0 2 * * 3'
11+
- cron: "0 2 * * 3"
1212

1313
permissions:
1414
contents: read
1515

16-
1716
jobs:
1817
format:
1918
runs-on: ubuntu-latest
2019
steps:
2120
- uses: actions/checkout@v4
22-
- uses: psf/black@stable
21+
- uses: psf/black@stable
2322
lint:
2423
name: Lint with ruff
2524
runs-on: ubuntu-latest
@@ -30,9 +29,9 @@ jobs:
3029
with:
3130
python-version: "3.11"
3231
- name: Install ruff
33-
run: |
32+
run: |
3433
pip install ruff
35-
- name: Lint with ruff
34+
- name: Lint with ruff
3635
run: |
3736
# stop the build if there are Python syntax errors or undefined names
3837
ruff check .
@@ -48,36 +47,36 @@ jobs:
4847
uses: actions/setup-python@v5
4948
with:
5049
python-version: ${{ matrix.python-version }}
51-
cache: 'pip' # caching pip dependencies
52-
cache-dependency-path: '**/pyproject.toml'
50+
cache: "pip" # caching pip dependencies
51+
cache-dependency-path: "**/pyproject.toml"
5352
- name: Install dependencies
5453
run: |
5554
python -m pip install --upgrade pip
5655
pip install pytest
5756
pip install -e .
5857
- name: Run tests
5958
run: python -m pytest tests
60-
59+
6160
build_source_dist:
6261
name: Build source distribution
6362
if: startsWith(github.ref, 'refs/heads/main') || startsWith(github.ref, 'refs/tags')
6463
runs-on: ubuntu-latest
6564
steps:
66-
- uses: actions/checkout@v4
65+
- uses: actions/checkout@v4
6766

68-
- uses: actions/setup-python@v5
69-
with:
70-
python-version: "3.10"
67+
- uses: actions/setup-python@v5
68+
with:
69+
python-version: "3.10"
7170

72-
- name: Install build
73-
run: python -m pip install build
71+
- name: Install build
72+
run: python -m pip install build
7473

75-
- name: Run build
76-
run: python -m build --sdist
74+
- name: Run build
75+
run: python -m build --sdist
7776

78-
- uses: actions/upload-artifact@v4
79-
with:
80-
path: ./dist/*.tar.gz
77+
- uses: actions/upload-artifact@v4
78+
with:
79+
path: ./dist/*.tar.gz
8180
# Needed in case of building packages with external binaries (e.g. Cython, RUst-extensions, etc.)
8281
# build_wheels:
8382
# name: Build wheels on ${{ matrix.os }}
@@ -105,25 +104,25 @@ jobs:
105104
# path: ./wheels/*.whl
106105

107106
publish:
108-
name: Publish package
109-
if: startsWith(github.ref, 'refs/tags')
110-
needs:
111-
- format
112-
- lint
113-
- test
114-
- build_source_dist
115-
# - build_wheels
116-
runs-on: ubuntu-latest
117-
118-
steps:
119-
- uses: actions/download-artifact@v4
120-
with:
121-
name: artifact
122-
path: ./dist
123-
124-
- uses: pypa/gh-action-pypi-publish@release/v1
125-
with:
126-
# remove repository key to set the default to pypi (not test.pypi.org)
127-
repository-url: https://test.pypi.org/legacy/
128-
user: __token__
129-
password: ${{ secrets.PYPI_API_TOKEN }}
107+
name: Publish package
108+
if: startsWith(github.ref, 'refs/tags')
109+
needs:
110+
- format
111+
- lint
112+
- test
113+
- build_source_dist
114+
# - build_wheels
115+
runs-on: ubuntu-latest
116+
117+
steps:
118+
- uses: actions/download-artifact@v4
119+
with:
120+
name: artifact
121+
path: ./dist
122+
123+
- uses: pypa/gh-action-pypi-publish@release/v1
124+
with:
125+
# remove repository key to set the default to pypi (not test.pypi.org)
126+
repository-url: https://test.pypi.org/legacy/
127+
user: __token__
128+
password: ${{ secrets.PYPI_API_TOKEN }}

0 commit comments

Comments
 (0)