From d89cc357ee4d3be82412b14f4c1aee9e1141f5d2 Mon Sep 17 00:00:00 2001 From: Pieter Marsman Date: Sat, 19 Mar 2022 20:46:00 +0100 Subject: [PATCH] Add github action for releasing to pypi if git tag is added. (#727) * Add github action for releasing to pypi if git tag is added. * Checkout code and fix typos. * Replace end with fi * Strictly numeric version for testing. * Remove obsolete Make commands for publishing * Also create GitHub release * Update pdfminer/__init__.py Co-authored-by: Jake Stockwin * Remove test pypi release * Use maintained github action for releasing * Change tag format for versions * Undo commenting pypi publishing * Remove develop branch, since that will be removed in favor off adding tags for releases. * Change version regex Co-authored-by: Jake Stockwin --- .github/workflows/actions.yml | 55 +++++++++++++++++++++++++++++++---- CONTRIBUTING.md | 4 +-- Makefile | 26 ----------------- pdfminer/Makefile | 9 ------ pdfminer/__init__.py | 2 +- tools/Makefile | 8 ----- 6 files changed, 53 insertions(+), 51 deletions(-) delete mode 100644 pdfminer/Makefile delete mode 100644 tools/Makefile diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 41452b6..1d4804f 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -1,14 +1,14 @@ name: Continuous integration on: - push: # run when commits are added to master or develop + push: # run when commits are added to master branches: - master - - develop - pull_request: # run on pr's against master or develop + tags: + - [ 0-9 ]{ 8 } # match version tags with format like 20220319 + pull_request: # run on pr's against master branches: - master - - develop env: default-python: "3.10" @@ -107,4 +107,49 @@ jobs: python -m pip install nox - name: Build docs run: | - nox --error-on-missing-interpreters --non-interactive --session docs \ No newline at end of file + nox --error-on-missing-interpreters --non-interactive --session docs + + publish: + name: Publish to PyPi + runs-on: ubuntu-latest + needs: + - check-code-formatting + - check-coding-style + - check-static-types + - tests + - build-docs + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install dependencies + run: python -m pip install wheel + - name: Set version + run: | + if [[ "${{ github.ref }}" == "refs/tags/"* ]] + then + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' | sed -e 's/^v//') + else + VERSION=$(date +%Y%m%d).$(date +%H%M%S) + fi + echo ${VERSION} + sed -i "s/__VERSION__/${VERSION}/g" pdfminer/__init__.py + - name: Build package + run: python setup.py sdist bdist_wheel + - name: Generate changelog + run: sed '1,/## \[/d;/## \[/Q' CHANGELOG.md > ${{ github.workspace }}-CHANGELOG.md + - name: Publish package to PyPi + if: startsWith(github.ref, 'refs/tags') + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} + - name: Create GitHub release + if: startsWith(github.ref, 'refs/tags') + uses: softprops/action-gh-release@v1 + id: create_release + with: + token: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token + body_path: ${{ github.workspace }}-CHANGELOG.md + files: | + dist/*.tar.gz + dist/*.whl \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6455696..be55249 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -27,8 +27,8 @@ Any contribution is appreciated! You might want to: ## Guideline for creating pull request * A pull request should close an existing issue. -* Pull requests should be merged to develop, not master. This ensures that master always equals the released version. -* Include unit tests when possible. In case of bugs, this will help to prevent the same mistake in the future. In case +* Pull requests should be merged to master. Version tags are used indicate the releases. +* Include unit tests when possible. In case of bugs, this will help to prevent the same mistake in the future. In case of features, this will show that your code works correctly. * Code should work for Python 3.6+. * Code should be formatted with [black](https://github.com/psf/black). diff --git a/Makefile b/Makefile index a4da1af..a25670f 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,11 @@ ## Makefile (for maintenance purpose) ## -PACKAGE=pdfminer - PYTHON=python -GIT=git RM=rm -f CP=cp -f MKDIR=mkdir -all: - -install: - $(PYTHON) setup.py install --home=$(HOME) - -clean: - -$(PYTHON) setup.py clean - -$(RM) -r build dist MANIFEST - -cd $(PACKAGE) && $(MAKE) clean - -cd tools && $(MAKE) clean - -cd samples && $(MAKE) clean - -distclean: clean cmap_clean - -sdist: distclean MANIFEST.in - $(PYTHON) setup.py sdist -register: distclean MANIFEST.in - $(PYTHON) setup.py sdist upload register - -WEBDIR=../euske.github.io/$(PACKAGE) -publish: - $(CP) docs/*.html docs/*.png docs/*.css $(WEBDIR) - CONV_CMAP=$(PYTHON) tools/conv_cmap.py CMAPSRC=cmaprsrc CMAPDST=pdfminer/cmap diff --git a/pdfminer/Makefile b/pdfminer/Makefile deleted file mode 100644 index 1d1661b..0000000 --- a/pdfminer/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# Makefile for pdfminer - -RM=rm -f - -all: - -clean: - -$(RM) *.pyc *.pyo - cd cmap && make clean diff --git a/pdfminer/__init__.py b/pdfminer/__init__.py index 5df9646..e8e5221 100644 --- a/pdfminer/__init__.py +++ b/pdfminer/__init__.py @@ -1,4 +1,4 @@ -__version__ = "20211012" +__version__ = "__VERSION__" # auto replaced with tag in github actions if __name__ == "__main__": print(__version__) diff --git a/tools/Makefile b/tools/Makefile deleted file mode 100644 index ed51702..0000000 --- a/tools/Makefile +++ /dev/null @@ -1,8 +0,0 @@ -# Makefile for tools - -RM=rm -f - -all: - -clean: - -$(RM) *.pyc *.pyo *.cgic *.cgio