| 1 |
name: Release |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- main |
| 7 |
|
| 8 |
jobs: |
| 9 |
release: |
| 10 |
name: Release |
| 11 |
runs-on: ubuntu-latest |
| 12 |
steps: |
| 13 |
- name: Check out the repository |
| 14 |
uses: actions/[email protected] |
| 15 |
with: |
| 16 |
fetch-depth: 2 |
| 17 |
|
| 18 |
- name: Set up Python |
| 19 |
uses: actions/[email protected] |
| 20 |
with: |
| 21 |
python-version: "3.9" |
| 22 |
|
| 23 |
- name: Install build dependencies |
| 24 |
run: | |
| 25 |
python -m pip install --upgrade pip |
| 26 |
pip install setuptools wheel build |
| 27 |
|
| 28 |
- name: Check if there is a parent commit |
| 29 |
id: check-parent-commit |
| 30 |
run: | |
| 31 |
echo "sha=$(git rev-parse --verify --quiet HEAD^)" >> $GITHUB_OUTPUT |
| 32 |
|
| 33 |
- name: Check workspace |
| 34 |
run: | |
| 35 |
pwd ; ls -la |
| 36 |
|
| 37 |
- name: Detect and tag new version |
| 38 |
id: check-version |
| 39 |
if: steps.check-parent-commit.outputs.sha |
| 40 |
uses: salsify/[email protected] |
| 41 |
with: |
| 42 |
version-command: | |
| 43 |
sed -n 's/version = \"\(.*\)\"/\1/p' pyproject.toml |
| 44 |
|
| 45 |
- name: Bump version for developmental release |
| 46 |
if: "! steps.check-version.outputs.tag" |
| 47 |
run: | |
| 48 |
sed "s/version = \"\(.*\)\"/version = \"\1\.dev\.`date +%Y%m%d%H%M%S`\"/" -i pyproject.toml |
| 49 |
|
| 50 |
- name: Build package |
| 51 |
run: | |
| 52 |
python -m build . --wheel |
| 53 |
|
| 54 |
- name: Publish package on PyPI |
| 55 |
if: steps.check-version.outputs.tag |
| 56 |
uses: pypa/[email protected] |
| 57 |
with: |
| 58 |
user: __token__ |
| 59 |
password: ${{ secrets.PYPI_TOKEN }} |
| 60 |
|
| 61 |
- name: Publish package on TestPyPI |
| 62 |
if: "! steps.check-version.outputs.tag" |
| 63 |
uses: pypa/[email protected] |
| 64 |
with: |
| 65 |
user: __token__ |
| 66 |
password: ${{ secrets.TEST_PYPI_TOKEN }} |
| 67 |
repository_url: https://test.pypi.org/legacy/ |
| 68 |
|
| 69 |
- name: Publish release notes |
| 70 |
uses: release-drafter/[email protected] |
| 71 |
with: |
| 72 |
publish: ${{ steps.check-version.outputs.tag != '' }} |
| 73 |
tag: ${{ steps.check-version.outputs.tag }} |
| 74 |
env: |
| 75 |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |