|
1 | 1 | name: Publish to PyPI |
2 | 2 | on: |
3 | | - push: |
4 | | - tags: |
5 | | - - 'v[1-9][0-9].[0-9]+.[0-9]+' |
6 | | - branches: [main] |
| 3 | + release: |
| 4 | + types: [published] |
7 | 5 |
|
8 | 6 | jobs: |
9 | | - pypi_release: |
| 7 | + build: |
10 | 8 | runs-on: ubuntu-22.04 |
11 | 9 | env: |
12 | | - POETRY_VERSION: 1.3.0 |
13 | 10 | 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 }} |
15 | 14 | 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 |
24 | 17 | with: |
25 | 18 | 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=" |
26 | 32 |
|
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 |
36 | 35 |
|
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 |
42 | 38 | |
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 |
48 | 45 |
|
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 |
60 | 52 |
|
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 |
68 | 67 |
|
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 |
89 | 73 |
|
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/' || '' }} |
93 | 78 |
|
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 |
96 | 85 | id: slack |
97 | 86 | 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 }}" |
106 | 87 | env: |
107 | 88 | 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 | + |
0 commit comments