Skip to content

Commit 21e4a75

Browse files
authored
DEV: Automate the release process (#1970)
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
1 parent 35be391 commit 21e4a75

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

.github/workflows/github-ci.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,6 @@ jobs:
138138
working-directory: /tmp
139139
run: python -c "import pypdf;print(pypdf.__version__)"
140140

141-
# - name: Release to pypi if tagged.
142-
# if: startsWith(github.ref, 'refs/tags')
143-
# uses: pypa/gh-action-pypi-publish@release/v1
144-
# with:
145-
# user: __token__
146-
# password: ${{ secrets.PYPI_API_TOKEN }}
147-
- name: Create GitHub release if tagged.
148-
if: startsWith(github.ref, 'refs/tags/')
149-
uses: softprops/action-gh-release@v1
150-
151141
coverage:
152142
name: Combine & check coverage.
153143
runs-on: ubuntu-latest

.github/workflows/release.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This action assumes that there is a REL-commit which already has a
2+
# Markdown-formatted git tag. Hence the CHANGELOG is already adjusted
3+
# and it's decided what should be in the release.
4+
# This action only ensures the release is done with the proper contents
5+
# and that it's announced with a Github release.
6+
name: Publish Python Package to PyPI
7+
on:
8+
push:
9+
tags:
10+
- '*.*.*'
11+
12+
jobs:
13+
build_and_publish:
14+
# this doesn't make sense if you don't have the PyPI secret
15+
if: github.repository == 'py-pdf/pypdf'
16+
name: Publish a new version of pypdf
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
# Ensure it's on PyPI
21+
- name: Checkout Repository
22+
uses: actions/checkout@v3
23+
24+
- name: Set up Python
25+
uses: actions/setup-python@v4
26+
with:
27+
python-version: 3.x
28+
29+
- name: Install Flit
30+
run: |
31+
python -m pip install --upgrade pip
32+
pip install flit
33+
34+
- name: Publish Package to PyPI🚀
35+
env:
36+
FLIT_USERNAME: '__token__'
37+
FLIT_PASSWORD: ${{ secrets.FLIT_PASSWORD }}
38+
run: |
39+
flit publish
40+
41+
# Create the Github Page
42+
- name: Prepare variables
43+
id: prepare_variables
44+
run: |
45+
git fetch --tags --force
46+
latest_tag=$(git describe --tags --abbrev=0)
47+
echo "latest_tag=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
48+
echo "date=$(date +'%Y-%m-%d')" >> "$GITHUB_ENV"
49+
tag_body=$(git tag -l "${latest_tag}" --format='%(contents:body)')
50+
- name: Create GitHub Release 🚀
51+
uses: actions/create-release@v1
52+
env:
53+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
54+
with:
55+
tag_name: ${{ github.ref }}
56+
release_name: Version ${{ env.latest_tag }}, ${{ env.date }}
57+
draft: false
58+
prerelease: false
59+
body: Body is ${{ env.tag_body }}

0 commit comments

Comments
 (0)