Skip to content
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

feat: setup maintainable project #2

Merged
merged 18 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 125
215 changes: 215 additions & 0 deletions .github/maintainers_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
# 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:

```zsh
brew update
brew install pyenv
```

Install necessary Python runtimes for development/testing. You can rely on GitHub Actions for testing with various major versions.

```zsh
pyenv install -l | grep -v "-e[conda|stackless|pypy]"

pyenv install 3.8.5 # select the latest patch version
pyenv local 3.8.5

pyenv versions
system
3.6.10
3.7.7
* 3.8.5 (set by /path-to-python-slack-hooks/.python-version)

pyenv rehash
```

Then, you can create a new Virtual Environment this way:

```zsh
python -m venv env_3.8.5
source env_3.8.5/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.

```zsh
./scripts/install_and_run_tests.sh
```

To simply install all the development dependencies for this project.

```zsh
./scripts/install.sh
```

Once you installed all the required dependencies, you can use the following.

```zsh
./scripts/run_tests.sh
./scripts/run_tests.sh tests/scenario_test/test_get_hooks.py
```

To format this project

```zsh
./scripts/format.sh
```

To lint this project

```zsh
./scripts/lint.sh
```

This project uses [pytype](https://google.github.io/pytype/) to check and infers types for your Python code.

```zsh
./scripts/run_pytype.sh
```

#### Develop Locally

If you want to test the package locally you can.

1. Build the package locally
- Run

```zsh
scripts/build_pypi_package.sh
```

- This will create a `.whl` file in the `./dist` folder
2. Use the built package
- Example `/dist/slack_cli_hooks-1.2.3-py2.py3-none-any.whl` was created
- From anywhere on your machine you can install this package to a project with

```zsh
pip install <project path>/dist/slack_cli_hooks-1.2.3-py2.py3-none-any.whl
```

### Releasing

#### 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

```zsh
./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 commit -m 'version 1.3.0.dev0'`
- `git push future-release`
- Create a git tag for the release. For example `git tag v1.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

#### 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 v1.2.3-release`
- `git commit -m 'version 1.2.3'`
- `git push {your-fork} v1.2.3-release`
- Merge in release PR after getting an approval from at least one maintainer.
- Create a git tag for the release. For example `git tag v1.2.3`.
- 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_pypi_org.sh`
- Create a GitHub release - <https://github.com/slackapi/python-slack-hooks/releases>

```markdown
## New Features

### Awesome Feature 1

Description here.

### Awesome Feature 2

Description here.

## Changes

* #123 Make it better - thanks @SlackHQ
* #123 Fix something wrong - thanks @seratch
```

3. (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

## Workflow

### Versioning and Tags

This project uses semantic versioning, 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.

### Issue Management

Labels are used to run issues through an organized workflow. Here are the basic definitions:

- `bug`: A confirmed bug report. A bug is considered confirmed when reproduction steps have been
documented and the issue has been reproduced.
- `enhancement`: A feature request for something this package might not already do.
- `docs`: An issue that is purely about documentation work.
- `tests`: An issue that is purely about testing work.
- `discussion`: An issue that is purely meant to hold a discussion. Typically the maintainers are looking for feedback in this issues.
- `question`: An issue that is like a support request because the user's usage was not correct.

**Triage** is the process of taking new issues that aren't yet "seen" and marking them with a basic level of information
with labels. An issue should have **one** of the following labels applied: `bug`, `enhancement`, `question`,
`needs feedback`, `docs`, `tests`, or `discussion`.

Issues are closed when a resolution has been reached. If for any reason a closed issue seems relevant once again,
reopening is great and better than creating a duplicate issue.

## Everything else

When in doubt, find the other maintainers and ask.
34 changes: 34 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Run codecov

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip
pip install .
pip install -r requirements/testing.txt
- name: Run all tests for codecov
run: |
pytest --cov=./slack_cli_hooks/ --cov-report=xml
# TODO uncomment when repo public
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# with:
# fail_ci_if_error: true
# verbose: true
23 changes: 23 additions & 0 deletions .github/workflows/flake8.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run flake8 validation

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 2
strategy:
matrix:
python-version: ["3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run flake8 verification
run: |
./scripts/lint.sh
23 changes: 23 additions & 0 deletions .github/workflows/pytype.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run pytype validation

on:
push:
branches: [main]
pull_request:

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 2
strategy:
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Run pytype verification
run: |
./scripts/run_pytype.sh
29 changes: 29 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Run all the unit tests

on:
push:
branches: [main]
pull_request:

jobs:
build:
# Avoiding -latest due to https://github.com/actions/setup-python/issues/162
runs-on: ubuntu-20.04
timeout-minutes: 5
strategy:
matrix:
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip
pip install .
pip install -r requirements/testing.txt
- name: Run tests
run: |
pytest
33 changes: 33 additions & 0 deletions .github/workflows/triage-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow uses the following github action to automate
# management of stale issues and prs in this repo:
# https://github.com/marketplace/actions/close-stale-issues

name: Close stale issues and PRs

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 1"

permissions:
issues: write
pull-requests: write

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
with:
days-before-issue-stale: 30
days-before-issue-close: 10
days-before-pr-stale: -1
days-before-pr-close: -1
stale-issue-label: auto-triage-stale
stale-issue-message: 👋 It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.
close-issue-message: As this issue has been inactive for more than one month, we will be closing it. Thank you to all the participants! If you would like to raise a related issue, please create a new issue which includes your specific details and references this issue number.
exempt-issue-labels: auto-triage-skip
exempt-all-milestones: true
remove-stale-when-updated: true
enable-statistics: true
operations-per-run: 60
Loading