1- name : CI
1+ # .github/workflows/ci.yml
2+ name : CI and Publish
23
4+ # Trigger on pushes/PRs to main AND pushes of tags starting with 'v'
35on :
46 push :
57 branches : [ "main" ]
8+ tags :
9+ - ' v*' # Trigger on tags like v0.1.0, v1.2.3, etc.
610 pull_request :
711 branches : [ "main" ]
812
913jobs :
10- build : # You can rename this job if you like, e.g., 'test' or 'checks'
14+ # Job 1: Run linters, type checks, and tests
15+ test_and_lint : # Renamed for clarity
1116 runs-on : ubuntu-latest
1217 strategy :
13- fail-fast : false # Keep running other matrix jobs even if one fails
18+ fail-fast : false
1419 matrix :
15- python-version : ["3.10", "3.11"] # Add/remove versions as needed
20+ python-version : ["3.10", "3.11"] # Test on relevant Python versions
1621
1722 steps :
1823 - name : Check out code
@@ -22,28 +27,58 @@ jobs:
2227 uses : actions/setup-python@v5
2328 with :
2429 python-version : ${{ matrix.python-version }}
25- cache : ' pip' # Enable caching for pip dependencies to speed up runs
30+ cache : ' pip'
2631
27- - name : Install dependencies
32+ - name : Install dependencies (including test extras)
2833 run : |
2934 python -m pip install --upgrade pip
30- # This command installs the 'codeconcat' package itself
31- # plus all packages listed under [project.optional-dependencies.test]
32- # in your pyproject.toml file (e.g., ruff, mypy, pytest).
33- pip install .[test]
35+ pip install .[test] # Installs package + ruff, mypy, pytest etc.
3436
3537 - name : Lint and Format Check with Ruff
3638 run : |
37- # Check if code is formatted according to Ruff rules (like black)
3839 ruff format --check .
39- # Check for code style issues, import errors, etc. (like flake8, isort)
4040 ruff check .
4141
4242 - name : Analyse code with Mypy
4343 run : |
44- # Ensure mypy runs on your source code and test directories
45- mypy codeconcat tests # Adjust these paths if your structure differs
44+ mypy codeconcat tests # Adjust paths if needed
4645
47- - name : Run tests with Pytest
46+ # Optional: Uncomment if you have pytest tests
47+ # - name: Run tests with Pytest
48+ # run: |
49+ # pytest
50+
51+ # Job 2: Publish package to PyPI on tagged commits
52+ publish :
53+ # Only run this job if the trigger was a tag push starting with 'v'
54+ if : startsWith(github.ref, 'refs/tags/v')
55+ # Only run this job if the 'test_and_lint' job succeeded
56+ needs : test_and_lint
57+ runs-on : ubuntu-latest
58+
59+ # Grant permissions for GitHub's OIDC token to be used for PyPI Trusted Publishing
60+ permissions :
61+ id-token : write # Essential for Trusted Publishing
62+
63+ steps :
64+ - name : Check out code
65+ uses : actions/checkout@v4
66+
67+ - name : Set up Python for publishing
68+ uses : actions/setup-python@v5
69+ with :
70+ python-version : ' 3.11' # Use a specific Python version for building/publishing
71+
72+ - name : Install build dependencies
4873 run : |
49- pytest
74+ python -m pip install --upgrade pip
75+ pip install build twine # Tools needed to build and upload the package
76+
77+ - name : Build package
78+ run : python -m build # Creates wheel and sdist in dist/ directory
79+
80+ - name : Publish package to PyPI
81+ # Twine will automatically use the OIDC token provided by the runner environment
82+ # when run in a job with 'id-token: write' permissions.
83+ # Ensure you have configured Trusted Publishing on PyPI for this repo/workflow.
84+ run : twine upload dist/*
0 commit comments