Skip to content

Commit b143432

Browse files
authored
Merge pull request #28 from negz/like-a-version
Push to PyPI
2 parents aa3e0e2 + c1e5e20 commit b143432

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ on:
99
workflow_dispatch:
1010
inputs:
1111
version:
12-
description: PyPI module version (e.g. v0.1.0)
12+
description: PyPI project version (e.g. v0.1.0)
1313
required: false
1414

1515
env:
1616
# Common versions
1717
PYTHON_VERSION: '3.11.5'
1818

19+
# The PyPi project version to push. The default is v0.0.0+gitdate-gitsha.
20+
PYPI_VERSION: ${{ inputs.version }}
21+
1922
jobs:
2023
lint:
2124
runs-on: ubuntu-22.04
@@ -66,6 +69,17 @@ jobs:
6669
- name: Setup Hatch
6770
run: pipx install hatch==1.7.0
6871

72+
# If a version wasn't explicitly passed as a workflow_dispatch input we
73+
# default to version v0.0.0+<git-commit-date>-<git-short-sha>, for example
74+
# v0.0.0+20231101115142-1091066df799. This is a simple implementation of
75+
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
76+
- name: Set Default PyPI Project Version
77+
if: env.PYPI_VERSION == ''
78+
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
79+
80+
- name: Set PyPI Project Version
81+
run: hatch version ${{ env.PYPI_VERSION }}
82+
6983
- name: Build Sdist and Wheel
7084
run: hatch build
7185

@@ -76,3 +90,24 @@ jobs:
7690
path: "dist/*"
7791
if-no-files-found: error
7892
retention-days: 1
93+
94+
95+
publish:
96+
# Don't publish unless we were run with an explicit version.
97+
if: ${{ inputs.version != '' }}
98+
runs-on: ubuntu-22.04
99+
steps:
100+
- name: Download Sdist and Wheel from GitHub
101+
uses: actions/download-artifact@v4
102+
with:
103+
name: module
104+
path: "dist"
105+
106+
- name: Publish to PyPI
107+
uses: pypa/[email protected]
108+
with:
109+
# Note that this is currently being pushed to the 'crossplane' PyPI
110+
# user (not org). See @negz if you need access - PyPI requires 2FA to
111+
# be enabled, which makes sharing the account hard. We're waiting for
112+
# a crossplane org to be approved.
113+
password: ${{ secrets.PYPI_API_TOKEN }}

crossplane/function/__version__.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2023 The Crossplane Authors.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""The version of function-sdk-python."""
16+
17+
# This is set at build time, using "hatch version"
18+
__version__ = "0.0.0"

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[build-system]
2-
requires = ["hatchling", "hatch-vcs"]
2+
requires = ["hatchling"]
33
build-backend = "hatchling.build"
44

55
[project]
6-
name = "function-sdk-python"
6+
name = "crossplane-function-sdk-python"
77
description = 'The Python SDK for Crossplane composition functions'
88
readme = "README.md"
99
requires-python = ">=3.11"
@@ -30,7 +30,8 @@ Issues = "https://github.com/crossplane/function-sdk-python/issues"
3030
Source = "https://github.com/crossplane/function-sdk-python"
3131

3232
[tool.hatch.version]
33-
source = "vcs"
33+
path = "crossplane/function/__version__.py"
34+
validate-bump = false # Allow going from 0.0.0.dev0+x to 0.0.0.dev0+y.
3435

3536
[tool.hatch.envs.default]
3637
type = "virtual"

0 commit comments

Comments
 (0)