Skip to content

Commit 9823ef1

Browse files
authored
Merge pull request #57 from ConvertAPI/trunk-based-release
Trunk-based releases: build on main, publish from a GitHub Release
2 parents 67f6683 + 837b1b0 commit 9823ef1

18 files changed

Lines changed: 740 additions & 178 deletions

‎.github/dependabot.yml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
# The workflows pin every action to a commit SHA; Dependabot keeps those pins current.
4+
- package-ecosystem: github-actions
5+
directory: /
6+
schedule:
7+
interval: weekly
8+
groups:
9+
actions:
10+
patterns: ['*']

‎.github/workflows/build.yml‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
name: Build
2+
run-name: >-
3+
${{ github.event_name == 'pull_request' && format('Checking that #{0} builds', github.event.pull_request.number)
4+
|| format('Building {0}', github.ref_name) }}
5+
6+
# Trunk-based: main is the only long-lived branch. Every pull request and every push to main runs the tests
7+
# on each supported Python and builds the sdist and wheel, but nothing is published here: this is a public
8+
# PyPI package, and PyPI versions are permanent, so a release is a deliberate act - publishing a GitHub
9+
# Release v{semver}, which runs publish.yml. The required status check is the `build` job, which passes
10+
# only when every test job passed and the packages built.
11+
on:
12+
pull_request:
13+
branches: [main]
14+
push:
15+
branches: [main]
16+
workflow_dispatch:
17+
18+
permissions:
19+
contents: read
20+
21+
concurrency:
22+
# A newer push to the same pull request cancels the older build; builds of main never cancel each other.
23+
group: build-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }}
24+
cancel-in-progress: true
25+
26+
jobs:
27+
test:
28+
name: test (Python ${{ matrix.python }})
29+
runs-on: ubuntu-latest
30+
timeout-minutes: 15
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
python: ['3.10', '3.11', '3.12', '3.13']
35+
steps:
36+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
37+
with:
38+
persist-credentials: false
39+
40+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
41+
with:
42+
python-version: ${{ matrix.python }}
43+
44+
- name: Install
45+
run: python -m pip install . -r test-requirements.txt
46+
47+
# The tests marked `live` convert real files on ConvertAPI and run only when the CONVERTAPI_SECRET
48+
# secret (an API token) exists; pull requests from forks and Dependabot never get it, so for them
49+
# only the mocked tests run. CONVERTAPI_BASE_URI (a variable) can point them at another deployment.
50+
- name: Test
51+
env:
52+
CONVERT_API_SECRET: ${{ secrets.CONVERTAPI_SECRET }}
53+
CONVERT_API_BASE_URI: ${{ vars.CONVERTAPI_BASE_URI }}
54+
run: python -m pytest -ra
55+
56+
build:
57+
name: build
58+
needs: test
59+
# Runs even when a test job failed, so that the required check reports a failure instead of being
60+
# skipped - a skipped required check counts as passed.
61+
if: always()
62+
runs-on: ubuntu-latest
63+
timeout-minutes: 10
64+
steps:
65+
- name: Check the tests
66+
env:
67+
RESULT: ${{ needs.test.result }}
68+
run: |
69+
if [ "$RESULT" != success ]; then
70+
echo "::error::The tests did not pass ($RESULT)"
71+
exit 1
72+
fi
73+
74+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
75+
with:
76+
persist-credentials: false
77+
78+
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
79+
with:
80+
python-version: '3.13'
81+
82+
- name: Install the build tools
83+
run: python -m pip install build==1.6.1 twine==7.0.0
84+
85+
# A development version that sorts below any real release and names the run, so a package
86+
# downloaded from this run can be tried out but never mistaken for a published one. PyPI refuses
87+
# local versions ("+g..."), so it could not be uploaded even by mistake.
88+
- name: Build
89+
id: build
90+
env:
91+
RUN: ${{ github.run_number }}
92+
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
93+
run: |
94+
set -euo pipefail
95+
VERSION="0.0.0.dev$RUN+g${SHA:0:7}"
96+
sed -i "s/^__version__ = .*/__version__ = '$VERSION'/" convertapi/__init__.py
97+
grep -qx "__version__ = '$VERSION'" convertapi/__init__.py
98+
python -m build -o dist
99+
twine check --strict dist/*
100+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
101+
102+
- name: Check the wheel installs
103+
env:
104+
VERSION: ${{ steps.build.outputs.version }}
105+
run: |
106+
set -euo pipefail
107+
python -m venv "$RUNNER_TEMP/venv"
108+
"$RUNNER_TEMP/venv/bin/pip" install dist/*.whl
109+
cd "$RUNNER_TEMP"
110+
"$RUNNER_TEMP/venv/bin/python" -c 'import sys, convertapi; assert convertapi.__version__ == sys.argv[1], convertapi.__version__; print(convertapi.user_agent)' "$VERSION"
111+
112+
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
113+
with:
114+
name: convertapi-${{ steps.build.outputs.version }}
115+
path: dist/
116+
retention-days: 14
117+
if-no-files-found: error
118+
119+
- name: Summary
120+
env:
121+
VERSION: ${{ steps.build.outputs.version }}
122+
run: |
123+
{
124+
echo "| | |"
125+
echo "|---|---|"
126+
echo "| Package | \`convertapi $VERSION\` (artifact only, not published) |"
127+
echo "| Files | $(ls dist | paste -sd ',' - | sed 's/,/, /g') |"
128+
} >> "$GITHUB_STEP_SUMMARY"

‎.github/workflows/main.yml‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)