Skip to content

Commit cb69b2d

Browse files
authored
Merge pull request #149 from ngrok/add-manual-publish-option
use manual workflow dispatch to publish artifacts
2 parents 12b7906 + 90cc157 commit cb69b2d

File tree

5 files changed

+124
-74
lines changed

5 files changed

+124
-74
lines changed

.github/workflows/build.yml

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ on:
1414
type: boolean
1515
publish:
1616
required: false
17-
type: string
17+
type: boolean
18+
default: false
1819
setup:
1920
required: false
2021
type: string
@@ -26,6 +27,10 @@ jobs:
2627
if: ${{ inputs.if }}
2728
name: stable - ${{ inputs.target }} - python@3.12
2829
runs-on: ${{ inputs.host }}
30+
env:
31+
PYTHON_VERSION: "3.12"
32+
MATURIN_VERSION: "v1.9.1"
33+
XWIN_VERSION: "16"
2934
steps:
3035
- name: Checkout
3136
uses: actions/checkout@v4
@@ -50,8 +55,22 @@ jobs:
5055
if: ${{ inputs.target == 'i686-pc-windows-msvc' }}
5156
uses: actions/setup-python@v5
5257
with:
53-
python-version: "3.12"
58+
python-version: ${{ env.PYTHON_VERSION }}
5459
architecture: "x86"
60+
- name: Download ARM64 Python SDK
61+
if: ${{ inputs.target == 'aarch64-pc-windows-msvc' }}
62+
run: |
63+
curl -LO https://www.python.org/ftp/python/${{ env.PYTHON_VERSION }}.0/python-${{ env.PYTHON_VERSION }}.0-embed-arm64.zip
64+
mkdir python-arm64
65+
tar -xf python-${{ env.PYTHON_VERSION }}.0-embed-arm64.zip -C python-arm64
66+
- name: Set ARM64 Python environment variables
67+
if: ${{ inputs.target == 'aarch64-pc-windows-msvc' }}
68+
shell: pwsh
69+
run: |
70+
echo "PYTHONHOME=${{ github.workspace }}\python-arm64" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
71+
echo "PYTHONPATH=${{ github.workspace }}\python-arm64" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
72+
echo "PATH=${{ github.workspace }}\python-arm64;${env:PATH}" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
73+
5574
- name: Build and (Publish) musl for ${{ inputs.target }}
5675
uses: addnab/docker-run-action@v3
5776
if: ${{ inputs.target == 'x86_64-unknown-linux-musl' || inputs.target == 'aarch64-unknown-linux-musl' }}
@@ -72,8 +91,9 @@ jobs:
7291
7392
if [ "${SHOULD_PUBLISH}" == 'true' ]; then
7493
echo "~~~~ maturin publishing"
75-
. ./venv/bin/activate && maturin publish --no-sdist -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
94+
. ./venv/bin/activate && maturin publish --no-sdist --skip-existing -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
7695
fi
96+
7797
- name: Build and (Publish) aarch64-unknown-linux-gnu
7898
uses: addnab/docker-run-action@v3
7999
if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }}
@@ -101,7 +121,7 @@ jobs:
101121
if [ "${SHOULD_PUBLISH}" = 'true' ]; then
102122
echo "~~~~ maturin publishing"
103123
# pass '--debug' to avoid optimization, which breaks tls signature validation on this platform
104-
. .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --debug -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
124+
. .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --skip-existing --debug -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
105125
else
106126
echo "~~~~ maturin building"
107127
. .env/bin/activate && maturin build --target ${{ inputs.target }}
@@ -136,30 +156,59 @@ jobs:
136156
if [ "${SHOULD_PUBLISH}" = 'true' ]; then
137157
echo "~~~~ maturin publishing"
138158
# pass '--debug' to avoid optimization, which breaks tls signature validation on this platform
139-
. .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --debug -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
159+
. .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --skip-existing --debug -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
140160
else
141161
echo "~~~~ maturin building"
142162
RUST_BACKTRACE=1 . .env/bin/activate && maturin build --target ${{ inputs.target }} --verbose
143163
fi
164+
- name: Build and (Publish) x86_64-unknown-linux-gnu
165+
uses: addnab/docker-run-action@v3
166+
if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }}
167+
with:
168+
image: ${{ inputs.docker }}
169+
options: '-e SHOULD_PUBLISH=${{ inputs.publish }} --user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build'
170+
run: |
171+
# Update and install required packages
172+
sudo apt-get update
173+
sudo apt-get install -y llvm-dev clang libclang-dev gcc-multilib
174+
175+
# Install Rust minimal toolchain
176+
curl --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal
177+
export PATH="$HOME/.cargo/bin:$PATH"
178+
179+
# Add necessary Rust targets and components
180+
rustup component add llvm-tools-preview || true
181+
rustup target add x86_64-unknown-linux-gnu
182+
183+
# Create and activate Python virtual environment
184+
python3 -m venv .env
185+
. .env/bin/activate && pip install -r requirements.txt
186+
. .env/bin/activate && pip install patchelf
187+
188+
if [ "${SHOULD_PUBLISH}" = 'true' ]; then
189+
echo "~~~~ maturin publishing"
190+
. .env/bin/activate && maturin publish --target ${{ inputs.target }} --no-sdist --skip-existing -i python3.12 -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
191+
else
192+
echo "~~~~ maturin building"
193+
. .env/bin/activate && maturin build --target ${{ inputs.target }}
194+
fi
144195
- name: Build Python Extension Module (non-docker)
145196
if: ${{ inputs.publish != true && !inputs.docker && !contains(inputs.target,'android') }}
146197
uses: PyO3/maturin-action@v1
147198
with:
148-
maturin-version: v1.6.0
199+
maturin-version: ${{ env.MATURIN_VERSION }}
149200
target: ${{ inputs.target }}
150-
# builds in release mode with the specified python version as the interpreter and the Cargo.toml file as the manifest
151-
args: --release -i python3.12 --target ${{ inputs.target }} -m Cargo.toml
201+
args: --release -i python${{ env.PYTHON_VERSION }} --target ${{ inputs.target }} -m Cargo.toml
152202
env:
153-
# see https://github.com/PyO3/maturin/issues/2110
154-
XWIN_VERSION: '16'
203+
XWIN_VERSION: ${{ env.XWIN_VERSION }}
155204
- name: Publish to PyPI (non-docker)
156205
if: ${{ inputs.publish == true && !inputs.docker && !contains(inputs.target,'android') }}
157206
uses: PyO3/maturin-action@v1
158207
with:
159208
command: publish
160-
maturin-version: v1.6.0
209+
maturin-version: ${{ env.MATURIN_VERSION }}
161210
target: ${{ inputs.target }}
162-
args: --no-sdist -i python3.12 -m Cargo.toml -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
211+
args: --no-sdist --skip-existing -i python${{ env.PYTHON_VERSION }} -m Cargo.toml -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
163212
- name: Upload artifact
164213
uses: actions/upload-artifact@v4
165214
with:

