Skip to content

Commit 7401cbe

Browse files
committed
ci workflow replacing main workflow
1 parent 0374e65 commit 7401cbe

File tree

3 files changed

+186
-46
lines changed

3 files changed

+186
-46
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Action: Setup Project (composite action)
2+
#
3+
# Purpose: Bootstrap a Python project in GitHub Actions by:
4+
# - Installing Task, uv, and uvx into a local ./bin directory
5+
# - Detecting presence of pyproject.toml and exposing it as an output
6+
# - Creating a virtual environment with uv and syncing dependencies
7+
#
8+
# Inputs:
9+
# - python-version: Python version used for the virtual environment (default: 3.12)
10+
#
11+
# Outputs:
12+
# - pyproject_exists: "true" if pyproject.toml exists, otherwise "false"
13+
#
14+
# Notes:
15+
# - Safe to run in repositories without pyproject.toml; dependency sync will be skipped.
16+
# - Used by workflows such as CI, Book, Marimo, and Release.
17+
18+
name: 'Setup Project'
19+
description: 'Setup the project'
20+
21+
inputs:
22+
python-version:
23+
description: 'Python version to use'
24+
required: false
25+
default: '3.12'
26+
27+
outputs:
28+
pyproject_exists:
29+
description: 'Flag indicating whether pyproject.toml exists'
30+
value: ${{ steps.check_pyproject.outputs.exists }}
31+
32+
runs:
33+
using: 'composite'
34+
steps:
35+
- name: Set up task, uv, uvx and the venv
36+
shell: bash
37+
run: |
38+
mkdir -p bin
39+
40+
# Add ./bin to the PATH
41+
echo "Adding ./bin to PATH"
42+
echo "$(pwd)/bin" >> $GITHUB_PATH
43+
44+
# Install Task
45+
curl -fsSL https://taskfile.dev/install.sh | sh -s -- -d -b ./bin
46+
47+
# Install uv and uvx
48+
curl -fsSL https://astral.sh/uv/install.sh | UV_INSTALL_DIR="./bin" sh
49+
50+
- name: Check version for task
51+
shell: bash
52+
run: |
53+
task --version
54+
55+
- name: Check version for uv
56+
shell: bash
57+
run: |
58+
uv --version
59+
60+
- name: Check for pyproject.toml
61+
id: check_pyproject
62+
shell: bash
63+
run: |
64+
if [ -f "pyproject.toml" ]; then
65+
echo "exists=true" >> "$GITHUB_OUTPUT"
66+
else
67+
echo "exists=false" >> "$GITHUB_OUTPUT"
68+
fi
69+
70+
- name: Build the virtual environment
71+
shell: bash
72+
run: uv venv --python ${{ inputs.python-version }}
73+
74+
- name: "Sync the virtual environment for ${{ github.repository }} if pyproject.toml exists"
75+
shell: bash
76+
run: |
77+
if [ -f "pyproject.toml" ]; then
78+
uv sync --all-extras
79+
else
80+
echo "No pyproject.toml found, skipping package installation"
81+
fi

.github/workflows/ci.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This file is part of the tschm/.config-templates repository
2+
# (https://github.com/tschm/.config-templates).
3+
#
4+
# Workflow: Continuous Integration
5+
#
6+
# Purpose: This workflow runs tests on multiple Python versions to ensure
7+
# compatibility and code quality across different environments.
8+
#
9+
# Trigger: This workflow runs on every push and on pull requests to main/master
10+
# branches (including from forks)
11+
#
12+
# Components:
13+
# - 🧪 Run tests on multiple Python versions
14+
# - 🔄 Matrix strategy for testing on different environments
15+
16+
name: "CI"
17+
18+
permissions:
19+
contents: read
20+
21+
on:
22+
push:
23+
pull_request:
24+
branches: [ main, master ]
25+
26+
jobs:
27+
test:
28+
# if: github.repository != 'tschm/.config-templates'
29+
# The type of runner that the job will run on
30+
runs-on: ${{ matrix.os }}
31+
32+
strategy:
33+
matrix:
34+
# mongo container action only supported on Linux
35+
os: [ ubuntu-latest ]
36+
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14']
37+
38+
# Steps represent a sequence of tasks that will be executed as part of the job
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v5
42+
with:
43+
lfs: true
44+
45+
# Use the composite action to set up the project
46+
- name: Setup the project
47+
id: setup
48+
uses: ./.github/actions/setup-project
49+
with:
50+
python-version: ${{ matrix.python-version }}
51+
52+
- name: "Run the tests"
53+
run: |
54+
# if there is a tests/requirements.txt file, install it
55+
if [ -f "tests/requirements.txt" ]; then
56+
uv pip install -r tests/requirements.txt
57+
fi
58+
uv pip install pytest
59+
uv run pytest tests

.github/workflows/main.yml

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3-
4-
name: pytest
5-
6-
on:
7-
push:
8-
branches: ["main"]
9-
pull_request:
10-
branches: ["main"]
11-
12-
jobs:
13-
pytest:
14-
name: py${{ matrix.python-version }} on ${{ matrix.os }}
15-
runs-on: ${{ matrix.os }}
16-
env:
17-
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
18-
strategy:
19-
matrix:
20-
os: [ubuntu-latest, macos-latest, windows-latest]
21-
python-version: ["3.9", "3.10", "3.11", "3.12"]
22-
23-
steps:
24-
- uses: actions/checkout@v4
25-
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v5
27-
with:
28-
python-version: ${{ matrix.python-version }}
29-
cache: "pip"
30-
- name: Install dependencies
31-
run: |
32-
pip install -r requirements.txt
33-
pip install pytest isort black flake8
34-
pip install ecos
35-
- name: Test with pytest
36-
run: |
37-
pytest ./tests
38-
- name: Check with isort
39-
run: |
40-
isort --check --diff .
41-
- name: Check with black
42-
run: |
43-
black --check --diff .
44-
- name: Check with flake8
45-
run: |
46-
flake8 --show-source --statistics .
1+
## This workflow will install Python dependencies, run tests and lint with a variety of Python versions
2+
## For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
3+
#
4+
#name: pytest
5+
#
6+
#on:
7+
# push:
8+
# branches: ["main"]
9+
# pull_request:
10+
# branches: ["main"]
11+
#
12+
#jobs:
13+
# pytest:
14+
# name: py${{ matrix.python-version }} on ${{ matrix.os }}
15+
# runs-on: ${{ matrix.os }}
16+
# env:
17+
# MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
18+
# strategy:
19+
# matrix:
20+
# os: [ubuntu-latest, macos-latest, windows-latest]
21+
# python-version: ["3.9", "3.10", "3.11", "3.12"]
22+
#
23+
# steps:
24+
# - uses: actions/checkout@v4
25+
# - name: Set up Python ${{ matrix.python-version }}
26+
# uses: actions/setup-python@v5
27+
# with:
28+
# python-version: ${{ matrix.python-version }}
29+
# cache: "pip"
30+
# - name: Install dependencies
31+
# run: |
32+
# pip install -r requirements.txt
33+
# pip install pytest
34+
# pip install ecos
35+
# - name: Test with pytest
36+
# run: |
37+
# pytest ./tests
38+
# #- name: Check with isort
39+
# # run: |
40+
# # isort --check --diff .
41+
# #- name: Check with black
42+
# # run: |
43+
# # black --check --diff .
44+
# #- name: Check with flake8
45+
# # run: |
46+
# # flake8 --show-source --statistics .

0 commit comments

Comments
 (0)