Skip to content

Commit

Permalink
feat: automate releases (#36)
Browse files Browse the repository at this point in the history
* Automate release

* Update maintainers_guide.md

* Improve wording
  • Loading branch information
WilliamBergamin authored Apr 3, 2024
1 parent a050a47 commit d9e93af
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 61 deletions.
143 changes: 93 additions & 50 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,66 +108,109 @@ If you want to test the package locally you can.

#### test.pypi.org deployment

It is possible to deploy this project on <https://test.pypi.org/> in order to try out packaging and deploy related changes
[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 useful with changes that
relate to the package itself, example the contents of the `pyproject.toml`

The following can be used to deploy this project on <https://test.pypi.org/>.

```zsh
./scripts/deploy_to_test_pypi.sh
# Set the new version with SLACK_CLI_HOOKS_VERSION
SLACK_CLI_HOOKS_VERSION="1.2.3" ./scripts/deploy_to_test_pypi.sh
```

#### Development Deployment

1. Create a branch in which the development release will live:
- Bump the version number in adherence to [Semantic Versioning](http://semver.org/) and [Developmental Release](https://peps.python.org/pep-0440/#developmental-releases) in `slack_cli_hooks/version.py`
- Example the current version is `1.2.3` a proper development bump would be `1.3.0.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.3.0.dev0` -> `1.3.0.dev1`
- Commit with a message including the new version number. For example `1.3.0.dev0` & Push the commit to a branch where the development release will live (create it if it does not exist)
- `git checkout -b future-release`
- `git add slack_cli_hooks/version.py`
- `git commit -m 'version 1.3.0.dev0'`
- `git push future-release`
- Create a git tag for the release. For example `git tag 1.3.0.dev0`.
- Push the tag up to github with `git push origin --tags`

2. Distribute the release
- Use the latest stable Python runtime
- `python -m venv .venv`
- `scripts/deploy_to_prod_pypi.sh`
- You do not need to create a GitHub release

3. (Slack Internal) Communicate the release internally
Releases for this library are automatically generated off of git releases. 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 a new GitHub Release from the
[Releases page](https://github.com/slackapi/python-slack-hooks/releases) by
clicking the "Draft a new release" button.
2. Input a new version manually into the "Choose a tag" input. You can start off
by incrementing the version to reflect a patch. (i.e. 1.16.0 -> 1.16.1.dev0)

- Example the current version is `1.2.3` a proper development bump would be `1.3.0.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.3.0.dev0` -> `1.3.0.dev1`
- After you input the new version, click the "Create a new tag: x.x.x on
publish" button. This won't create your tag immediately.
- Auto-generate the release notes by clicking the "Auto-generate release
notes" button. This will pull in changes that will be included in your
release.
- Edit the resulting notes to ensure they have decent messaging that are
understandable by non-contributors, but each commit should still have it's
own line.
- Flip to the preview mode and review the pull request labels of the changes
included in this release (i.e. `semver:minor` `semver:patch`,
`semver:major`). Tip: Your release version should be based on the tag of
the largest change, so if this release includes a `semver:minor`, the
release version in your tag should be upgraded to reflect a minor.
- Ensure that this version adheres to [semantic versioning](http://semver.org/) and
[Developmental Release](https://peps.python.org/pep-0440/#developmental-releases).
See [Versioning](#versioning-and-tags) for correct version format. Version tags
should match the following pattern: `1.0.1` (no `v` preceding the number).

3. Set the "Target" input to the feature branch with the development changes.
4. Name the release title after the version tag. The release title is what will
be used by the pipeline to populate the value in `slack_cli_hooks/version.py`
and the Pypi package version!
5. Make any adjustments to generated release notes to make sure they are
accessible and approachable and that an end-user with little context about
this project could still understand.
6. Select "Set as a pre-release"
7. Publish the release by clicking the "Publish release" button!
8. After a few minutes, the corresponding version will be available on
<https://pypi.org/project/slack-cli-hooks/>.
9. (Slack Internal) Communicate the release internally

#### Production Deployment

1. Create the commit for the release:
- Bump the version number in adherence to [Semantic Versioning](http://semver.org/) in `slack_cli_hooks/version.py`
- 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.
- `git checkout -b 1.2.3-release`
- `git add slack_cli_hooks/version.py`
- `git commit -m 'version 1.2.3'`
- `git push {your-fork} 1.2.3-release`
- Create a release PR and get an approval from at least one maintainer.
- Merge in your release PR.

2. Distribute the release
- Use the latest stable Python runtime
- `python -m venv .venv`
- `/scripts/deploy_to_prod_pypi.sh`
- Create a GitHub release - <https://github.com/slackapi/python-slack-hooks/releases>
- Click `Draft a new release`
- Input the new version you set in [version.py](../slack_cli_hooks/version.py) manually as the `choose a tag` input (example `1.2.3`)
- After you input the new version, click the "Create a new tag: x.x.x on publish" button.
- Set the "Target" input to the "main" branch.
- Name the release title after the version tag.
- Auto-generate the release notes by clicking the "Auto-generate release notes" button.
- Make any adjustments to generated release notes to make sure they are accessible and approachable and that an end-user with little context about this project could still understand.
- Publish the release by clicking the "Publish release" button!

3. (Slack Internal) Communicate the release internally
Releases for this library are automatically generated off of git releases. 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 a new GitHub Release from the
[Releases page](https://github.com/slackapi/python-slack-hooks/releases) by
clicking the "Draft a new release" button.
2. Input a new version manually into the "Choose a tag" input. You can start off
by incrementing the version to reflect a patch. (i.e. 1.16.0 -> 1.16.1)

- After you input the new version, click the "Create a new tag: x.x.x on
publish" button. This won't create your tag immediately.
- Auto-generate the release notes by clicking the "Auto-generate release
notes" button. This will pull in changes that will be included in your
release.
- Edit the resulting notes to ensure they have decent messaging that are
understandable by non-contributors, but each commit should still have it's
own line.
- Flip to the preview mode and review the pull request labels of the changes
included in this release (i.e. `semver:minor` `semver:patch`,
`semver:major`). Tip: Your release version should be based on the tag of
the largest change, so if this release includes a `semver:minor`, the
release version in your tag should be upgraded to reflect a minor.
- Ensure that this version adheres to [semantic versioning](http://semver.org/). See
[Versioning](#versioning-and-tags) for correct version format. Version tags
should match the following pattern: `1.0.1` (no `v` preceding the number).

3. Set the "Target" input to the "main" branch.
4. Name the release title after the version tag. The release title is what will
be used by the pipeline to populate the value in `slack_cli_hooks/version.py`
and the Pypi package version!
5. Make any adjustments to generated release notes to make sure they are
accessible and approachable and that an end-user with little context about
this project could still understand.
6. Publish the release by clicking the "Publish release" button!
7. After a few minutes, the corresponding version will be available on
<https://pypi.org/project/slack-cli-hooks/>.
8. (Slack Internal) Communicate the release internally
- Include a link to the GitHub release

4. (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
9. (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

Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Upload A Release To Pypi

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
pip install twine
- name: Build package
run: |
python -m build
twine check dist/*
env:
SLACK_CLI_HOOKS_VERSION: ${{ github.event.release.name }}
- name: Publish package
run: twine upload dist/*
env:
TWINE_USERNAME: ${{ secrets.PYPI_USER }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
10 changes: 0 additions & 10 deletions scripts/deploy_to_prod_pypi.sh

This file was deleted.

5 changes: 4 additions & 1 deletion slack_cli_hooks/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
"""Check the latest version at https://pypi.org/project/slack-cli-hooks/"""
__version__ = "0.0.0.dev2"

import os

__version__ = os.environ.get("SLACK_CLI_HOOKS_VERSION", "0.0.0.dev0")

0 comments on commit d9e93af

Please sign in to comment.