.github/workflows/ci.yml

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,23 @@ env:
44
APP_NAME: ngrok
55
MACOSX_DEPLOYMENT_TARGET: '10.13'
66
on:
7+
workflow_call:
8+
inputs:
9+
publish:
10+
required: false
11+
default: false
12+
type: boolean
13+
secrets:
14+
NGROK_AUTHTOKEN:
15+
required: true
16+
MATURIN_PASSWORD:
17+
required: true
718
push:
19+
inputs:
20+
publish:
21+
required: false
22+
default: false
23+
type: boolean
824
branches:
925
- '**'
1026
tags-ignore:
@@ -15,11 +31,7 @@ on:
1531
- '**/*.gitignore'
1632
- .editorconfig
1733
- docs/**
18-
workflow_dispatch:
19-
pull_request:
20-
types: [opened, reopened]
21-
branches:
22-
- main
34+
2335
jobs:
2436
udeps:
2537
name: Udeps
@@ -61,42 +73,19 @@ jobs:
6173
run: |
6274
NGROK_AUTHTOKEN=${{ secrets.NGROK_AUTHTOKEN }} make mypy
6375
NGROK_AUTHTOKEN=${{ secrets.NGROK_AUTHTOKEN }} make testfast
64-
decide:
65-
name: Decide on Publishing
66-
runs-on: ubuntu-latest
67-
steps:
68-
- uses: actions/checkout@v4
69-
- name: Decide
70-
id: decide
71-
run: |
72-
echo "github.ref: ${{ github.ref }}"
73-
echo "github.repository: ${{ github.repository }}"
74-
echo "git log:"
75-
git log -1 --pretty=%B
76-
77-
if [ '${{ github.ref }}' == 'refs/heads/main' ] && [ '${{ github.repository }}' == 'ngrok/ngrok-python' ] && git log -1 --pretty=%B | grep "^Release [0-9]\+\.[0-9]\+\.[0-9]\+$"; then
78-
echo "SHOULD_PUBLISH=true" >> $GITHUB_OUTPUT
79-
else
80-
echo "SHOULD_PUBLISH=false" >> $GITHUB_OUTPUT
81-
fi
82-
cat $GITHUB_OUTPUT
83-
outputs:
84-
publish: ${{ steps.decide.outputs.SHOULD_PUBLISH }}
8576
8677
build:
8778
needs:
8879
- clippy
89-
- decide
9080
- fmt
9181
- test
9282
- udeps
9383
uses: ./.github/workflows/build.yml
9484
secrets: inherit
9585
with:
86+
publish: ${{ inputs.publish || false }}
9687
docker: ${{ matrix.settings.docker }}
9788
host: ${{ matrix.settings.host }}
98-
if: true
99-
publish: ${{ needs.decide.outputs.publish }}
10089
setup: ${{ matrix.settings.setup }}
10190
target: ${{ matrix.settings.target }}
10291
strategy:
@@ -123,6 +112,7 @@ jobs:
123112
docker: ghcr.io/rust-cross/manylinux2014-cross:armv7
124113
- host: ubuntu-latest
125114
target: x86_64-unknown-linux-gnu
115+
docker: ghcr.io/rust-cross/manylinux2014-cross:x86_64
126116
- host: ubuntu-latest
127117
target: x86_64-unknown-linux-musl
128118
docker: alpine:3.21
@@ -136,7 +126,6 @@ jobs:
136126
target: x86_64-pc-windows-msvc
137127

138128
build-freebsd:
139-
needs: decide
140129
runs-on: ubuntu-22.04
141130
name: Build FreeBSD
142131
timeout-minutes: 20
@@ -152,9 +141,8 @@ jobs:
152141
RUSTUP_HOME: /usr/local/rustup
153142
CARGO_HOME: /usr/local/cargo
154143
RUSTUP_IO_THREADS: 1
155-
SHOULD_PUBLISH: ${{ needs.decide.outputs.publish }}
156144
with:
157-
envs: RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS SHOULD_PUBLISH
145+
envs: RUSTUP_HOME CARGO_HOME RUSTUP_IO_THREADS
158146
usesh: true
159147
mem: 3000
160148
prepare: |
@@ -167,37 +155,12 @@ jobs:
167155
export PATH="/usr/local/cargo/bin:$PATH"
168156
python3 -m venv .env
169157
. .env/bin/activate && pip install -r requirements.txt
170-
if [ "${SHOULD_PUBLISH}" == 'true' ]; then
171-
echo "~~~~ maturin just building since pypi doesn't support BSD wheels"
172-
# https://discuss.python.org/t/pypi-org-unsupported-platform-tag-openbsd-7-0-amd64/16302
173-
# . .env/bin/activate && maturin publish --no-sdist -u __token__ -p ${{ secrets.MATURIN_PASSWORD }}
174-
. .env/bin/activate && maturin build
175-
else
176-
echo "~~~~ maturin building"
177-
. .env/bin/activate && maturin build
178-
fi
179-
# make the rsync back faster
158+
echo "~~~~ maturin building"
159+
. .env/bin/activate && maturin build
180160
rm -rf .env/ target/debug/ target/release/
181161
- name: Upload artifact
182162
uses: actions/upload-artifact@v4
183163
with:
184164
name: bindings-freebsd
185165
path: target/wheels/*.whl
186-
if-no-files-found: error
187-
tag:
188-
if: ${{ github.ref == 'refs/heads/main' && needs.decide.outputs.publish == true }}
189-
needs:
190-
- decide
191-
- build
192-
runs-on: ubuntu-latest
193-
name: Tag Release
194-
steps:
195-
- uses: actions/checkout@v4
196-
- uses: jrobsonchase/direnv-action@v0.7
197-
- name: Tag
198-
run: |
199-
version="$(extract-crate-version ngrok-python)"
200-
git config user.name "GitHub Action"
201-
git config user.email noreply@ngrok.com
202-
git tag -a -m "Version ${version}" v${version}
203-
git push --tags
166+
if-no-files-found: error

.github/workflows/publish.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish All
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
ci:
7+
name: Run CI
8+
uses: ./.github/workflows/ci.yml
9+
secrets:
10+
NGROK_AUTHTOKEN: ${{ secrets.NGROK_AUTHTOKEN }}
11+
MATURIN_PASSWORD: ${{ secrets.MATURIN_PASSWORD }}
12+
permissions:
13+
contents: write
14+
with:
15+
publish: true
16+
tag-release:
17+
name: Tag Release
18+
needs: ci
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v4
22+
- uses: jrobsonchase/direnv-action@v0.7
23+
- name: Tag Release
24+
run: |
25+
version="$(grep '^version =' Cargo.toml | head -n1 | awk -F\" '{print $2}')"
26+
tag="v${version}"
27+
git config user.name "GitHub Action"
28+
git config user.email noreply@ngrok.com
29+
echo "Version: ${version} tag: $tag"
30+
echo "Fetching all tags in the repository"
31+
git fetch --tags
32+
if git rev-parse "refs/tags/$tag" >/dev/null 2>&1; then
33+
echo "Tag $tag already exists, skipping tag creation."
34+
else
35+
echo "Tag $tag does not exist, pushing tag."
36+
git tag -a -m "Version ${version}" $tag
37+
git push --tags
38+
fi

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ changelog = "https://github.com/ngrok/ngrok-python/blob/main/CHANGELOG.md"
3131
ngrok-asgi = "ngrok:__main__.asgi_cli"
3232

3333
[build-system]
34-
requires = ["maturin>=1.5,<=1.6"]
34+
requires = ["maturin>=1.5,<=1.9.1"]
3535
build-backend = "maturin"
3636

3737
[tool.maturin]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
aiohttp==3.9.5 # async HTTP client/server framework
22
black==23.3.0 # code formatter
33
furo==2024.8.6 # customisable Sphinx theme
4-
maturin==1.6.0 # build and publish Python packages
4+
maturin==1.9.1 # build and publish Python packages
55
mypy==1.15.0 # static type checker
66
myst-parser==4.0.1 # Sphinx extension for Markdown
77
pytest-xdist==3.6.1 # run tests in parallel

0 commit comments

Comments
 (0)