diff --git a/.git-hooks/post-commit b/.git-hooks/post-commit new file mode 100755 index 0000000..043e9ca --- /dev/null +++ b/.git-hooks/post-commit @@ -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" \ No newline at end of file diff --git a/.github/workflows/release_and_publish.yml b/.github/workflows/release_and_publish.yml new file mode 100644 index 0000000..7d6375e --- /dev/null +++ b/.github/workflows/release_and_publish.yml @@ -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/poetry-publish@v1.17 + with: + pypi_token: ${{ secrets.PYPI_TOKEN }} + ignore_dev_requirements: "yes" \ No newline at end of file diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f23ef0d..9c5138a 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -66,14 +66,19 @@ Ready to contribute? Here's how to set up `pipreqs` for local development. 3. Pipreqs is developed using Poetry. Refer to the `documentation `_ 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 @@ -81,13 +86,13 @@ Ready to contribute? Here's how to set up `pipreqs` for local development. 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 ----------------------- diff --git a/pyproject.toml b/pyproject.toml index 7dd9b6a..609de27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" \ No newline at end of file