Skip to content

Commit af88a91

Browse files
authored
[BRE-1135] Adding dev release CD support for pushes to main (#1352)
1 parent 0a2154e commit af88a91

File tree

5 files changed

+237
-92
lines changed

5 files changed

+237
-92
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build and Publish Python Wheels (Dev)
2+
run-name: ${{ github.ref != 'refs/heads/main' && 'Dry Run - ' || '' }}Build and Publish Python Wheels (Dev)
3+
4+
on:
5+
push:
6+
branches:
7+
- "main"
8+
workflow_dispatch:
9+
10+
concurrency:
11+
group: build-python-dev
12+
cancel-in-progress: false
13+
14+
env:
15+
_TARGET_DIR: target/wheels/dist
16+
17+
jobs:
18+
build-dev:
19+
name: Build Dev
20+
uses: ./.github/workflows/build-python-wheels.yml
21+
permissions:
22+
contents: read
23+
with:
24+
dev_version: true
25+
26+
publish-dev:
27+
name: Publish Dev
28+
environment: "Bitwarden SDK Python - Dev"
29+
runs-on: ubuntu-24.04
30+
needs: build-dev
31+
permissions:
32+
contents: read
33+
id-token: write
34+
steps:
35+
- name: Get workflow run assets
36+
env:
37+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38+
RUN_ID: ${{ github.run_id }}
39+
run: |
40+
gh run download "$RUN_ID" --repo "$GITHUB_REPOSITORY" --pattern "bitwarden_sdk-*.dev*"
41+
mkdir -p "$_TARGET_DIR"
42+
shopt -s globstar
43+
mv **/*.whl "$_TARGET_DIR"
44+
find "$_TARGET_DIR" -type f
45+
46+
- name: Publish dev package to Test PyPI
47+
if: github.ref == 'refs/heads/main'
48+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # v1.13.0
49+
with:
50+
repository-url: https://test.pypi.org/legacy/
51+
packages-dir: ${{ env._TARGET_DIR }}
52+
verify-metadata: true # Runs twine check before upload
53+
54+
validate:
55+
name: Validate Dev
56+
runs-on: ubuntu-24.04
57+
if: github.ref == 'refs/heads/main'
58+
needs:
59+
- build-dev
60+
- publish-dev
61+
permissions: {}
62+
env:
63+
_EXPECTED_VERSION: ${{ needs.build-dev.outputs.package_version }}
64+
steps:
65+
- name: Create and activate virtual environment
66+
run: |
67+
python3 -m venv venv
68+
source venv/bin/activate
69+
70+
- name: Install dev package from Test PyPI
71+
run: |
72+
timeout=60
73+
end_time=$((SECONDS + timeout))
74+
75+
while [ $SECONDS -lt $end_time ]; do
76+
if pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple "bitwarden-sdk==$_EXPECTED_VERSION" --pre; then
77+
echo "Package installed successfully"
78+
break
79+
else
80+
echo "Package installation failed, retrying in 5 seconds..."
81+
sleep 5
82+
fi
83+
done
84+
85+
if [ $SECONDS -ge $end_time ]; then
86+
echo "Package installation failed after $timeout seconds"
87+
exit 1
88+
fi
89+
90+
- name: Validate code version
91+
run: |
92+
echo "Python package version:"
93+
python -c "import bitwarden_sdk; print(bitwarden_sdk.__version__)"
94+
95+
package_version=$(python -c "import bitwarden_sdk; print(bitwarden_sdk.__version__)")
96+
if [ "$package_version" != "$_EXPECTED_VERSION" ]; then
97+
echo "==================================="
98+
echo "[!] Package version ($package_version) does not match expected version ($_EXPECTED_VERSION)"
99+
echo "==================================="
100+
exit 1
101+
fi

.github/workflows/build-python-wheels.yml

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@ on:
88
- "rc"
99
- "hotfix-rc"
1010
workflow_dispatch:
11+
inputs:
12+
dev_version:
13+
description: "Create a dev build (e.g., .dev1 suffix)"
14+
default: false
15+
type: boolean
16+
workflow_call:
17+
inputs:
18+
dev_version:
19+
description: "Create a dev build (e.g., .dev1 suffix)"
20+
required: true
21+
type: boolean
22+
outputs:
23+
package_version:
24+
description: "The package version (with optional .devX suffix)"
25+
value: ${{ jobs.setup.outputs.package_version }}
1126

1227
defaults:
1328
run:
1429
shell: bash
1530
working-directory: languages/python
1631

32+
env:
33+
_VERSION_FILE: ../../crates/bitwarden-py/Cargo.toml
34+
_TEST_PYPI_REPOSITORY_URL: https://test.pypi.org/pypi/bitwarden-sdk/json
35+
1736
permissions:
1837
contents: read
1938

@@ -24,17 +43,57 @@ jobs:
2443

2544
setup:
2645
name: Setup
27-
runs-on: ubuntu-22.04
46+
runs-on: ubuntu-24.04
2847
outputs:
2948
package_version: ${{ steps.retrieve-version.outputs.package_version }}
49+
package_version_cargo: ${{ steps.retrieve-version.outputs.package_version_cargo }}
3050
steps:
3151
- name: Checkout repo
3252
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
3353

3454
- name: Get Package Version
3555
id: retrieve-version
56+
env:
57+
USE_DEV_VERSION: ${{ inputs.dev_version }}
3658
run: |
37-
VERSION="$(grep -o '^version = ".*"' ../../crates/bitwarden-py/Cargo.toml | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
59+
VERSION="$(grep -o '^version = ".*"' "$_VERSION_FILE" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
60+
61+
if [ -z "$VERSION" ]; then
62+
echo "==================================="
63+
echo "[!] Could not determine package version from $_VERSION_FILE"
64+
echo "==================================="
65+
exit 1
66+
fi
67+
68+
if [ "$USE_DEV_VERSION" = "true" ]; then
69+
latest_dev_num=0
70+
71+
# Get all versions from PyPI that match the current package version with dev suffix
72+
dev_versions=$(curl -s "$_TEST_PYPI_REPOSITORY_URL" | \
73+
jq -r --arg version "$VERSION" \
74+
'.releases | keys[] | select(test("^" + $version + "\\.dev[0-9]+$"))' || true)
75+
76+
if [ -n "$dev_versions" ]; then
77+
# Extract dev numbers and find the latest
78+
latest_dev_num=$(echo "$dev_versions" | \
79+
sed -n "s/^${VERSION}\.dev\([0-9]\+\)$/\1/p" | \
80+
sort -n | \
81+
tail -1)
82+
else
83+
echo "Failed to retrieve current dev_versions from PyPi."
84+
exit 1
85+
fi
86+
87+
# Increment dev number
88+
new_dev_num=$((latest_dev_num + 1))
89+
dev_version_suffix=".dev${new_dev_num}"
90+
91+
echo "package_version_cargo=${VERSION}-dev${new_dev_num}" >> $GITHUB_OUTPUT
92+
93+
VERSION="${VERSION}${dev_version_suffix}"
94+
fi
95+
96+
echo "Package version: $VERSION"
3897
echo "package_version=$VERSION" >> $GITHUB_OUTPUT
3998
4099
build:
@@ -64,12 +123,12 @@ jobs:
64123
python-version: "3.9"
65124
maturin-build-args: ""
66125

67-
- os: ubuntu-22.04
126+
- os: ubuntu-24.04
68127
target: x86_64-unknown-linux-gnu
69128
python-version: "3.9"
70129
maturin-build-args: "--zig"
71130

72-
- os: ubuntu-22.04
131+
- os: ubuntu-24.04
73132
target: aarch64-unknown-linux-gnu
74133
python-version: "3.9"
75134
maturin-build-args: "--zig"
@@ -78,6 +137,23 @@ jobs:
78137
- name: Checkout repo
79138
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
80139

140+
- name: Add dev version suffix
141+
if: ${{ inputs.dev_version }}
142+
env:
143+
PACKAGE_VERSION_CARGO: ${{ needs.setup.outputs.package_version_cargo }}
144+
run: |
145+
echo "Updating version files with: $_PACKAGE_VERSION"
146+
147+
inplace_arg="-i"
148+
# Use sed with cross-platform compatibility (macOS and Linux)
149+
if [[ "$OSTYPE" == "darwin"* ]]; then
150+
inplace_arg="-i ''"
151+
fi
152+
153+
sed $inplace_arg "s/^version = \"[0-9]\.[0-9]\.[0-9]\"/version = \"$PACKAGE_VERSION_CARGO\"/" "$_VERSION_FILE"
154+
sed $inplace_arg "s/__version__ = \"[0-9]\.[0-9]\.[0-9]\"/__version__ = \"$_PACKAGE_VERSION\"/" bitwarden_sdk/__init__.py
155+
git diff
156+
81157
- name: Setup Python
82158
uses: actions/setup-python@e797f83bcb11b83ae66e0230d6156d7c80228e7c # v6.0.0
83159
with:
@@ -117,15 +193,15 @@ jobs:
117193
target: ${{ matrix.settings.target }}
118194
args: --release --interpreter python${{ matrix.settings.python-version }} ${{ matrix.settings.maturin-build-args }}
119195
sccache: true
120-
working-directory: ${{ github.workspace }}/languages/python
196+
working-directory: languages/python
121197

122198
- name: Build wheels (Linux - x86_64)
123199
if: ${{ matrix.settings.target == 'x86_64-unknown-linux-gnu' }}
124200
uses: PyO3/maturin-action@ea5bac0f1ccd0ab11c805e2b804bfcb65dac2eab # v1.45.0
125201
with:
126202
target: ${{ matrix.settings.target }}
127203
args: --release --sdist --interpreter python${{ matrix.settings.python-version }} ${{ matrix.settings.maturin-build-args }}
128-
working-directory: ${{ github.workspace }}/languages/python
204+
working-directory: languages/python
129205

130206
- name: Upload wheels
131207
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3

0 commit comments

Comments
 (0)