feat: added ci that push to pypi

This commit is contained in:
Jordan ⌨️ 2023-02-22 17:23:15 +01:00
parent b9258d530f
commit 5f1c796003
5 changed files with 54 additions and 4 deletions

40
.github/workflows/pypi.yaml vendored Normal file
View file

@ -0,0 +1,40 @@
name: Publish to Pypi
on:
release:
types: [published]
jobs:
publish:
name: Publish to PyPI
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Python3
run: |
sudo apt-get update
sudo apt-get install python3 python3-pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Extract tag name
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Set version to tag
run: |
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" osdk/const.py
- name: Build a binary wheel
run: |
python setup.py sdist bdist_wheel
- name: Publish a Python distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

View file

@ -145,7 +145,7 @@ cmds += [Cmd("h", "help", "Show this help message", helpCmd)]
def versionCmd(args: Args):
print(f"OSDK v{const.VERSION}\n")
print(f"OSDK v{const.get_version()}\n")
cmds += [Cmd("v", "version", "Show current version", versionCmd)]

View file

@ -1,7 +1,8 @@
import os
import sys
import subprocess
VERSION = "0.4.0"
VERSION = "{{VERSION_PLACEHOLDER}}"
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
ARGV0 = os.path.basename(sys.argv[0])
OSDK_DIR = ".osdk"

View file

@ -2,6 +2,8 @@ from typing import Any, TypeVar, cast
import json
import hashlib
from osdk import shell, const
T = TypeVar('T')
@ -56,3 +58,10 @@ def asList(i: T | list[T] | None) -> list[T]:
if isinstance(i, list):
return cast(list[T], i)
return [i]
def get_version() -> str:
if const.VERSION == "{{VERSION_PLACEHOLDER}}":
return str(int(shell.popen(*["git", "rev-parse", "--short", "HEAD"])[:-1], 16))
else:
return const.VERSION

View file

@ -1,9 +1,9 @@
from setuptools import setup
from osdk.const import VERSION
from osdk.utils import get_version
setup(
name="osdk",
version=VERSION,
version=get_version(),
python_requires='>=3.10',
description="Operating System Development Kit",
author="The DEVSE Community",