Skip to content

Commit 0264a03

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

File tree

3 files changed

+74
-20
lines changed

3 files changed

+74
-20
lines changed

.github/workflows/ci.yaml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
env:
1616
# Common versions
17-
PYTHON_VERSION: '3.12.11' # TODO: Used?
17+
PYTHON_VERSION: '3.13.7' # TODO: Used?
1818
DOCKER_BUILDX_VERSION: 'v0.26.1'
1919

2020
# These environment variables are important to the Crossplane CLI install.sh
@@ -86,11 +86,47 @@ jobs:
8686
#remove-link-from-badge: false
8787
#unique-id-for-comment: python3.8
8888

89+
build-pypi:
90+
runs-on: ubuntu-24.04
91+
steps:
92+
- name: Checkout
93+
uses: actions/checkout@v4
94+
95+
- name: Setup Python
96+
uses: actions/setup-python@v5
97+
with:
98+
python-version: ${{ env.PYTHON_VERSION }}
99+
100+
- name: Setup Hatch
101+
run: pipx install hatch==${{ env.HATCH_VERSION }}
102+
103+
# If a version wasn't explicitly passed as a workflow_dispatch input we
104+
# default to version v0.0.0+<git-commit-date>-<git-short-sha>, for example
105+
# v0.0.0+20231101115142-1091066df799. This is a simple implementation of
106+
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
107+
- name: Set Default PyPI Project Version
108+
if: env.PYPI_VERSION == ''
109+
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
110+
111+
- name: Set PyPI Project Version
112+
run: hatch version ${{ env.PYPI_VERSION }}
113+
114+
- name: Build Sdist and Wheel
115+
run: hatch build
116+
117+
- name: Upload Sdist and Wheel to GitHub
118+
uses: actions/upload-artifact@v4
119+
with:
120+
name: dist
121+
path: "dist/*"
122+
if-no-files-found: error
123+
retention-days: 1
124+
89125
# We want to build most packages for the amd64 and arm64 architectures. To
90126
# speed this up we build single-platform packages in parallel. We then upload
91127
# those packages to GitHub as a build artifact. The push job downloads those
92128
# artifacts and pushes them as a single multi-platform package.
93-
build:
129+
build-xpkg:
94130
runs-on: ubuntu-24.04
95131
strategy:
96132
fail-fast: true
@@ -142,10 +178,28 @@ jobs:
142178
if-no-files-found: error
143179
retention-days: 1
144180

181+
publish:
182+
# Don't publish unless we were run with an explicit version.
183+
if: ${{ inputs.version != '' }}
184+
needs:
185+
- build
186+
runs-on: ubuntu-24.04
187+
steps:
188+
- name: Download Sdist and Wheel from GitHub
189+
uses: actions/download-artifact@v5
190+
with:
191+
name: dist
192+
path: "dist"
193+
194+
- name: Publish to PyPI
195+
uses: pypa/gh-action-pypi-publish@v1.12.4
196+
with:
197+
password: ${{ secrets.PYPI_API_TOKEN }}
198+
145199
# This job downloads the single-platform packages built by the build job, and
146200
# pushes them as a multi-platform package. We only push the package it the
147201
# XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
148-
push:
202+
push-xpkg:
149203
runs-on: ubuntu-24.04
150204
permissions:
151205
contents: read

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)