development
yml 195 lines 5.87 KB
Raw
1 name: PyPI Release
2
3 # Dispatched by release-crates.yml once the crate publish succeeds.
4 on:
5 workflow_dispatch:
6 inputs:
7 tag:
8 description: "Release tag (e.g. v0.4.0)"
9 required: true
10
11 permissions:
12 id-token: write
13 contents: read
14
15 env:
16 CARGO_TERM_COLOR: always
17 ONDE_APP_ID: ${{ secrets.ONDE_APP_ID }}
18 ONDE_APP_SECRET: ${{ secrets.ONDE_APP_SECRET }}
19 GRESIQ_API_KEY: ${{ secrets.GRESIQ_API_KEY }}
20 GRESIQ_API_SECRET: ${{ secrets.GRESIQ_API_SECRET }}
21 HF_TOKEN: ${{ secrets.HF_TOKEN }}
22
23 jobs:
24 build-wheels:
25 name: Build PyPI wheels
26 runs-on: ${{ matrix.build.OS }}
27 strategy:
28 fail-fast: false
29 matrix:
30 build:
31 - {
32 NAME: linux-x64-glibc,
33 OS: ubuntu-latest,
34 TARGET: x86_64-unknown-linux-gnu,
35 MANYLINUX: "2014",
36 }
37 - {
38 NAME: linux-arm64-glibc,
39 OS: ubuntu-24.04-arm,
40 TARGET: aarch64-unknown-linux-gnu,
41 MANYLINUX: "2014",
42 }
43 - {
44 NAME: win32-x64-msvc,
45 OS: windows-2022,
46 TARGET: x86_64-pc-windows-msvc,
47 }
48 - {
49 NAME: win32-arm64-msvc,
50 OS: windows-2022,
51 TARGET: aarch64-pc-windows-msvc,
52 }
53 - {
54 NAME: darwin-x64,
55 OS: macos-26-intel,
56 TARGET: x86_64-apple-darwin,
57 }
58 - { NAME: darwin-arm64, OS: macos-26, TARGET: aarch64-apple-darwin }
59 steps:
60 - name: Checkout
61 uses: actions/checkout@v6
62 with:
63 ref: ${{ github.event.inputs.tag || github.ref }}
64
65 - name: Set the release version
66 shell: bash
67 run: |
68 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
69 release_version="${GITHUB_REF_NAME#v}"
70 else
71 release_version="${{ github.event.inputs.tag }}"
72 release_version="${release_version#v}"
73 fi
74 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
75
76 - name: Read Rust toolchain
77 shell: bash
78 run: |
79 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
80 if [ -z "$rust_toolchain" ]; then
81 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
82 exit 1
83 fi
84 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
85
86 - name: Install Rust toolchain
87 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
88 with:
89 toolchain: ${{ env.RUST_TOOLCHAIN }}
90
91 - name: Install Rust target
92 shell: bash
93 run: |
94 rustup target add ${{ matrix.build.TARGET }} --toolchain ${{ env.RUST_TOOLCHAIN }}
95 rustup target list --installed
96
97 - name: Build wheel
98 uses: PyO3/maturin-action@v1
99 with:
100 target: ${{ matrix.build.TARGET }}
101 manylinux: ${{ matrix.build.MANYLINUX || 'off' }}
102 working-directory: pypi
103 args: --release --locked --compatibility pypi --out dist
104 before-script-linux: yum install -y perl-core
105 docker-options: -e ONDE_APP_ID -e ONDE_APP_SECRET -e GRESIQ_API_KEY -e GRESIQ_API_SECRET -e HF_TOKEN
106
107 - name: Upload wheel artifact
108 uses: actions/upload-artifact@v4
109 with:
110 name: wheels-${{ matrix.build.NAME }}
111 path: pypi/dist/*
112
113 build-sdist:
114 name: Build source distribution
115 runs-on: ubuntu-latest
116 steps:
117 - name: Checkout
118 uses: actions/checkout@v6
119 with:
120 ref: ${{ github.event.inputs.tag || github.ref }}
121
122 - name: Read Rust toolchain
123 shell: bash
124 run: |
125 rust_toolchain="$(sed -n 's/^channel = "\(.*\)"/\1/p' rust-toolchain.toml | head -n 1)"
126 if [ -z "$rust_toolchain" ]; then
127 echo "Failed to read Rust toolchain from rust-toolchain.toml" >&2
128 exit 1
129 fi
130 echo "RUST_TOOLCHAIN=${rust_toolchain}" >> "$GITHUB_ENV"
131
132 - name: Install Rust toolchain
133 uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9
134 with:
135 toolchain: ${{ env.RUST_TOOLCHAIN }}
136
137 - name: Build sdist
138 uses: PyO3/maturin-action@v1
139 with:
140 command: sdist
141 working-directory: pypi
142 args: --out dist
143
144 - name: Upload sdist artifact
145 uses: actions/upload-artifact@v4
146 with:
147 name: sdist
148 path: pypi/dist/*
149
150 publish-pypi:
151 name: Publish to PyPI
152 runs-on: ubuntu-latest
153 needs:
154 - build-wheels
155 - build-sdist
156 steps:
157 - name: Checkout
158 uses: actions/checkout@v6
159 with:
160 ref: ${{ github.event.inputs.tag || github.ref }}
161
162 - name: Set the release version
163 shell: bash
164 run: |
165 if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
166 release_version="${GITHUB_REF_NAME#v}"
167 else
168 release_version="${{ github.event.inputs.tag }}"
169 release_version="${release_version#v}"
170 fi
171 echo "RELEASE_VERSION=${release_version}" >> "$GITHUB_ENV"
172
173 - name: Download distribution artifacts
174 uses: actions/download-artifact@v4
175 with:
176 pattern: "*"
177 path: dist
178 merge-multiple: true
179
180 - name: Check whether release already exists on PyPI
181 id: pypi-check
182 shell: bash
183 run: |
184 if curl -fsS "https://pypi.org/pypi/onde-cli/${RELEASE_VERSION}/json" >/dev/null 2>&1; then
185 echo "onde-cli ${RELEASE_VERSION} already exists on PyPI, skipping publish"
186 echo "exists=true" >> "$GITHUB_OUTPUT"
187 else
188 echo "exists=false" >> "$GITHUB_OUTPUT"
189 fi
190
191 - name: Publish distribution
192 if: steps.pypi-check.outputs.exists != 'true'
193 uses: pypa/gh-action-pypi-publish@release/v1
194 with:
195 skip-existing: true