Publish to PyPI #113
Workflow file for this run
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
name: Publish to PyPI | |
on: | |
release: | |
types: [published] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
env: | |
PYTHON_VERSION: "3.10" | |
outputs: | |
sdist-package-name: ${{ steps.build-package.outputs.sdist-package-name }} | |
bdist-package-name: ${{ steps.build-package.outputs.bdist-package-name }} | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
- id: build-package | |
run: | | |
python3 -m pip install --upgrade pip | |
python3 -m pip install setuptools | |
python3 -m pip install wheel | |
python3 -m pip install build | |
python3 -m pip install . | |
python3 -m build | |
echo "Contents of dist directory:" | |
ls -la dist/ | |
VERSION=${{ github.event.release.tag_name }} | |
SDIST_PACKAGE_NAME="schematicpy-${VERSION}.tar.gz" | |
BDIST_PACKAGE_NAME="schematicpy-${VERSION}-py3-none-any.whl" | |
RELEASE_URL_PREFIX="https://uploads.github.com/repos/${{ github.event.repository.full_name }}/releases/${{ github.event.release.id }}/assets?name=" | |
echo "sdist-package-name=$SDIST_PACKAGE_NAME" >> $GITHUB_OUTPUT | |
echo "bdist-package-name=$BDIST_PACKAGE_NAME" >> $GITHUB_OUTPUT | |
echo "sdist-release-url=${RELEASE_URL_PREFIX}${SDIST_PACKAGE_NAME}" >> $GITHUB_OUTPUT | |
echo "bdist-release-url=${RELEASE_URL_PREFIX}${BDIST_PACKAGE_NAME}" >> $GITHUB_OUTPUT | |
- name: upload-build-sdist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.build-package.outputs.sdist-package-name }} | |
path: dist/${{ steps.build-package.outputs.sdist-package-name }} | |
if-no-files-found: error | |
- name: upload-build-bdist | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ steps.build-package.outputs.bdist-package-name }} | |
path: dist/${{ steps.build-package.outputs.bdist-package-name }} | |
if-no-files-found: error | |
publish: | |
needs: build | |
runs-on: ubuntu-latest | |
environment: | |
name: ${{ github.event.release.prerelease == 'true' && 'testpypi' || 'pypi' }} | |
url: ${{ github.event.release.prerelease == 'true' && 'https://test.pypi.org/p/schematicpy' || 'https://pypi.org/p/schematicpy' }} | |
permissions: | |
id-token: write | |
steps: | |
- name: download-sdist | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ needs.build.outputs.sdist-package-name }} | |
path: dist | |
- name: download-bdist | |
uses: actions/download-artifact@v4 | |
with: | |
name: ${{ needs.build.outputs.bdist-package-name }} | |
path: dist | |
- name: deploy-to-test-pypi | |
if: 'github.event.release.prerelease' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
repository-url: https://test.pypi.org/legacy/ | |
- name: deploy-to-prod-pypi | |
if: '!github.event.release.prerelease' | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
slack-notification: | |
needs: publish | |
runs-on: ubuntu-latest | |
steps: | |
- name: post-slack-notification | |
id: slack | |
uses: slackapi/[email protected] | |
env: | |
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} | |
with: | |
# Post to the `fair-data-tools` slack channel | |
channel-id: 'C01ANC02U59' | |
slack-message: "A new version of Schematic has been released. Check out the new version: ${{ github.ref_name }}" |