-
Notifications
You must be signed in to change notification settings - Fork 75
153 lines (125 loc) · 4.15 KB
/
python-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
name: SolidsPy CI/CD Pipeline
on:
push:
branches:
- main
- "2.0"
tags:
- "v*.*.*"
pull_request:
branches:
- main
- "2.0"
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
test:
name: Test on Python ${{ matrix.python-version }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12", "3.13"]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install -e .[dev]
- name: Run tests with coverage
run: |
pytest --cov=solidspy tests/
- name: Generate coverage report
run: |
coverage xml
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.python-version }}
path: coverage.xml
release:
name: Release Process
needs: test
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Extract version from tag
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
- name: Validate VERSION Format
run: |
if [[ ! "${{ env.VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: ${{ env.VERSION }}"
exit 1
fi
- name: Update __version__ in __init__.py
run: |
sed -i 's|__version__ = ".*"|__version__ = "${{ env.VERSION }}"|' src/solidspy/__init__.py
- name: Update version in pyproject.toml
run: |
sed -i 's/version = ".*"/version = "${{ env.VERSION }}"/' pyproject.toml
- name: Update version in conda-recipe/meta.yaml
run: |
sed -i 's|{% set version = ".*" %}|{% set version = "'${{ env.VERSION }}'" %}|' conda-recipe/meta.yaml
- name: Update release in docs/conf.py
run: |
sed -i 's|release = ".*"|release = "${{ env.VERSION }}"|' docs/conf.py
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Commit version update
run: |
git add .
git commit -m "Update version to ${{ env.VERSION }}" || echo "No changes to commit"
- name: Push changes (Force)
uses: ad-m/github-push-action@v0.8.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: "2.0"
directory: .
force: true
# Build and Publish Steps
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install build tools
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build Python package
run: python -m build
- name: Publish package to TestPyPI
env:
TWINE_USERNAME: "__token__"
TWINE_PASSWORD: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: |
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/* --verbose
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: "3.10"
channels: conda-forge
use-mamba: false
- name: Install conda-build and anaconda-client via conda
run: |
conda install -y conda-build anaconda-client
conda list anaconda-client
- name: Build Conda package
run: conda build conda-recipe --output-folder dist -c conda-forge
- name: Upload Conda package
env:
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
run: |
for pkg in dist/*/*.tar.bz2; do
conda run -n base anaconda upload "$pkg" --force
done