Skip to content

Commit aa8c425

Browse files
authored
Merge pull request #7 from IfcLCA/main
package
2 parents 9d8e1b5 + e79adf9 commit aa8c425

1 file changed

Lines changed: 44 additions & 21 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,87 @@ name: Python package
33
on:
44
push:
55
branches: ["release"]
6+
tags: ["v*"]
67
pull_request:
78
branches: ["release"]
89
workflow_dispatch:
910

1011
jobs:
1112
build:
1213
runs-on: ubuntu-latest
13-
strategy:
14-
fail-fast: false
15-
matrix:
16-
python-version: ["3.9", "3.10", "3.11"]
17-
1814
steps:
1915
- uses: actions/checkout@v4
20-
- name: Set up Python ${{ matrix.python-version }}
16+
17+
- name: Set up Python 3.12
2118
uses: actions/setup-python@v3
2219
with:
23-
python-version: ${{ matrix.python-version }}
20+
python-version: "3.12"
21+
2422
- name: Install dependencies
2523
run: |
2624
python -m pip install --upgrade pip
2725
python -m pip install flake8 pytest
2826
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
2928
- name: Lint with flake8
3029
run: |
31-
# Stop the build if there are Python syntax errors or undefined names
30+
# Stop the build on syntax errors or undefined names
3231
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
33-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
32+
# Treat all other errors as warnings
3433
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
35-
# - name: Test with pytest
36-
# run: |
37-
# pytest
3834
3935
publish:
40-
if: github.ref == 'refs/heads/release'
41-
runs-on: ubuntu-latest
36+
if: startsWith(github.ref, 'refs/tags/v')
4237
needs: build
38+
runs-on: ubuntu-latest
4339
environment: release
40+
4441
steps:
4542
- uses: actions/checkout@v4
46-
- name: Set up Python
43+
44+
- name: Set up Python 3.12
4745
uses: actions/setup-python@v3
4846
with:
49-
python-version: "3.10"
47+
python-version: "3.12"
48+
5049
- name: Install dependencies
5150
run: |
5251
python -m pip install --upgrade pip
5352
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
54-
- name: Install wheel
53+
54+
- name: Install wheel & twine
55+
run: |
56+
python -m pip install wheel twine
57+
58+
- name: Extract and validate version from tag
59+
id: get_version
5560
run: |
56-
python -m pip install wheel
61+
# Extract version from tag (remove 'v' prefix)
62+
VERSION=${GITHUB_REF#refs/tags/v}
63+
64+
# Validate version format (allows for alpha/beta versions)
65+
if ! [[ $VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+(a|b|rc)?[0-9]*$ ]]; then
66+
echo "Error: Invalid version format. Expected format: X.Y.Z[a|b|rc]N (e.g., 0.1.0a1)"
67+
exit 1
68+
fi
69+
70+
echo "VERSION=$VERSION" >> $GITHUB_ENV
71+
echo "Using version: $VERSION"
72+
73+
- name: Update version in setup.py
74+
run: |
75+
# Update the version in setup.py dynamically
76+
sed -i "s/version='[^']*'/version='$VERSION'/" setup.py
77+
echo "Updated setup.py with version: $VERSION"
78+
grep "version=" setup.py
79+
5780
- name: Build package
5881
run: |
5982
python setup.py sdist bdist_wheel
60-
- name: Publish package
83+
84+
- name: Publish to PyPI
6185
run: |
62-
python -m pip install twine
63-
twine upload dist/*
86+
twine upload --skip-existing dist/*
6487
env:
6588
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
6689
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}

0 commit comments

Comments
 (0)