-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9ceeba5
commit 852122d
Showing
2 changed files
with
122 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,69 @@ | ||
# This workflow will upload a Python Package using Twine when a release is created | ||
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Upload Python Package | ||
name: Build, Test, and Publish | ||
on: | ||
# Run this workflow everytime a pull request is opened to main | ||
# to test the changes. | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
# Run this workflow every time a new release is created | ||
release: | ||
types: [published] | ||
|
||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
|
||
jobs: | ||
deploy: | ||
name: Build and deploy PyPi package | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
# Set up Python 3.x | ||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
# Install dependencies | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install build | ||
# Get the version of the package | ||
- name: Package Version | ||
id: package-version | ||
uses: paulhatch/semantic-version@v5.4.0 | ||
with: | ||
major_pattern: "(MAJOR)" | ||
minor_pattern: "(MINOR)" | ||
|
||
# Build the package using the version | ||
- name: Build package | ||
run: python -m build | ||
run: | | ||
export MAJOR=${{ steps.package-version.outputs.major }} | ||
export MINOR=${{ steps.package-version.outputs.minor }} | ||
export PATCH=${{ steps.package-version.outputs.patch }} | ||
echo "Building version $MAJOR.$MINOR.$PATCH" | ||
python -m build | ||
# Load the secret from 1Password | ||
- name: Load secret | ||
id: op-load-secret | ||
uses: 1password/load-secrets-action@v2 | ||
with: | ||
export-env: false | ||
env: | ||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }} | ||
SECRET: op://development/msmp5ffdzke4oke7o627ufud6e/credential | ||
|
||
# Publish the package to PyPi if a release is created | ||
- name: Publish package | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
if: github.event_name == 'release' | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} | ||
password: ${{ steps.op-load-secret.outputs.SECRET }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,76 @@ | ||
try: | ||
from setuptools import setup | ||
except ImportError: | ||
from distutils.core import setup | ||
|
||
long_description = open('README.md').read() | ||
|
||
setup( | ||
name='panda3d_astron', | ||
description='Panda3D Astron server support as a Python 3 module. Allows the use of Astron with stock Panda3D', | ||
long_description=long_description, | ||
license='MIT', | ||
version='1.0.2', | ||
author='Jordan Maxwell', | ||
maintainer='Jordan Maxwell', | ||
url='https://github.com/thetestgame/panda3d_astron', | ||
packages=['panda3d_astron'], | ||
install_requires=['panda3d'], | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
]) | ||
""" | ||
Setup script for building the module into a package for publishing to PyPI. | ||
""" | ||
|
||
from setuptools import setup | ||
import sys | ||
import os | ||
|
||
def get_version() -> str: | ||
""" | ||
Get the package version from the environment variables. | ||
""" | ||
|
||
major = os.environ.get('MAJOR', '1') | ||
minor = os.environ.get('MINOR', '0') | ||
patch = os.environ.get('PATCH', '0') | ||
|
||
return f'{major}.{minor}.{patch}' | ||
|
||
def get_readme(filename: str = 'README.md') -> str: | ||
""" | ||
Returns the contents of the requested README file | ||
""" | ||
|
||
with open(filename, 'r') as file: | ||
return file.read() | ||
|
||
def get_requirements(filename: str = 'requirements.txt') -> list: | ||
""" | ||
Returns the contents of the requested requirements.txt | ||
file | ||
""" | ||
|
||
with open(filename, 'r') as file: | ||
return [line.strip() for line in file if line.strip() and not line.startswith('#')] | ||
|
||
def get_package_url(main_module: str) -> str: | ||
""" | ||
Returns the URL for the package | ||
""" | ||
|
||
repository_name = main_module.replace('_', '-') | ||
return f'https://github.com/thetestgame/{repository_name}' | ||
|
||
def main() -> int: | ||
""" | ||
Main entry point for the setup script | ||
""" | ||
|
||
# Define some constants | ||
module_name = 'panda3d_astron' | ||
|
||
# Run the setup | ||
setup( | ||
name=module_name, | ||
description='', | ||
long_description=get_readme(), | ||
long_description_content_type='text/markdown', | ||
license='MIT', | ||
version=get_version(), | ||
author='Jordan Maxwell', | ||
maintainer='Jordan Maxwell', | ||
url=get_package_url(module_name), | ||
packages=[module_name], | ||
install_requires=[ | ||
"panda3d" | ||
], | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
]) | ||
|
||
return 0 | ||
|
||
# Run the main function | ||
if __name__ == '__main__': | ||
sys.exit(main()) |