Repository navigation
ci: add pypi release workflow #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4215713
build: move to pyproject.toml and drop python 3.6
WilliamBergamin 674f1e2
build: replace black and flake8 with ruff
WilliamBergamin 3d75268
style: format with ruff
WilliamBergamin ce9e172
docs: fix docstrings flagged by ruff pydocstyle
WilliamBergamin 39dce1b
build: add mypy type checking
WilliamBergamin d7343e1
ci: add pypi release workflow
WilliamBergamin 4dad4a3
build: use pep 639 license metadata and drop pypy
WilliamBergamin f7f10d9
Merge branch 'pyproject' into ruff
WilliamBergamin 6b42087
Merge branch 'ruff' into mypy
WilliamBergamin e7cac94
Merge branch 'mypy' into release
WilliamBergamin 3df411e
Merge remote-tracking branch 'origin/main' into release
WilliamBergamin c4824aa
build: tidy config left over from the pyproject, ruff, and mypy moves
WilliamBergamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| # Maintainers Guide | ||
|
|
||
| This document describes tools, tasks and workflow that one needs to be familiar with in order to effectively maintain | ||
| this project. If you use this package within your own software as is but don't plan on modifying it, this guide is | ||
| **not** for you. | ||
|
|
||
| ## Tools | ||
|
|
||
| ### Python (and friends) | ||
|
|
||
| We recommend using [pyenv](https://github.com/pyenv/pyenv) for Python runtime management. If you use macOS, follow the following steps: | ||
|
|
||
| ```sh | ||
| brew update | ||
| brew install pyenv | ||
| ``` | ||
|
|
||
| Install necessary Python runtimes for development/testing. You can rely on GitHub Actions for testing with various major versions. | ||
|
|
||
| ```sh | ||
| pyenv install -l | grep -v "-e[conda|stackless|pypy]" | ||
|
|
||
| pyenv install 3.9.18 # select the latest patch version | ||
| pyenv local 3.9.18 | ||
|
|
||
| pyenv versions | ||
| system | ||
| 3.6.10 | ||
| 3.7.7 | ||
| * 3.9.18 (set by /path-to-python-slack-discovery-sdk/.python-version) | ||
|
|
||
| pyenv rehash | ||
| ``` | ||
|
|
||
| Then, you can create a new Virtual Environment this way: | ||
|
|
||
| ```sh | ||
| python -m venv env_3.9.18 | ||
| source env_3.9.18/bin/activate | ||
| ``` | ||
|
|
||
| ## Tasks | ||
|
|
||
| ### Testing | ||
|
|
||
| #### Run All the Unit Tests | ||
|
|
||
| If you make some changes to this project, please write corresponding unit tests as much as possible. You can easily run all the tests by running the following scripts. | ||
|
|
||
| If this is your first time to run tests, although it may take a bit longer, running the following script is the easiest. | ||
|
|
||
| ```sh | ||
| ./scripts/install_and_run_tests.sh | ||
| ``` | ||
|
|
||
| To simply install all the development dependencies for this project. | ||
|
|
||
| ```sh | ||
| ./scripts/install.sh | ||
| ``` | ||
|
|
||
| Once you installed all the required dependencies, you can use the following. | ||
|
|
||
| ```sh | ||
| ./scripts/run_tests.sh | ||
| ./scripts/run_tests.sh tests/test_rate_limit_support.py | ||
| ``` | ||
|
|
||
| Tests marked `live` call the real Discovery API and are skipped unless `SLACK_DISCOVERY_SDK_TEST_ENTERPRISE_TOKEN` is set. See [Running tests](../README.md#running-tests) for the app and tokens they need. | ||
|
|
||
| To format this project | ||
|
|
||
| ```sh | ||
| ./scripts/format.sh | ||
| ``` | ||
|
|
||
| To lint this project | ||
|
|
||
| ```sh | ||
| ./scripts/lint.sh | ||
| ``` | ||
|
|
||
| This project uses [mypy](https://mypy.readthedocs.io/en/stable/index.html) to check and infers types for your Python code. | ||
|
|
||
| ```sh | ||
| ./scripts/run_mypy.sh | ||
| ``` | ||
|
|
||
| To clean your virtual environment (useful when testing scripts in isolation): | ||
|
|
||
| ```sh | ||
| ./scripts/uninstall_all.sh | ||
| ``` | ||
|
|
||
| > **Note**: Several scripts support a `--no-install` flag to prevent redundant dependency installation when scripts call other scripts internally. | ||
|
|
||
| #### Develop Locally | ||
|
|
||
| If you want to test the package locally you can. | ||
|
|
||
| 1. Build the package locally | ||
|
|
||
| - Run | ||
|
|
||
| ```sh | ||
| scripts/build_pypi_package.sh | ||
| ``` | ||
|
|
||
| - This will create a `.whl` file in the `./dist` folder | ||
|
|
||
| 2. Use the built package | ||
|
|
||
| - Example `/dist/slack_discovery_sdk-1.2.3-py3-none-any.whl` was created | ||
| - From anywhere on your machine you can install this package to a project with | ||
|
|
||
| ```sh | ||
| pip install <project path>/dist/slack_discovery_sdk-1.2.3-py3-none-any.whl | ||
| ``` | ||
|
|
||
| ### Releasing | ||
|
|
||
| #### test.pypi.org deployment | ||
|
|
||
| [TestPyPI](https://test.pypi.org/) is a separate instance of the Python Package | ||
| Index that allows you to try distribution tools and processes without affecting | ||
| the real index. This is particularly useful when making changes related to the | ||
| package configuration itself, for example, modifications to the `pyproject.toml` file. | ||
|
|
||
| You can deploy this project to TestPyPI using GitHub Actions. | ||
|
|
||
| To deploy using GitHub Actions: | ||
|
|
||
| 1. Push your changes to a branch or tag | ||
| 2. Navigate to <https://github.com/slackapi/python-slack-discovery-sdk/actions/workflows/pypi-release.yml> | ||
| 3. Click on "Run workflow" | ||
| 4. Select your branch or tag from the dropdown | ||
| 5. Click "Run workflow" to build and deploy your branch to TestPyPI | ||
|
|
||
| Alternatively, you can deploy from your local machine with: | ||
|
|
||
| ```sh | ||
| ./scripts/deploy_to_test_pypi.sh | ||
| ``` | ||
|
|
||
| #### Development Deployment | ||
|
|
||
| Deploying a new version of this library to PyPI is triggered by publishing a GitHub Release. | ||
| Before creating a new release, ensure that everything on a stable branch has | ||
| landed, then [run the tests](#run-all-the-unit-tests). | ||
|
|
||
| 1. Create the commit for the release | ||
| 1. Use the latest supported Python version. Using a [virtual environment](#python-and-friends) is recommended. | ||
| 2. In `slack_discovery_sdk/version.py` bump the version number in adherence to [Semantic Versioning](http://semver.org/) and [Developmental Release](https://peps.python.org/pep-0440/#developmental-releases). | ||
| - Example: if the current version is `1.2.3`, a proper development bump would be `1.2.4.dev0` | ||
| - `.dev` will indicate to pip that this is a [Development Release](https://peps.python.org/pep-0440/#developmental-releases) | ||
| - Note that the `dev` version can be bumped in development releases: `1.2.4.dev0` -> `1.2.4.dev1` | ||
| 3. Commit with a message including the new version number. For example `1.2.4.dev0` & push the commit to a branch where the development release will live (create it if it does not exist) | ||
| 1. `git checkout -b future-release` | ||
| 2. `git add --all` (review files with `git status` before committing) | ||
| 3. `git commit -m 'chore(release): version 1.2.4.dev0'` | ||
| 4. `git push -u origin future-release` | ||
| 2. Create a new GitHub Release | ||
| 1. Navigate to the [Releases page](https://github.com/slackapi/python-slack-discovery-sdk/releases). | ||
| 2. Click the "Draft a new release" button. | ||
| 3. Set the "Target" to the feature branch with the development changes. | ||
| 4. Click "Tag: Select tag" | ||
| 5. Input a new tag name manually. The tag name must match the version in `slack_discovery_sdk/version.py` prefixed with "v" (e.g., if version is `1.2.4.dev0`, enter `v1.2.4.dev0`) | ||
| 6. Click the "Create a new tag" button. This won't create your tag immediately. | ||
| 7. Click the "Generate release notes" button. | ||
| 8. The release name should match the tag name! | ||
| 9. Edit the resulting notes to ensure they have decent messaging that is understandable by non-contributors, but each commit should still have its own line. | ||
| 10. Set this release as a pre-release. | ||
| 11. Publish the release by clicking the "Publish release" button! | ||
| 3. Navigate to the [release workflow run](https://github.com/slackapi/python-slack-discovery-sdk/actions/workflows/pypi-release.yml). You will need to approve the deployment! | ||
| 4. After a few minutes, the corresponding version will be available on <https://pypi.org/project/slack-discovery-sdk>. | ||
| 5. (Slack Internal) Communicate the release internally | ||
|
|
||
| #### Production Deployment | ||
|
|
||
| Deploying a new version of this library to PyPI is triggered by publishing a GitHub Release. | ||
| Before creating a new release, ensure that everything on the `main` branch since | ||
| the last tag is in a releasable state! At a minimum, [run the tests](#run-all-the-unit-tests). | ||
|
|
||
| 1. Create the commit for the release | ||
| 1. Use the latest supported Python version. Using a [virtual environment](#python-and-friends) is recommended. | ||
| 2. In `slack_discovery_sdk/version.py` bump the version number in adherence to [Semantic Versioning](http://semver.org/) and the [Versioning](#versioning-and-tags) section. | ||
| 3. Commit with a message including the new version number. For example `1.2.3` & push the commit to a branch and create a PR to sanity check. | ||
| 1. `git checkout -b 1.2.3-release` | ||
| 2. `git add --all` (review files with `git status` before committing) | ||
| 3. `git commit -m 'chore(release): version 1.2.3'` | ||
| 4. `git push -u origin 1.2.3-release` | ||
| 4. Add relevant labels to the PR and add the PR to a GitHub Milestone. | ||
| 5. Merge in release PR after getting an approval from at least one maintainer. | ||
| 2. Create a new GitHub Release | ||
| 1. Navigate to the [Releases page](https://github.com/slackapi/python-slack-discovery-sdk/releases). | ||
| 2. Click the "Draft a new release" button. | ||
| 3. Set the "Target" to the `main` branch. | ||
| 4. Click "Tag: Select tag" | ||
| 5. Input a new tag name manually. The tag name must match the version in `slack_discovery_sdk/version.py` prefixed with "v" (e.g., if version is `1.2.3`, enter `v1.2.3`) | ||
| 6. Click the "Create a new tag" button. This won't create your tag immediately. | ||
| 7. Click the "Generate release notes" button. | ||
| 8. The release name should match the tag name! | ||
| 9. Edit the resulting notes to ensure they have decent messaging that is understandable by non-contributors, but each commit should still have its own line. | ||
| 10. Include a link to the current GitHub Milestone. | ||
| 11. Ensure the "latest release" checkbox is checked to mark this as the latest stable release. | ||
| 12. Publish the release by clicking the "Publish release" button! | ||
| 3. Navigate to the [release workflow run](https://github.com/slackapi/python-slack-discovery-sdk/actions/workflows/pypi-release.yml). You will need to approve the deployment! | ||
| 4. After a few minutes, the corresponding version will be available on <https://pypi.org/project/slack-discovery-sdk>. | ||
| 5. Close the current GitHub Milestone and create one for the next patch version. | ||
| 6. (Slack Internal) Communicate the release internally | ||
| - Include a link to the GitHub release | ||
| 7. (Slack Internal) Tweet by @SlackAPI | ||
| - Not necessary for patch updates, might be needed for minor updates, | ||
| definitely needed for major updates. Include a link to the GitHub release | ||
|
|
||
| ## Workflow | ||
|
|
||
| ### Versioning and Tags | ||
|
|
||
| This project uses [Semantic Versioning](http://semver.org/), expressed through the numbering scheme of | ||
| [PEP-0440](https://www.python.org/dev/peps/pep-0440/). | ||
|
|
||
| ### Branches | ||
|
|
||
| `main` is where active development occurs. Long running named feature branches are occasionally created for | ||
| collaboration on a feature that has a large scope (because everyone cannot push commits to another person's open Pull | ||
| Request). At some point in the future after a major version increment, there may be maintenance branches for older major | ||
| versions. | ||
|
|
||
| ## Everything else | ||
|
|
||
| When in doubt, find the other maintainers and ask. |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuring-automatically-generated-release-notes | ||
| changelog: | ||
| categories: | ||
| - title: 🚀 Enhancements | ||
| labels: | ||
| - enhancement | ||
| - title: 🐛 Bug Fixes | ||
| labels: | ||
| - bug | ||
| - title: 📚 Documentation | ||
| labels: | ||
| - docs | ||
| - title: 🤖 Build | ||
| labels: | ||
| - build | ||
| - title: 🧪 Testing/Code Health | ||
| labels: | ||
| - code health | ||
| - title: 🔒 Security | ||
| labels: | ||
| - security | ||
| - title: 📦 Other changes | ||
| labels: | ||
| - "*" |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| name: Upload A Release to pypi.org or test.pypi.org | ||
|
|
||
| on: | ||
| release: | ||
| types: | ||
| - published | ||
| workflow_dispatch: | ||
| inputs: | ||
| dry_run: | ||
| description: "Dry run (build only, do not publish)" | ||
| required: false | ||
| type: boolean | ||
|
|
||
| jobs: | ||
| release-build: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
| with: | ||
| ref: ${{ github.event.release.tag_name || github.ref }} | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Python | ||
| uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0 | ||
| with: | ||
| python-version: "3.x" | ||
|
|
||
| - name: Build release distributions | ||
| run: | | ||
| scripts/build_pypi_package.sh | ||
|
|
||
| - name: Persist dist folder | ||
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 | ||
| with: | ||
| name: release-dist | ||
| path: dist/ | ||
|
|
||
| test-pypi-publish: | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - release-build | ||
| # Run this job for workflow_dispatch events when dry_run input is not 'true' | ||
| # Note: The comparison is against a string value 'true' since GitHub Actions inputs are strings | ||
| if: github.event_name == 'workflow_dispatch' && github.event.inputs.dry_run != 'true' | ||
| environment: | ||
| name: testpypi | ||
| permissions: | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Retrieve dist folder | ||
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | ||
| with: | ||
| name: release-dist | ||
| path: dist/ | ||
|
|
||
| - name: Publish release distributions to test.pypi.org | ||
| # Using OIDC for PyPI publishing (no API tokens needed) | ||
| # See: https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-pypi | ||
| uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 | ||
| with: | ||
| repository-url: https://test.pypi.org/legacy/ | ||
|
|
||
| pypi-publish: | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - release-build | ||
| if: github.event_name == 'release' | ||
| environment: | ||
| name: pypi | ||
| permissions: | ||
| id-token: write | ||
|
|
||
| steps: | ||
| - name: Retrieve dist folder | ||
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 | ||
| with: | ||
| name: release-dist | ||
| path: dist/ | ||
|
|
||
| - name: Publish release distributions to pypi.org | ||
| # Using OIDC for PyPI publishing (no API tokens needed) | ||
| # See: https://docs.github.com/en/actions/how-tos/secure-your-work/security-harden-deployments/oidc-in-pypi | ||
| uses: pypa/gh-action-pypi-publish@7245906fb61fa33a13554f9d5fb856fe61758086 # v1.14.3 | ||
|
|
||
| notify: | ||
| if: github.event_name == 'release' && !github.event.release.prerelease && github.repository == 'slackapi/python-slack-discovery-sdk' | ||
| runs-on: ubuntu-latest | ||
| needs: | ||
| - pypi-publish | ||
| permissions: | ||
| contents: read | ||
|
|
||
| steps: | ||
| - name: Notify Slack | ||
| uses: slackapi/slack-github-action@dcb1066f776dd043e64d0e8ba94ca15cc7e1875d # v4.0.0 | ||
| with: | ||
| errors: true | ||
| webhook: ${{ secrets.SLACK_RELEASE_ANNOUNCEMENTS_WEBHOOK_URL }} | ||
| webhook-type: webhook-trigger | ||
| payload: | | ||
| action_url: "${{ github.event.release.html_url }}" | ||
| message: "python-slack-discovery-sdk ${{ github.event.release.tag_name }}" | ||
| repository: "${{ github.repository }}" | ||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,6 @@ tmp.txt | |
| .DS_Store | ||
| logs/ | ||
|
|
||
| .pytype/ | ||
| *.db | ||
| .env* | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking): The maintainers guide says the tag and
version.pymust match, but nothing checks it. A step comparing${GITHUB_REF_NAME#v}to__version__would stop a mistyped tag from publishing, since PyPI versions can't be reused.