Skip to content

Commit 168c1ab

Browse files
authored
CI: Implement automatic dynamic versioning for pre-releases (#469)
1 parent 5366b13 commit 168c1ab

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

.github/workflows/pypi_publish.yml

+24-10
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Note: We may want to rename this file at some point. However, if we rename the workflow file name,
66
# we have to also update the Trusted Publisher settings on PyPI.
77

8-
name: Packaging and Publishing
8+
name: CDK Publish
99

1010
on:
1111
push:
@@ -14,7 +14,12 @@ on:
1414
workflow_dispatch:
1515
inputs:
1616
version:
17-
description: "Note that this workflow is intended for prereleases. For public-facing stable releases, please use the GitHub Releases workflow instead: https://github.com/airbytehq/airbyte-python-cdk/blob/main/docs/RELEASES.md. If running this workflow from main or from a dev branch, please enter the desired version number here, for instance 1.2.3dev0 or 1.2.3rc1."
17+
description: >
18+
Note that this workflow is intended for prereleases. For public-facing stable releases,
19+
please use the GitHub Releases workflow instead:
20+
https://github.com/airbytehq/airbyte-python-cdk/blob/main/docs/RELEASES.md.
21+
For prereleases, please leave the version blank to use the detected version. Alternatively,
22+
you can override the dynamic versioning for special use cases.
1823
required: false
1924
publish_to_pypi:
2025
description: "Publish to PyPI. If true, the workflow will publish to PyPI."
@@ -37,17 +42,30 @@ jobs:
3742
name: Build Python Package
3843
runs-on: ubuntu-24.04
3944
steps:
40-
- name: Detect Release Tag Version
45+
46+
- name: Checkout CDK Repo
47+
uses: actions/checkout@v4
48+
with:
49+
fetch-depth: 0
50+
51+
- name: Detect Prerelease Version using Dunamai
52+
uses: mtkennerly/dunamai-action@v1
53+
with:
54+
args: --style pep440
55+
env-var: DETECTED_VERSION
56+
57+
- name: Detect Release Tag Version from git ref ('${{ github.ref_name }}')
4158
if: startsWith(github.ref, 'refs/tags/v')
4259
run: |
60+
echo "Overriding Dunamai detected version: '${{ env.DETECTED_VERSION || 'none' }}'"
61+
# Extract the version from the git ref
4362
DETECTED_VERSION=${{ github.ref_name }}
44-
echo "Version ref set to '${DETECTED_VERSION}'"
4563
# Remove the 'v' prefix if it exists
4664
DETECTED_VERSION="${DETECTED_VERSION#v}"
47-
echo "Setting version to '$DETECTED_VERSION'"
65+
echo "Setting detected version to '$DETECTED_VERSION'"
4866
echo "DETECTED_VERSION=${DETECTED_VERSION}" >> $GITHUB_ENV
4967
50-
- name: Validate and set VERSION from git ref ('${{ github.ref_name }}') and input (${{ github.event.inputs.version || 'none' }})
68+
- name: Validate and set VERSION (detected='${{ env.DETECTED_VERSION }}', input='${{ github.event.inputs.version || 'none' }}')
5169
id: set_version
5270
run: |
5371
INPUT_VERSION=${{ github.event.inputs.version }}
@@ -84,10 +102,6 @@ jobs:
84102
echo "IS_PRERELEASE=true" >> $GITHUB_OUTPUT
85103
fi
86104
87-
- uses: actions/checkout@v4
88-
with:
89-
fetch-depth: 0
90-
91105
- uses: hynek/build-and-inspect-python-package@v2
92106
env:
93107
# Pass in the evaluated version from the previous step

docs/RELEASES.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ _Note:_
2121

2222
This process is slightly different from the above, since we don't necessarily want public release notes to be published for internal testing releases. The same underlying workflow will be run, but we'll kick it off directly:
2323

24-
1. Navigate to the "Packaging and Publishing" workflow in GitHub Actions.
25-
2. Type the version number - including a valid pre-release suffix. Examples: `1.2.3dev0`, `1.2.3rc1`, `1.2.3b0`, etc.
26-
3. Select `main` or your dev branch from the "Use workflow from" dropdown.
27-
4. Select your options and click "Run workflow".
28-
5. Monitor the workflow to ensure the process has succeeded.
24+
1. Navigate to the "Publish CDK" workflow in GitHub Actions.
25+
2. Select your dev branch (or `main`) from the "Use workflow from" dropdown.
26+
3. Leave the version number blank, allowing the CI workflow to pick a version number
27+
using [Dunamai](https://dunamai.readthedocs.io).
28+
4. Select from the other options and click "Run workflow".
29+
5. Monitor the workflow to ensure the process has succeeded. You will see the
30+
version number in the GitHub Actions job output and in GitHub Environments view.
2931

3032
## Understanding and Debugging Builder and SDM Releases
3133

@@ -59,15 +61,15 @@ To manually test changes against a dev image of SDM before committing to a relea
5961

6062
Once the publish pipeline has completed, choose a connector to test. Set the base_image in the connector's metadata to your pre-release version in Dockerhub (make sure to update the SHA as well).
6163
Next, build the pre-release image locally using `airbyte-ci connectors —name=<source> build`.
62-
You can now run connector interfaces against the built image using the pattern`docker run airbyte/<source-name>:dev <spec/check/discover/read>`.
64+
You can now run connector interfaces against the built image using the pattern`docker run airbyte/<source-name>:dev <spec/check/discover/read>`.
6365
The connector's README should include a list of these commands, which can be copy/pasted and run from the connector's directory for quick testing against a local config.
6466
You can also run `airbyte-ci connectors —name=<source> test` to run the CI test suite against the dev image.
6567

6668
#### Pretesting Low-Code Python connectors
6769

6870
Once the publish pipeline has completed, set the version of `airbyte-cdk` in the connector's pyproject.toml file to the pre-release version in PyPI.
69-
Update the lockfile and run connector interfaces via poetry:`poetry run source-<name> spec/check/discover/read`.
70-
You can also run `airbyte-ci connectors —name=<source> test` to run the CI test suite against the dev image.


71+
Update the lockfile and run connector interfaces via poetry:`poetry run source-<name> spec/check/discover/read`.
72+
You can also run `airbyte-ci connectors —name=<source> test` to run the CI test suite against the dev image.
7173

7274
#### Pretesting in Cloud
7375

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ version = "0.0.0" # Version will be calculated dynamically.
2727

2828
[tool.poetry-dynamic-versioning]
2929
enable = true
30+
style = "pep440" # Ensures compatibility with PyPI
3031

3132
[tool.poetry.dependencies]
3233
python = ">=3.10,<3.13"

0 commit comments

Comments
 (0)