|
| 1 | +name: FIP test suite |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + bump_type: |
| 7 | + description: "Version bump type" |
| 8 | + required: false |
| 9 | + default: "rc" |
| 10 | + type: choice |
| 11 | + options: |
| 12 | + - rc |
| 13 | + - patch |
| 14 | + - minor |
| 15 | + - major |
| 16 | + - stable |
| 17 | + pull_request: |
| 18 | + push: |
| 19 | + branches: |
| 20 | + - main |
| 21 | + - dev* |
| 22 | + - release* |
| 23 | + release: |
| 24 | + types: [published] |
| 25 | + |
| 26 | +jobs: |
| 27 | + # ╔──────────────────────────╗ |
| 28 | + # │ _____ _ │ |
| 29 | + # │ |_ _|__ ___| |_ ___ │ |
| 30 | + # │ | |/ _ \/ __| __/ __| │ |
| 31 | + # │ | | __/\__ \ |_\__ \ │ |
| 32 | + # │ |_|\___||___/\__|___/ │ |
| 33 | + # │ │ |
| 34 | + # ╚──────────────────────────╝ |
| 35 | + tests: |
| 36 | + runs-on: windows-latest |
| 37 | + name: FIP unit tests |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v5 |
| 40 | + |
| 41 | + - uses: astral-sh/setup-uv@v6 |
| 42 | + with: |
| 43 | + enable-cache: true |
| 44 | + |
| 45 | + - name: Install python dependencies |
| 46 | + run: uv sync |
| 47 | + |
| 48 | + - name: Run ruff format |
| 49 | + run: uv run ruff format |
| 50 | + |
| 51 | + - name: Run ruff check |
| 52 | + run: uv run ruff check |
| 53 | + |
| 54 | + - name: Run codespell |
| 55 | + run: uv run codespell |
| 56 | + |
| 57 | + - name: Setup .NET Core SDK |
| 58 | + uses: actions/setup-dotnet@v4 |
| 59 | + with: |
| 60 | + dotnet-version: 8.x |
| 61 | + |
| 62 | + - name: Restore dotnet tools |
| 63 | + run: dotnet tool restore |
| 64 | + |
| 65 | + - name: Setup Bonsai environment |
| 66 | + working-directory: ./bonsai |
| 67 | + run: ./setup.ps1 |
| 68 | + |
| 69 | + - name: Run python unit tests |
| 70 | + run: uv run python -m unittest |
| 71 | + |
| 72 | + - name: Regenerate schemas |
| 73 | + run: uv run fip regenerate |
| 74 | + |
| 75 | + - name: Check for uncommitted changes |
| 76 | + run: | |
| 77 | + git config --global core.safecrlf false |
| 78 | + git diff --exit-code || (echo "Untracked changes found" && exit 1) |
| 79 | +
|
| 80 | + # ╔───────────────────────────────────────────────────────────╗ |
| 81 | + # │ ____ ___ ____ ____ ____ _ │ |
| 82 | + # │ / ___|_ _/ ___| _ \ | _ \ ___| | ___ __ _ ___ ___ │ |
| 83 | + # │ | | | | | | | | | | |_) / _ \ |/ _ \/ _` / __|/ _ \ │ |
| 84 | + # │ | |___ | | |___| |_| | | _ < __/ | __/ (_| \__ \ __/ │ |
| 85 | + # │ \____|___\____|____/ |_| \_\___|_|\___|\__,_|___/\___| │ |
| 86 | + # │ │ |
| 87 | + # ╚───────────────────────────────────────────────────────────╝ |
| 88 | + github-rc-release: |
| 89 | + needs: tests |
| 90 | + runs-on: windows-latest |
| 91 | + if: > |
| 92 | + github.ref == 'refs/heads/main' && |
| 93 | + github.event_name == 'push' && |
| 94 | + github.event.head_commit.author.email != 'github-actions[bot]@users.noreply.github.com' |
| 95 | + name: Create GitHub pre-release |
| 96 | + steps: |
| 97 | + - uses: actions/checkout@v5 |
| 98 | + with: |
| 99 | + fetch-depth: 0 |
| 100 | + ref: main |
| 101 | + |
| 102 | + - uses: astral-sh/setup-uv@v6 |
| 103 | + with: |
| 104 | + enable-cache: true |
| 105 | + |
| 106 | + - name: Bump pre-release by default |
| 107 | + # Note: Bumping the rc will fail if the version is not currently an rc |
| 108 | + # To solve it, we bump the patch and rc atomically |
| 109 | + shell: bash # interop with win/linux for if statement |
| 110 | + run: | |
| 111 | + if uv version --bump rc --dry-run; then |
| 112 | + uv version --bump rc |
| 113 | + else |
| 114 | + uv version --bump rc --bump patch |
| 115 | + fi |
| 116 | +
|
| 117 | + - name: Regenerate schemas |
| 118 | + run: uv run fip regenerate |
| 119 | + |
| 120 | + - name: Regenerate examples |
| 121 | + run: uv run ./examples/example.py --path-seed "./examples/{schema}.json" |
| 122 | + |
| 123 | + - name: Commit version and schema changes |
| 124 | + run: | |
| 125 | + git config --global user.name "github-actions[bot]" |
| 126 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 127 | + git add . |
| 128 | + git commit -m "Bump version and regenerate schemas [skip ci]" || echo "No changes to commit" |
| 129 | + git push origin main |
| 130 | +
|
| 131 | + - name: Get version |
| 132 | + id: get_version |
| 133 | + shell: bash |
| 134 | + run: | |
| 135 | + version=$(uv version --short) |
| 136 | + echo "version=$version" >> $GITHUB_OUTPUT |
| 137 | +
|
| 138 | + - name: Create GitHub Release |
| 139 | + uses: softprops/action-gh-release@v2 |
| 140 | + env: |
| 141 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 142 | + with: |
| 143 | + tag_name: v${{ steps.get_version.outputs.version }} |
| 144 | + name: v${{ steps.get_version.outputs.version }} |
| 145 | + generate_release_notes: true |
| 146 | + prerelease: true |
| 147 | + body: | |
| 148 | + Automated pre-release v${{ steps.get_version.outputs.version }} |
| 149 | +
|
| 150 | + # ╔─────────────────────────────────────────────────────────────────╗ |
| 151 | + # │ ____ _ _ _ ____ _ │ |
| 152 | + # │ | _ \ _ _| |__ | (_) ___ | _ \ ___| | ___ __ _ ___ ___ │ |
| 153 | + # │ | |_) | | | | '_ \| | |/ __| | |_) / _ \ |/ _ \/ _` / __|/ _ \ │ |
| 154 | + # │ | __/| |_| | |_) | | | (__ | _ < __/ | __/ (_| \__ \ __/ │ |
| 155 | + # │ |_| \__,_|_.__/|_|_|\___| |_| \_\___|_|\___|\__,_|___/\___| │ |
| 156 | + # │ │ |
| 157 | + # ╚─────────────────────────────────────────────────────────────────╝ |
| 158 | + |
| 159 | + prepare-public-release: |
| 160 | + runs-on: windows-latest |
| 161 | + name: Prepare files for public release |
| 162 | + needs: tests |
| 163 | + if: github.event_name == 'workflow_dispatch' |
| 164 | + outputs: |
| 165 | + version: ${{ steps.get_version.outputs.version }} |
| 166 | + is_prerelease: ${{ steps.check_prerelease.outputs.prerelease }} |
| 167 | + steps: |
| 168 | + - uses: actions/checkout@v5 |
| 169 | + with: |
| 170 | + fetch-depth: 0 |
| 171 | + ref: main |
| 172 | + |
| 173 | + - uses: astral-sh/setup-uv@v6 |
| 174 | + with: |
| 175 | + enable-cache: true |
| 176 | + |
| 177 | + - name: Get target version |
| 178 | + id: get_version |
| 179 | + shell: bash |
| 180 | + run: | |
| 181 | + # Use bump type from input (defaults to rc) |
| 182 | + bump_type="${{ github.event.inputs.bump_type || 'rc' }}" |
| 183 | + echo "Bumping version with type: $bump_type" |
| 184 | +
|
| 185 | + # Handle version bumping based on type |
| 186 | + if [[ "$bump_type" == "rc" ]]; then |
| 187 | + # Handle rc bumping logic (same as in github-rc-release) |
| 188 | + if uv version --bump rc --dry-run; then |
| 189 | + uv version --bump rc |
| 190 | + else |
| 191 | + uv version --bump rc --bump patch |
| 192 | + fi |
| 193 | + else |
| 194 | + # Handle patch, minor, major, stable |
| 195 | + uv version --bump $bump_type |
| 196 | + fi |
| 197 | +
|
| 198 | + release_version=$(uv run uv version --short) |
| 199 | + echo "version=$release_version" >> $GITHUB_OUTPUT |
| 200 | + echo "Release version will be: $release_version" |
| 201 | +
|
| 202 | + - name: Validate version format |
| 203 | + run: uv version ${{ steps.get_version.outputs.version }} --dry-run |
| 204 | + |
| 205 | + - name: Update package version |
| 206 | + run: uv version ${{ steps.get_version.outputs.version }} |
| 207 | + |
| 208 | + - name: Regenerate schemas |
| 209 | + run: uv run fip regenerate |
| 210 | + |
| 211 | + - name: Regenerate examples |
| 212 | + run: uv run ./examples/example.py --path-seed "./examples/{schema}.json" |
| 213 | + |
| 214 | + - name: Commit version, schema changes and create tag |
| 215 | + run: | |
| 216 | + git config --global user.name "github-actions[bot]" |
| 217 | + git config --global user.email "github-actions[bot]@users.noreply.github.com" |
| 218 | + git add . |
| 219 | + git commit -m "v${{ steps.get_version.outputs.version }} [skip ci]" |
| 220 | + git tag -a "v${{ steps.get_version.outputs.version }}" -m "Release v${{ steps.get_version.outputs.version }}" |
| 221 | + git push origin main |
| 222 | + git push origin "v${{ steps.get_version.outputs.version }}" |
| 223 | +
|
| 224 | + - name: Determine if prerelease |
| 225 | + id: check_prerelease |
| 226 | + shell: bash |
| 227 | + run: | |
| 228 | + version="${{ steps.get_version.outputs.version }}" |
| 229 | + if [[ "$version" == *"rc"* ]]; then |
| 230 | + echo "prerelease=true" >> $GITHUB_OUTPUT |
| 231 | + else |
| 232 | + echo "prerelease=false" >> $GITHUB_OUTPUT |
| 233 | + fi |
| 234 | +
|
| 235 | + - name: Create GitHub Release |
| 236 | + uses: softprops/action-gh-release@v2 |
| 237 | + env: |
| 238 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 239 | + with: |
| 240 | + tag_name: v${{ steps.get_version.outputs.version }} |
| 241 | + name: Release v${{ steps.get_version.outputs.version }} |
| 242 | + generate_release_notes: true |
| 243 | + prerelease: ${{ steps.check_prerelease.outputs.prerelease }} |
| 244 | + body: | |
| 245 | + Release v${{ steps.get_version.outputs.version }} |
| 246 | +
|
| 247 | + This release was manually triggered. |
| 248 | +
|
| 249 | + publish-to-pypi: |
| 250 | + runs-on: windows-latest |
| 251 | + name: Publish to PyPI |
| 252 | + needs: [tests, prepare-public-release] |
| 253 | + if: | |
| 254 | + (github.event_name == 'workflow_dispatch') || |
| 255 | + (github.event_name == 'release' && |
| 256 | + github.event.action == 'published' && |
| 257 | + !github.event.release.prerelease && |
| 258 | + startsWith(github.ref, 'refs/tags/v')) |
| 259 | + steps: |
| 260 | + - uses: actions/checkout@v5 |
| 261 | + with: |
| 262 | + fetch-depth: 0 |
| 263 | + ref: ${{ github.event_name == 'workflow_dispatch' && 'main' || github.ref_name }} |
| 264 | + |
| 265 | + - uses: astral-sh/setup-uv@v6 |
| 266 | + with: |
| 267 | + enable-cache: true |
| 268 | + |
| 269 | + - name: Verify version consistency (for automatic releases) |
| 270 | + if: github.event_name == 'release' |
| 271 | + shell: bash |
| 272 | + run: | |
| 273 | + tag_version=$(echo "${{ github.ref_name }}" | sed 's/^v//') |
| 274 | + package_version=$(uv run uv version --short) |
| 275 | + if [[ "$tag_version" != "$package_version" ]]; then |
| 276 | + echo "ERROR: Tag version ($tag_version) doesn't match package version ($package_version)" |
| 277 | + exit 1 |
| 278 | + fi |
| 279 | + echo "✅ Version consistency verified: $tag_version" |
| 280 | +
|
| 281 | + - name: Get current version (for manual releases) |
| 282 | + if: github.event_name == 'workflow_dispatch' |
| 283 | + shell: bash |
| 284 | + run: | |
| 285 | + package_version=$(uv run uv version --short) |
| 286 | + echo "📦 Publishing version: $package_version" |
| 287 | +
|
| 288 | + - name: Build |
| 289 | + run: uv build |
| 290 | + |
| 291 | + - name: Publish to PyPI |
| 292 | + run: uv publish --token ${{ secrets.AIND_PYPI_TOKEN }} |
| 293 | + |
| 294 | + # ╔─────────────────────────╗ |
| 295 | + # │ ____ │ |
| 296 | + # │ | _ \ ___ ___ ___ │ |
| 297 | + # │ | | | |/ _ \ / __/ __| │ |
| 298 | + # │ | |_| | (_) | (__\__ \ │ |
| 299 | + # │ |____/ \___/ \___|___/ │ |
| 300 | + # │ │ |
| 301 | + # ╚─────────────────────────╝ |
| 302 | + build-docs: |
| 303 | + name: Build and deploy documentation to GitHub Pages |
| 304 | + runs-on: ubuntu-latest |
| 305 | + needs: publish-to-pypi |
| 306 | + steps: |
| 307 | + - name: Checkout repository |
| 308 | + uses: actions/checkout@v5 |
| 309 | + |
| 310 | + - name: Install uv |
| 311 | + uses: astral-sh/setup-uv@v3 |
| 312 | + |
| 313 | + - name: Setup Graphviz |
| 314 | + uses: ts-graphviz/setup-graphviz@v2 |
| 315 | + |
| 316 | + - name: Install docs group of dependencies |
| 317 | + run: uv sync --group docs |
| 318 | + |
| 319 | + - name: Build Sphinx documentation |
| 320 | + run: uv run sphinx-build -b html docs/ _build/html |
| 321 | + |
| 322 | + - name: Deploy to GitHub Pages |
| 323 | + uses: peaceiris/actions-gh-pages@v4 |
| 324 | + with: |
| 325 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 326 | + publish_dir: _build/html |
| 327 | + force_orphan: true |
0 commit comments