diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 36931d5e9..0cc464924 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,105 +1,92 @@ name: Publish to PyPI on: - push: - tags: - - 'v[1-9][0-9].[0-9]+.[0-9]+' - branches: [main] + release: + types: [published] jobs: - pypi_release: + build: runs-on: ubuntu-22.04 env: - POETRY_VERSION: 1.3.0 PYTHON_VERSION: "3.10" - if: github.event_name == 'push' && contains(github.ref, 'refs/tags') + outputs: + sdist-package-name: ${{ steps.build-package.outputs.sdist-package-name }} + bdist-package-name: ${{ steps.build-package.outputs.bdist-package-name }} steps: - #---------------------------------------------- - # check-out repo and set-up python - #---------------------------------------------- - - name: Check out repository - uses: actions/checkout@v4 - - - name: Set up Python ${{ env.PYTHON_VERSION }} - uses: actions/setup-python@v5 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 with: python-version: ${{ env.PYTHON_VERSION }} - - #---------------------------------------------- - # install & configure poetry - #---------------------------------------------- - - name: Install Poetry + - id: build-package run: | - curl -sSL https://install.python-poetry.org \ - | python3 - --version ${{ env.POETRY_VERSION }}; - poetry config virtualenvs.create true; - poetry config virtualenvs.in-project true; + 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 - #---------------------------------------------- - # install dependencies and root project - #---------------------------------------------- - - name: Install dependencies and root project - run: poetry install --no-interaction --all-extras + 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=" - #---------------------------------------------- - # get current pushed tag - #---------------------------------------------- - - name: Show GitHub ref - run: echo "$GITHUB_REF" + echo "sdist-package-name=$SDIST_PACKAGE_NAME" >> $GITHUB_OUTPUT + echo "bdist-package-name=$BDIST_PACKAGE_NAME" >> $GITHUB_OUTPUT - - name: Get current pushed tag - run: | - echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - echo "$RELEASE_VERSION" + 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: Override version tag - run: poetry run python3 override_version.py - shell: sh + - name: upload-sdist-artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.build-package.outputs.sdist-package-name }} + path: dist/ + if-no-files-found: error - #---------------------------------------------- - # publish to testpypi - #---------------------------------------------- - # - run: poetry config repositories.testpypi https://test.pypi.org/legacy/ - # - run: poetry config pypi-token.testpypi ${{ secrets.TWINE_TEST_TOKEN }} - # - name: Publish package to test Pypi - # run: poetry publish -vvvv --build -r testpypi + - name: upload-bdist-artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.build-package.outputs.bdist-package-name }} + path: dist/ + if-no-files-found: error - #---------------------------------------------- - # check tag - #---------------------------------------------- - - name: Check Tag - id: check-tag - run: | - if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo ::set-output name=match::true - fi - #---------------------------------------------- - # publish to pypi - #---------------------------------------------- - - name: Publish package to Pypi - id: publish-to-pypi - if: steps.check-tag.outputs.match == 'true' - env: - PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }} - PYPI_USERNAME: __token__ - run: | - poetry publish --build --username $PYPI_USERNAME --password $PYPI_TOKEN + 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 - #---------------------------------------------- - # post a message to slack - #---------------------------------------------- + - name: deploy-to-pypi + uses: pypa/gh-action-pypi-publish@release/v1 + with: + repository-url: ${{ github.event.release.prerelease == true && 'https://test.pypi.org/legacy/' || '' }} - - name: Post to a Slack channel - if: steps.publish-to-pypi.outcome == 'success' + slack-notification: + needs: publish + if: ${{ github.event.release.prerelease != true }} + runs-on: ubuntu-latest + steps: + - name: post-slack-notification id: slack uses: slackapi/slack-github-action@v1.23.0 - with: - # Slack channel id, channel name, or user id to post message. - # See also: https://api.slack.com/methods/chat.postMessage#channels - # You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs. - # ibc-fair-data channel and data-curator-schematic channel - channel-id: 'C050YD75QRL,C01ANC02U59' - # For posting a simple plain text message - slack-message: "Schematic has just been released. Check out new version: ${{ github.ref_name }}" 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 }}" diff --git a/CONTRIBUTION.md b/CONTRIBUTION.md index fedbbdb3e..c9d8b26ae 100644 --- a/CONTRIBUTION.md +++ b/CONTRIBUTION.md @@ -80,31 +80,24 @@ Be consistent and follow existing code conventions and spirit. Once the code has been merged into the `develop` branch on this repo, there are two processes that need to be completed to ensure a _release_ is complete. -- You should create a GitHub [tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging), with the appropriate version number. Typically, from `v21.06` onwards all tags are created following the Linux Ubuntu versioning convention which is the `YY.MM` format where `Y` is the year and `M` is the month of that year when that release was created. -- You should push the package to [PyPI](https://pypi.org/). Schematic is on PyPI as [schematicpy](https://pypi.org/project/schematicpy/). You can go through the following two sections for that. +### Create a GitHub tag -### Release to Test PyPI _(optional)_ +A GitHub [tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging) should be created with the appropriate version number. Typically, from `v21.06` onwards all tags are created following the Linux Ubuntu versioning convention which is the `YY.MM` format where `Y` is the year and `M` is the month of that year when that release was created. When creating a release-candidate for a new version, the tag should be created with the `-rc` suffix. The final release tag should be created without the `-rc` suffix. -The purpose of this section is to verify that the package looks and works as intended, by viewing it on [Test PyPI](https://test.pypi.org/) and installing the test version in a separate virtual environment. +### Release to Test PyPI -``` -poetry build # build the package -poetry config repositories.testpypi https://test.pypi.org/legacy/ # add Test PyPI as an alternate package repository -poetry publish -r testpypi # publish the package to Test PyPI -``` - -Installing: +When a release-candidate is created and published in Github (with the `-rc` suffix and the `prerelease` flag set to `true`), the package will be published to [Test PyPI](https://test.pypi.org/). Testing against the release-candidate can be performed by installing the `-rc` package from Test PyPI. ``` -pip install --index-url https://test.pypi.org/simple/ +pip install -i https://test.pypi.org/simple/ schematicpy ``` ### Release to PyPI _(mandatory)_ -If the package looks great on Test PyPI and works well, the next step is to publish the package to PyPI: +When a release (no `-rc` suffix and the `prerelease` flag set to `false`) is created from a validated release-candidate, the package will be published to [PyPI](https://pypi.org/) automatically. The new version will be available for installation with the following command: ``` -poetry publish # publish the package to PyPI +pip install schematicpy ``` > You'll need to [register](https://pypi.org/account/register/) for a PyPI account before uploading packages to the package index. Similarly for [Test PyPI](https://test.pypi.org/account/register/) as well. diff --git a/override_version.py b/override_version.py deleted file mode 100644 index 6a9d97c5a..000000000 --- a/override_version.py +++ /dev/null @@ -1,14 +0,0 @@ -import os - -import toml - -data = toml.load("pyproject.toml") -# get release version -RELEASE_VERSION = os.getenv("RELEASE_VERSION") -# Modify field -data["tool"]["poetry"]["version"] = RELEASE_VERSION -print("the version number of this release is: ", RELEASE_VERSION) -# override and save changes -f = open("pyproject.toml", "w") -toml.dump(data, f) -f.close()