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

Automate Versioning, Release, and PyPI Publishing #425

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions .git-hooks/post-commit
fredgrub marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#! /bin/bash
version=`git diff HEAD^..HEAD -- "$(git rev-parse --show-toplevel)"/pyproject.toml | grep -m 1 '^\+.*version' | sed -s 's/[^A-Z0-9\.\-]//g'`

if [[ ! $version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)(\-[A-Z]+\.[0-9]+)?$ ]]; then
echo -e "Skip tag: invalid version '$version'"
exit 1
fi

git tag -a "v$version" -m "`git log -1 --format=%s`"
echo "Created a new tag, v$version"
32 changes: 32 additions & 0 deletions .github/workflows/release_and_publish.yml
fredgrub marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Create and publish a release

on:
push:
tags:
- 'v*.*.*'

jobs:
create_release:
name: Create Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: ncipollo/release-action@v1
with:
name: Release ${{ github.ref_name }}
makeLatest: true

publish_to_pypi:
name: Publish to PyPI
needs: create_release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build and publish to PyPI
uses: JRubics/[email protected]
with:
pypi_token: ${{ secrets.PYPI_TOKEN }}
ignore_dev_requirements: "yes"
13 changes: 9 additions & 4 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,33 @@ Ready to contribute? Here's how to set up `pipreqs` for local development.
3. Pipreqs is developed using Poetry. Refer to the `documentation <https://python-poetry.org/docs/>`_ to install Poetry in your local environment. Next, you should install pipreqs's dependencies::

$ poetry install --with dev
$ poetry self add poetry-bumpversion

4. Create a branch for local development::
4. Configure `./git-hooks/` directory so that it becomes visible to git hooks (this hook depends on `bash`, `sed` and `grep` - tools usually included in any linux distribution)::

$ git config core.hooksPath .git-hooks

5. Create a branch for local development::

$ git checkout -b name-of-your-bugfix-or-feature

Now you can make your changes locally.

5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::
6. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox::

$ poetry run flake8 pipreqs tests
$ poetry run python -m unittest discover
$ poetry run tox

To test all versions of python using tox you need to have them installed and for this two options are recommended: `pyenv` or `asdf`.

6. Commit your changes and push your branch to GitHub::
7. Commit your changes and push your branch to GitHub::

$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature

7. Submit a pull request through the GitHub website.
8. Submit a pull request through the GitHub website.

Pull Request Guidelines
-----------------------
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ tox = "^4.11.3"
coverage = "^7.3.2"
sphinx = { version = "^7.2.6", python = ">=3.9" }

[tool.poetry_bumpversion.file."pipreqs/__init__.py"]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
Loading