Skip to content

Commit bd699ca

Browse files
author
Patrick J. McNerthney
committed
Add PyPi build and publish
1 parent 3f77e4a commit bd699ca

File tree

3 files changed

+79
-21
lines changed

3 files changed

+79
-21
lines changed

.github/workflows/ci.yaml

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ on:
1414

1515
env:
1616
# Common versions
17-
PYTHON_VERSION: '3.12.11' # TODO: Used?
17+
PYTHON_VERSION: '3.13.7' # TODO: Used?
18+
HATCH_VERSION: '1.12.0'
1819
DOCKER_BUILDX_VERSION: 'v0.26.1'
1920

2021
# These environment variables are important to the Crossplane CLI install.sh
@@ -32,6 +33,9 @@ env:
3233
# XPKG: xpkg.upbound.io/${{ github.repository}}
3334
CROSSPLANE_REGORG: ghcr.io/${{ github.repository}}
3435

36+
# The PyPi project version to push. The default is v0.0.0+gitdate-gitsha.
37+
PYPI_VERSION: ${{ inputs.version }}
38+
3539
# The package version to push. The default is 0.0.0-gitsha.
3640
XPKG_VERSION: ${{ inputs.version }}
3741

@@ -86,11 +90,47 @@ jobs:
8690
#remove-link-from-badge: false
8791
#unique-id-for-comment: python3.8
8892

93+
build-pypi:
94+
runs-on: ubuntu-24.04
95+
steps:
96+
- name: Checkout
97+
uses: actions/checkout@v4
98+
99+
- name: Setup Python
100+
uses: actions/setup-python@v5
101+
with:
102+
python-version: ${{ env.PYTHON_VERSION }}
103+
104+
- name: Setup Hatch
105+
run: pipx install hatch==${{ env.HATCH_VERSION }}
106+
107+
# If a version wasn't explicitly passed as a workflow_dispatch input we
108+
# default to version v0.0.0+<git-commit-date>-<git-short-sha>, for example
109+
# v0.0.0+20231101115142-1091066df799. This is a simple implementation of
110+
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
111+
- name: Set Default PyPI Project Version
112+
if: env.PYPI_VERSION == ''
113+
run: echo "PYPI_VERSION=v0.0.0+$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" >> $GITHUB_ENV
114+
115+
- name: Set PyPI Project Version
116+
run: hatch version ${{ env.PYPI_VERSION }}
117+
118+
- name: Build Sdist and Wheel
119+
run: hatch build
120+
121+
- name: Upload Sdist and Wheel to GitHub
122+
uses: actions/upload-artifact@v4
123+
with:
124+
name: dist
125+
path: "dist/*"
126+
if-no-files-found: error
127+
retention-days: 1
128+
89129
# We want to build most packages for the amd64 and arm64 architectures. To
90130
# speed this up we build single-platform packages in parallel. We then upload
91131
# those packages to GitHub as a build artifact. The push job downloads those
92132
# artifacts and pushes them as a single multi-platform package.
93-
build:
133+
build-xpkg:
94134
runs-on: ubuntu-24.04
95135
strategy:
96136
fail-fast: true
@@ -142,16 +182,34 @@ jobs:
142182
if-no-files-found: error
143183
retention-days: 1
144184

185+
publish-pypi:
186+
# Don't publish unless we were run with an explicit version.
187+
if: ${{ inputs.version != '' }}
188+
needs:
189+
- build-pypi
190+
runs-on: ubuntu-24.04
191+
steps:
192+
- name: Download Sdist and Wheel from GitHub
193+
uses: actions/download-artifact@v5
194+
with:
195+
name: dist
196+
path: "dist"
197+
198+
- name: Publish to PyPI
199+
uses: pypa/gh-action-pypi-publish@v1.12.4
200+
with:
201+
password: ${{ secrets.PYPI_API_TOKEN }}
202+
145203
# This job downloads the single-platform packages built by the build job, and
146204
# pushes them as a multi-platform package. We only push the package it the
147205
# XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
148-
push:
206+
push-xpkg:
149207
runs-on: ubuntu-24.04
150208
permissions:
151209
contents: read
152210
packages: write
153211
needs:
154-
- build
212+
- build-xpkg
155213
steps:
156214
- name: Checkout
157215
uses: actions/checkout@v4

crossplane/pythonic/function.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -220,30 +220,30 @@ async def run_function(self, request):
220220

221221
def trimFullName(self, name):
222222
name = name.split('.')
223-
ix = 0
224223
for values in (
225-
('request', 'response'),
226-
('observed', 'desired'),
227-
('resources', 'extra_resources'),
228-
None,
229-
('resource', 'items'),
224+
('request', 'observed', 'resources', None, 'resource'),
225+
('request', 'extra_resources', None, 'items', 'resource'),
226+
('response', 'desired', 'resources', None, 'resource'),
230227
):
231-
if values:
232-
if ix < len(name):
228+
if len(values) <= len(name):
229+
for ix, value in enumerate(values):
230+
if value and value != name[ix] and not name[ix].startswith(f"{value}["):
231+
break
232+
else:
233+
ix = 0
233234
for value in values:
234-
if name[ix] == value:
235-
del name[ix]
236-
break
237-
if name[ix].startswith(f"{value}["):
238-
if ix:
235+
if value:
236+
if value == name[ix]:
237+
del name[ix]
238+
elif ix:
239239
name[ix-1] += name[ix][len(value):]
240240
del name[ix]
241241
else:
242242
name[ix] = name[ix][len(value):]
243243
ix += 1
244-
break
245-
else:
246-
ix += 1
244+
else:
245+
ix += 1
246+
break
247247
return '.'.join(name)
248248

249249

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "crossplane-function-pythonic"
3-
version = "0.0.6"
3+
version = "0.0.7"
44
description = 'A Python centric Crossplane Function'
55
readme = "README.md"
66
requires-python = ">=3.11,<3.14"

0 commit comments

Comments
 (0)