Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push to PyPI #28

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ on:
workflow_dispatch:
inputs:
version:
description: PyPI module version (e.g. v0.1.0)
description: PyPI project version (e.g. v0.1.0)
required: false

env:
# Common versions
PYTHON_VERSION: '3.11.5'

# The PyPi project version to push. The default is v0.0.0+gitdate-gitsha.
PYPI_VERSION: ${{ inputs.version }}

jobs:
lint:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -66,6 +69,17 @@ jobs:
- name: Setup Hatch
run: pipx install hatch==1.7.0

# If a version wasn't explicitly passed as a workflow_dispatch input we
# default to version v0.0.0+<git-commit-date>-<git-short-sha>, for example
# v0.0.0+20231101115142-1091066df799. This is a simple implementation of
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
- name: Set Default PyPI Project Version
if: env.PYPI_VERSION == ''
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

- name: Set PyPI Project Version
run: hatch version ${{ env.PYPI_VERSION }}

- name: Build Sdist and Wheel
run: hatch build

Expand All @@ -76,3 +90,24 @@ jobs:
path: "dist/*"
if-no-files-found: error
retention-days: 1


publish:
# Don't publish unless we were run with an explicit version.
if: ${{ inputs.version != '' }}
runs-on: ubuntu-22.04
steps:
- name: Download Sdist and Wheel from GitHub
uses: actions/download-artifact@v4
with:
name: module
path: "dist"

- name: Publish to PyPI
uses: pypa/[email protected]
with:
# Note that this is currently being pushed to the 'crossplane' PyPI
# user (not org). See @negz if you need access - PyPI requires 2FA to
# be enabled, which makes sharing the account hard. We're waiting for
# a crossplane org to be approved.
password: ${{ secrets.PYPI_API_TOKEN }}
18 changes: 18 additions & 0 deletions crossplane/function/__version__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 The Crossplane Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""The version of function-sdk-python."""

# This is set at build time, using "hatch version"
__version__ = "0.0.0"
7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[build-system]
requires = ["hatchling", "hatch-vcs"]
requires = ["hatchling"]
build-backend = "hatchling.build"

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

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

[tool.hatch.envs.default]
type = "virtual"
Expand Down