Skip to content

Commit

Permalink
DEV: Automate the release process (#1970)
Browse files Browse the repository at this point in the history
This PR has two goals:

* Ensure that I, as a maintainer, do releases more consistently and with less effort.
* Enable other trusted members of the pypdf community and the py-pdf organization to make releases to PyPI. That should typically not be done, but is a last resort in case I become inactive.

What was done:

* A new repository secret `FLIT_PASSWORD` was created via PyPI. It is a PyPI token for pypdf.
* A Github Action `release.yaml` (this PR) was created.

## Hints

To ensure that you can write Markdown-style git tags, you can do this:

```
git config --global core.commentChar ";" 
```

## Testing

I used pdfly for that. Looks mostly fine. It especially published to PyPI.
See "TODO" for what is missing.

## TODO

* Make the release have rendered Markdown. I think I struggle with the fact that the body is a multi-line string ... maybe 🤔 
* Ensure the package is only pushed if it passes our test suite

## Resources

* https://github.com/actions/create-release
* https://flit.pypa.io/en/stable/cmdline.html#envvar-FLIT_INDEX_URL
* https://git-scm.com/docs/git-config#Documentation/git-config.txt-corecommentChar

Closes #1836
  • Loading branch information
MartinThoma authored Jul 16, 2023
1 parent 35be391 commit 21e4a75
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 10 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/github-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ jobs:
working-directory: /tmp
run: python -c "import pypdf;print(pypdf.__version__)"

# - name: Release to pypi if tagged.
# 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 tagged.
if: startsWith(github.ref, 'refs/tags/')
uses: softprops/action-gh-release@v1

coverage:
name: Combine & check coverage.
runs-on: ubuntu-latest
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This action assumes that there is a REL-commit which already has a
# Markdown-formatted git tag. Hence the CHANGELOG is already adjusted
# and it's decided what should be in the release.
# This action only ensures the release is done with the proper contents
# and that it's announced with a Github release.
name: Publish Python Package to PyPI
on:
push:
tags:
- '*.*.*'

jobs:
build_and_publish:
# this doesn't make sense if you don't have the PyPI secret
if: github.repository == 'py-pdf/pypdf'
name: Publish a new version of pypdf
runs-on: ubuntu-latest

steps:
# Ensure it's on PyPI
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Install Flit
run: |
python -m pip install --upgrade pip
pip install flit
- name: Publish Package to PyPI🚀
env:
FLIT_USERNAME: '__token__'
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
run: |
flit publish
# Create the Github Page
- name: Prepare variables
id: prepare_variables
run: |
git fetch --tags --force
latest_tag=$(git describe --tags --abbrev=0)
echo "latest_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"
tag_body=$(git tag -l "${latest_tag}" --format='%(contents:body)')
- name: Create GitHub Release 🚀
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Version ${{ env.latest_tag }}, ${{ env.date }}
draft: false
prerelease: false
body: Body is ${{ env.tag_body }}

0 comments on commit 21e4a75

Please sign in to comment.