Skip to content

Commit

Permalink
Merge pull request #269 from DavidT3/pub/getReadyForPyPIPublish
Browse files Browse the repository at this point in the history
Pub/get ready for py pi publish
  • Loading branch information
DavidT3 committed Apr 25, 2024
2 parents 1bd9969 + c361811 commit 3f493a7
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 4 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/publish_to_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Created with the help of:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# and
# https://medium.com/@VersuS_/automate-pypi-releases-with-github-actions-4c5a9cfe947d

# This action triggers the second stage of publishing this module. When a new release is created this action will begin. It builds the module, then
# publishes it to the real PyPI index


# The overall name of the action
name: Publish DAXA to real PyPI, triggered on creation of release

# This action triggers when there is a release to the repo, but only when the release is published
on:
release:
types: [published]

# Now the actual jobs we want the action to do are set up
jobs:
# The only job in this action, building and publishing the DAXA Python module
build-n-publish:
name: Build and publish DAXA
# The build/publishing process runs on latest Ubuntu - not super important what this is for this use case
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/daxa # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

# This job has several steps
steps:
# Checks out the master branch and then activates a relatively recent version of Python
- uses: actions/checkout@v4
with:
fetch-depth: 0


- name: Setup the Python install
uses: actions/setup-python@v4
with:
python-version: 3.8

# The next two chunks set up PIP properly and build the module
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
# This SHOULD set the correct version in setup.py, taken from the tag
- name: Extract tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Update version in setup.py
run: >-
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
- name: Build a binary wheel and source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/


- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

93 changes: 93 additions & 0 deletions .github/workflows/publish_to_test_pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Created with the help of:
# https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/
# and
# https://medium.com/@VersuS_/automate-pypi-releases-with-github-actions-4c5a9cfe947d

# This action triggers the first stage of publishing this module. When a new tag is created and pushed to the remote
# repository, this action will begin. It builds the module, just as it would for an actual PyPI release, then uploads
# it to the Test PyPI index. That way I can test install the package from the test PyPI and not expose the real PyPI
# index to a potentially buggered version. When I verify that it works, a real publishing can be triggered by
# releasing the module.

# As a reminder to myself, the installation from test PyPI has to be done using this command (THE TEST PYPI PROJECT
# NAME IS DIFFERENT FROM THE ACTUAL NAME, BECAUSE THERE IS ALREADY A 'DAXA' PROJECT ON TEST PYPI):
# pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple daxa-xray

# The overall name of the action
name: Publish DAXA to test PyPI, triggered on creation of tags

# This action triggers when there is a push to the repo
on: push

# Now the actual jobs we want the action to do are setup
jobs:
# The only job in this action, building and publishing the DAXA Python module
build-n-publish:
name: Build and publish DAXA
# I actually only want to run this one if the pushed commit has a tag - I will only do this for new versions of the module
if: startsWith(github.ref, 'refs/tags')
# The build/publishing process runs on latest Ubuntu - not super important what this is for this use case
runs-on: ubuntu-latest
environment:
name: testpypi
url: https://test.pypi.org/p/daxa-xray # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

# This job has several steps
steps:
# Checks out the master branch and then activates a relatively recent version of Python
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup the Python install
uses: actions/setup-python@v4
with:
python-version: 3.8

# The next two chunks set up PIP properly and build the module
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
# This SHOULD set the correct version in setup.py, taken from the tag
- name: Extract tag name
id: tag
run: echo ::set-output name=TAG_NAME::$(echo $GITHUB_REF | cut -d / -f 3)
- name: Update version in setup.py
run: >-
sed -i "s/{{VERSION_PLACEHOLDER}}/${{ steps.tag.outputs.TAG_NAME }}/g" setup.py
- name: Build a binary wheel and source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

# # Then the module is published to the test PyPI index
# - name: Publish to TestPyPI
# uses: pypa/gh-action-pypi-publish@master
# with:
# password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# repository_url: https://test.pypi.org/legacy/
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1


6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
# This code is a part of the Democratising Archival X-ray Astronomy (DAXA) module.
# Last modified by David J Turner (turne540@msu.edu) 27/07/2023, 07:43. Copyright (c) The Contributors
# Last modified by David J Turner (turne540@msu.edu) 25/04/2024, 16:01. Copyright (c) The Contributors

from os import path

from setuptools import setup

# import versioneer

# Uses the README as the long description
this_directory = path.abspath(path.dirname(__file__))
with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

setup(
name='daxa',
version='0.1',
version='{{VERSION_PLACEHOLDER}}',
packages=['daxa'],
url='https://github.com/DavidT3/DAXA',
license='BSD 3',
Expand Down

0 comments on commit 3f493a7

Please sign in to comment.