Skip to content

Commit 951cd74

Browse files
authored
[SCHEMATIC-210] Updates publish.yml for Test PyPi deployments (#1559) (#1560)
* [SCHEMATIC-210] Updates `publish.yml` for Test PyPi deployments (#1559) * updates pypi publishing workflow * specify python version explicitly * list dist/ * throw error if no files * Update publish.yml * Update publish.yml * test * undo test * test build * test full build * debug prerelease * full debug print * reverse logic * use boolean true * try publish * adds test url * override_version * updates version * manually edit version * add back slack and revert version * lock ubuntu version * addresses lingling comments
1 parent 318f244 commit 951cd74

File tree

3 files changed

+78
-114
lines changed

3 files changed

+78
-114
lines changed

.github/workflows/publish.yml

Lines changed: 71 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,93 @@
11
name: Publish to PyPI
22
on:
3-
push:
4-
tags:
5-
- 'v[1-9][0-9].[0-9]+.[0-9]+'
6-
branches: [main]
3+
release:
4+
types: [published]
75

86
jobs:
9-
pypi_release:
7+
build:
108
runs-on: ubuntu-22.04
119
env:
12-
POETRY_VERSION: 1.3.0
1310
PYTHON_VERSION: "3.10"
14-
if: github.event_name == 'push' && contains(github.ref, 'refs/tags')
11+
outputs:
12+
sdist-package-name: ${{ steps.build-package.outputs.sdist-package-name }}
13+
bdist-package-name: ${{ steps.build-package.outputs.bdist-package-name }}
1514
steps:
16-
#----------------------------------------------
17-
# check-out repo and set-up python
18-
#----------------------------------------------
19-
- name: Check out repository
20-
uses: actions/checkout@v4
21-
22-
- name: Set up Python ${{ env.PYTHON_VERSION }}
23-
uses: actions/setup-python@v5
15+
- uses: actions/checkout@v4
16+
- uses: actions/setup-python@v5
2417
with:
2518
python-version: ${{ env.PYTHON_VERSION }}
19+
- id: build-package
20+
run: |
21+
python3 -m pip install --upgrade pip
22+
python3 -m pip install setuptools
23+
python3 -m pip install wheel
24+
python3 -m pip install build
25+
python3 -m pip install .
26+
python3 -m build
27+
28+
VERSION=${{ github.event.release.tag_name }}
29+
SDIST_PACKAGE_NAME="schematicpy-${VERSION}.tar.gz"
30+
BDIST_PACKAGE_NAME="schematicpy-${VERSION}-py3-none-any.whl"
31+
RELEASE_URL_PREFIX="https://uploads.github.com/repos/${{ github.event.repository.full_name }}/releases/${{ github.event.release.id }}/assets?name="
2632
27-
#----------------------------------------------
28-
# install & configure poetry
29-
#----------------------------------------------
30-
- name: Install Poetry
31-
run: |
32-
curl -sSL https://install.python-poetry.org \
33-
| python3 - --version ${{ env.POETRY_VERSION }};
34-
poetry config virtualenvs.create true;
35-
poetry config virtualenvs.in-project true;
33+
echo "sdist-package-name=$SDIST_PACKAGE_NAME" >> $GITHUB_OUTPUT
34+
echo "bdist-package-name=$BDIST_PACKAGE_NAME" >> $GITHUB_OUTPUT
3635
37-
#----------------------------------------------
38-
# install dependencies and root project
39-
#----------------------------------------------
40-
- name: Install dependencies and root project
41-
run: poetry install --no-interaction --all-extras
36+
echo "sdist-release-url=${RELEASE_URL_PREFIX}${SDIST_PACKAGE_NAME}" >> $GITHUB_OUTPUT
37+
echo "bdist-release-url=${RELEASE_URL_PREFIX}${BDIST_PACKAGE_NAME}" >> $GITHUB_OUTPUT
4238
43-
#----------------------------------------------
44-
# get current pushed tag
45-
#----------------------------------------------
46-
- name: Show GitHub ref
47-
run: echo "$GITHUB_REF"
39+
- name: upload-sdist-artifact
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: ${{ steps.build-package.outputs.sdist-package-name }}
43+
path: dist/
44+
if-no-files-found: error
4845

49-
- name: Get current pushed tag
50-
run: |
51-
echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
52-
echo "$RELEASE_VERSION"
53-
54-
#----------------------------------------------
55-
# override version tag
56-
#----------------------------------------------
57-
- name: Override version tag
58-
run: poetry run python3 override_version.py
59-
shell: sh
46+
- name: upload-bdist-artifact
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: ${{ steps.build-package.outputs.bdist-package-name }}
50+
path: dist/
51+
if-no-files-found: error
6052

61-
#----------------------------------------------
62-
# publish to testpypi
63-
#----------------------------------------------
64-
# - run: poetry config repositories.testpypi https://test.pypi.org/legacy/
65-
# - run: poetry config pypi-token.testpypi ${{ secrets.TWINE_TEST_TOKEN }}
66-
# - name: Publish package to test Pypi
67-
# run: poetry publish -vvvv --build -r testpypi
53+
publish:
54+
needs: build
55+
runs-on: ubuntu-latest
56+
environment:
57+
name: ${{ github.event.release.prerelease == true && 'testpypi' || 'pypi' }}
58+
url: ${{ github.event.release.prerelease == true && 'https://test.pypi.org/p/schematicpy' || 'https://pypi.org/p/schematicpy' }}
59+
permissions:
60+
id-token: write
61+
steps:
62+
- name: download-sdist
63+
uses: actions/download-artifact@v4
64+
with:
65+
name: ${{ needs.build.outputs.sdist-package-name }}
66+
path: dist
6867

69-
#----------------------------------------------
70-
# check tag
71-
#----------------------------------------------
72-
- name: Check Tag
73-
id: check-tag
74-
run: |
75-
if [[ ${{ github.event.ref }} =~ ^refs/tags/v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
76-
echo ::set-output name=match::true
77-
fi
78-
#----------------------------------------------
79-
# publish to pypi
80-
#----------------------------------------------
81-
- name: Publish package to Pypi
82-
id: publish-to-pypi
83-
if: steps.check-tag.outputs.match == 'true'
84-
env:
85-
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
86-
PYPI_USERNAME: __token__
87-
run: |
88-
poetry publish --build --username $PYPI_USERNAME --password $PYPI_TOKEN
68+
- name: download-bdist
69+
uses: actions/download-artifact@v4
70+
with:
71+
name: ${{ needs.build.outputs.bdist-package-name }}
72+
path: dist
8973

90-
#----------------------------------------------
91-
# post a message to slack
92-
#----------------------------------------------
74+
- name: deploy-to-pypi
75+
uses: pypa/gh-action-pypi-publish@release/v1
76+
with:
77+
repository-url: ${{ github.event.release.prerelease == true && 'https://test.pypi.org/legacy/' || '' }}
9378

94-
- name: Post to a Slack channel
95-
if: steps.publish-to-pypi.outcome == 'success'
79+
slack-notification:
80+
needs: publish
81+
if: ${{ github.event.release.prerelease != true }}
82+
runs-on: ubuntu-latest
83+
steps:
84+
- name: post-slack-notification
9685
id: slack
9786
uses: slackapi/slack-github-action@v1.23.0
98-
with:
99-
# Slack channel id, channel name, or user id to post message.
100-
# See also: https://api.slack.com/methods/chat.postMessage#channels
101-
# You can pass in multiple channels to post to by providing a comma-delimited list of channel IDs.
102-
# ibc-fair-data channel and data-curator-schematic channel
103-
channel-id: 'C050YD75QRL,C01ANC02U59'
104-
# For posting a simple plain text message
105-
slack-message: "Schematic has just been released. Check out new version: ${{ github.ref_name }}"
10687
env:
10788
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
89+
with:
90+
# Post to the `fair-data-tools` slack channel
91+
channel-id: 'C01ANC02U59'
92+
slack-message: "A new version of Schematic has been released. Check out the new version: ${{ github.ref_name }}"
93+

CONTRIBUTION.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,35 +80,26 @@ Be consistent and follow existing code conventions and spirit.
8080

8181
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.
8282

83-
- 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.
84-
- 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.
83+
### Create a GitHub tag
8584

86-
### Release to Test PyPI _(optional)_
85+
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.
8786

88-
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.
87+
### Release to Test PyPI
8988

90-
```
91-
poetry build # build the package
92-
poetry config repositories.testpypi https://test.pypi.org/legacy/ # add Test PyPI as an alternate package repository
93-
poetry publish -r testpypi # publish the package to Test PyPI
94-
```
95-
96-
Installing:
89+
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.
9790

9891
```
99-
pip install --index-url https://test.pypi.org/simple/
92+
pip install -i https://test.pypi.org/simple/ schematicpy
10093
```
10194

10295
### Release to PyPI _(mandatory)_
10396

104-
If the package looks great on Test PyPI and works well, the next step is to publish the package to PyPI:
97+
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:
10598

10699
```
107-
poetry publish # publish the package to PyPI
100+
pip install schematicpy
108101
```
109102

110-
> 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.
111-
112103
## Testing
113104

114105
* All new code must include tests.

override_version.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)