diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..d2d45d1 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,56 @@ +name: Upload Python Package + +on: + release: + types: [created] + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Run semver-diff + id: semver-diff + uses: tj-actions/semver-diff@v1.2.0 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.6.x' + + - name: Upgrade pip + run: pip install -U pip + + - name: Install dependencies + run: make install-deploy + + - name: Setup git + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + + - name: bumpversion + run: | + make increase-version PART="${{ steps.semver-diff.outputs.release_type }}" + + - name: Build and publish + run: make release + env: + TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} + TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} + + - name: Generate CHANGELOG + uses: tj-actions/github-changelog-generator@v1.8 + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v3 + with: + base: "main" + title: "Upgraded ${{ steps.semver-diff.outputs.old_version }} → ${{ steps.semver-diff.outputs.new_version }}" + branch: "chore/upgrade-${{ steps.semver-diff.outputs.old_version }}-to-${{ steps.semver-diff.outputs.new_version }}" + commit-message: "Upgraded from ${{ steps.semver-diff.outputs.old_version }} → ${{ steps.semver-diff.outputs.new_version }}" + body: "View [CHANGES](https://github.com/${{ github.repository }}/compare/${{ steps.semver-diff.outputs.old_version }}...${{ steps.semver-diff.outputs.new_version }})" + token: ${{ secrets.PAT_TOKEN }} diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml deleted file mode 100644 index 1a03a7b..0000000 --- a/.github/workflows/python-publish.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This workflow will upload a Python Package using Twine when a release is created -# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries - -name: Upload Python Package - -on: - release: - types: [created] - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install setuptools wheel twine - - name: Build and publish - env: - TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} - TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} - run: | - python setup.py sdist bdist_wheel - twine upload dist/* diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2904151 --- /dev/null +++ b/Makefile @@ -0,0 +1,59 @@ +# Self-Documented Makefile see https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html + +.DEFAULT_GOAL := help +PART := minor + +# Put it first so that "make" without argument is like "make help". +help: + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-32s-\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +guard-%: ## Checks that env var is set else exits with non 0 mainly used in CI; + @if [ -z '${${*}}' ]; then echo 'Environment variable $* not set' && exit 1; fi + +# -------------------------------------------------------- +# ------- Python package (pip) management commands ------- +# -------------------------------------------------------- + +clean: clean-build clean-pyc ## remove all build and Python artifacts + +clean-build: ## remove build artifacts + @rm -fr build/ + @rm -fr dist/ + @rm -fr .eggs/ + @find . -name '*.egg-info' -exec rm -fr {} + + @find . -name '*.egg' -exec rm -f {} + + +clean-pyc: ## remove Python file artifacts + @find . -name '*.pyc' -exec rm -f {} + + @find . -name '*.pyo' -exec rm -f {} + + @find . -name '*~' -exec rm -f {} + + @find . -name '__pycache__' -exec rm -fr {} + || true + +lint: ## check style with flake8 + @flake8 github_deploy + +release: dist ## package and upload a release + @twine upload dist/* + +dist: clean install-deploy ## builds source and wheel package + @pip install twine==3.4.1 + @python setup.py sdist bdist_wheel + +increase-version: guard-PART ## Increase project version + @bump2version $(PART) + @git switch -c main + +install-wheel: clean ## Install wheel + @echo "Installing wheel..." + @pip install wheel + +install: install-wheel ## install the package to the active Python's site-packages + @pip install . + +install-deploy: install-wheel + @pip install -e .'[deploy]' + +migrations: + @python manage.py makemigrations + +.PHONY: clean clean-build clean-pyc dist increase-version install-wheel install install-deploy increase-version lint release migrations diff --git a/setup.py b/setup.py index fd25ff8..95b6c50 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,15 @@ else: LONG_DESCRIPTION = "" +deploy_requires = [ + "bump2version", + "readme_renderer[md]", +] + +extras_require = { + "deploy": deploy_requires, +} + setup( name="github-deploy", @@ -31,6 +40,7 @@ license="MIT", packages=find_packages(), python_requires='>=3.6', + extras_require=extras_require, install_requires=[ "asyncclick", "asyncio",