Skip to content

Commit db2e268

Browse files
committed
add publish workflow
1 parent b6a0046 commit db2e268

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- pyproject.toml
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
environment:
14+
name: pypi
15+
url: https://pypi.org/p/tinybird-sdk
16+
permissions:
17+
contents: read
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Detect version change
25+
id: version_check
26+
run: |
27+
BEFORE_SHA="${{ github.event.before }}"
28+
AFTER_SHA="${{ github.sha }}"
29+
30+
BEFORE_VERSION="$(git show "${BEFORE_SHA}:pyproject.toml" 2>/dev/null | sed -nE 's/^version = "([^"]+)"/\1/p' | head -n1)"
31+
AFTER_VERSION="$(sed -nE 's/^version = "([^"]+)"/\1/p' pyproject.toml | head -n1)"
32+
33+
echo "before_version=${BEFORE_VERSION}" >> "$GITHUB_OUTPUT"
34+
echo "after_version=${AFTER_VERSION}" >> "$GITHUB_OUTPUT"
35+
36+
if [ -z "$AFTER_VERSION" ]; then
37+
echo "Could not read current version from pyproject.toml"
38+
exit 1
39+
fi
40+
41+
if [ "$BEFORE_VERSION" = "$AFTER_VERSION" ]; then
42+
echo "changed=false" >> "$GITHUB_OUTPUT"
43+
echo "No version bump detected (${AFTER_VERSION}); skipping publish."
44+
else
45+
echo "changed=true" >> "$GITHUB_OUTPUT"
46+
echo "Version changed: ${BEFORE_VERSION} -> ${AFTER_VERSION}"
47+
fi
48+
49+
- name: Set up Python
50+
if: steps.version_check.outputs.changed == 'true'
51+
uses: actions/setup-python@v5
52+
with:
53+
python-version: '3.11'
54+
55+
- name: Install build dependencies
56+
if: steps.version_check.outputs.changed == 'true'
57+
run: |
58+
python -m pip install --upgrade pip
59+
python -m pip install build
60+
61+
- name: Build distributions
62+
if: steps.version_check.outputs.changed == 'true'
63+
run: python -m build
64+
65+
- name: Publish package to PyPI
66+
if: steps.version_check.outputs.changed == 'true'
67+
uses: pypa/gh-action-pypi-publish@release/v1
68+
with:
69+
password: ${{ secrets.PYPI_TOKEN }}

0 commit comments

Comments
 (0)