Skip to content

Commit a5f6a19

Browse files
committed
ci: Add GitHub Actions workflows for testing and publishing.
1 parent 3e51a01 commit a5f6a19

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

.github/workflows/publish.yml

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: Publish to PyPI
2+
3+
on:
4+
push:
5+
tags:
6+
- '[0-9]+.[0-9]+.[0-9]+' # Matches semantic versioning tags
7+
- '[0-9]+.[0-9]+.[0-9]+-test.*' # Test releases
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
15+
16+
steps:
17+
- uses: actions/checkout@v3
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install pytest
28+
pip install -e .
29+
30+
- name: Run tests
31+
run: pytest
32+
33+
publish:
34+
needs: test
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
39+
- name: Set up Python
40+
uses: actions/setup-python@v4
41+
with:
42+
python-version: '3.x'
43+
44+
- name: Install build tools
45+
run: |
46+
python -m pip install --upgrade pip
47+
pip install build twine
48+
49+
- name: Verify tag version matches package version
50+
run: |
51+
PACKAGE_VERSION=$(python setup.py --version)
52+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
53+
if [ "$PACKAGE_VERSION" != "$TAG_VERSION" ]; then
54+
echo "Package version ($PACKAGE_VERSION) does not match tag version ($TAG_VERSION)"
55+
exit 1
56+
fi
57+
58+
- name: Build package
59+
run: python -m build
60+
61+
- name: Publish to TestPyPI
62+
if: contains(github.ref, 'test')
63+
env:
64+
TWINE_USERNAME: __token__
65+
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
66+
run: twine upload --repository testpypi dist/*
67+
68+
- name: Publish to PyPI
69+
if: "!contains(github.ref, 'test')"
70+
env:
71+
TWINE_USERNAME: __token__
72+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
73+
run: twine upload dist/*
74+
75+
- name: Create Release
76+
uses: softprops/action-gh-release@v1
77+
with:
78+
files: dist/*
79+
generate_release_notes: true
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/windows-test.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Windows Package Test
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
# Optional: manual trigger
8+
workflow_dispatch:
9+
10+
jobs:
11+
test-windows:
12+
runs-on: windows-latest
13+
strategy:
14+
matrix:
15+
python-version: ['3.11', '3.12']
16+
architecture: ['x64']
17+
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: actions/cache@v3
21+
with:
22+
path: ~\AppData\Local\pip\Cache
23+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
24+
25+
- name: Set up Python ${{ matrix.python-version }} ${{ matrix.architecture }}
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
architecture: ${{ matrix.architecture }}
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install pytest pytest-cov
35+
pip install -e .
36+
37+
- name: Run tests
38+
run: |
39+
pytest --cov=cedarscript_ast_parser tests/
40+
- name: Test PyPI installation
41+
run: |
42+
pip uninstall cedarscript-ast-parser -y
43+
pip install cedarscript-ast-parser
44+
python -c "from cedarscript_ast_parser import CEDARScriptASTParser; CEDARScriptASTParser()"
45+
46+
# Optional: Upload artifacts if your package generates any
47+
- name: Upload artifacts
48+
if: failure()
49+
uses: actions/upload-artifact@v3
50+
with:
51+
name: test-artifacts
52+
path: |
53+
./*.log
54+
./tests/results

tests/test_parser.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import pytest
2+
from cedarscript_ast_parser import CEDARScriptASTParser
3+
4+
5+
def test_can_instantiate_parser():
6+
"""Test that we can create a CEDARScriptASTParser instance"""
7+
CEDARScriptASTParser()

0 commit comments

Comments
 (0)