Skip to content

Commit b585963

Browse files
authored
Add dev package support to build_packages.yml. (#667)
Progress on #584. ~~Depends on #666 (the first commit).~~ This is refactors the `build_packages.yml` workflow so it can be used via `workflow_call` as part of a "pkgci" setup, as an alternative to creating a new `pkgci_build_packages.yml` workflow as originally proposed in #589. This lets us reuse the same workflow for building stable, nightly, and dev packages, all across the same matrix of Python versions and operating systems. Package builds take about 2 minutes (wall time) across the full matrix, so we might as well build them all, instead of artificially constraining ourselves to a subset like only Linux on Python 3.11. Triggers for the workflow are now this: Trigger | Scenario | Build type(s) -- | -- | -- `schedule` | Nightly pre-release build | `rc` `workflow_dispatch` | Workflow testing, manual releasing | `rc` default, `stable` and `dev` possible `workflow_call` | Pull request or push "pkgci" dev builds | `dev` default, `stable` and `rc` possible With this workflow behavior: Build type | Version suffix | Cache enabled? | Tracing enabled? | Pushes to release? -- | -- | -- | -- | -- `stable` | None | No | Yes | No `rc` | `rcYYYYMMDD` | No | Yes | Yes `dev` | `.dev0+${{ github.sha }}` | Yes | No | No Tested over at https://github.com/ScottTodd/shark-ai/actions/workflows/build_packages.yml. Example run: https://github.com/ScottTodd/shark-ai/actions/runs/12245900071 (warm cache)
1 parent 518c3ec commit b585963

File tree

1 file changed

+62
-19
lines changed

1 file changed

+62
-19
lines changed

.github/workflows/build_packages.yml

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,21 @@
77
name: Build packages
88

99
on:
10+
# Trigger from another workflow (typically to build dev packages and then test them)
11+
workflow_call:
12+
inputs:
13+
build_type:
14+
description: The type of build version to produce ("stable", "rc", or "dev")
15+
type: string
16+
default: "dev"
17+
# Trigger manually (typically to test the workflow or manually build a release [candidate])
1018
workflow_dispatch:
19+
inputs:
20+
build_type:
21+
description: The type of build version to produce ("stable", "rc", or "dev")
22+
type: string
23+
default: "rc"
24+
# Trigger on a schedule to build nightly release candidates.
1125
schedule:
1226
# Runs at 11:00 AM UTC, which is 3:00 AM PST (UTC-8)
1327
- cron: '0 11 * * *'
@@ -16,14 +30,12 @@ permissions:
1630
contents: read
1731

1832
jobs:
19-
# Note: metadata generation could happen in a separate trigger/schedule
20-
# workflow. For cross platform builds, it's useful to just generate the
21-
# metadata on Linux and pass that to later jobs using artifacts.
33+
# Generate metadata on Linux and pass to later jobs.
2234
setup_metadata:
2335
if: ${{ github.repository_owner == 'nod-ai' || github.event_name != 'schedule' }}
2436
runs-on: ubuntu-24.04
2537
outputs:
26-
version_suffix: ${{ steps.version_rc.outputs.version_suffix }}
38+
version_suffix: ${{ steps.version_local.outputs.version_suffix }}
2739
steps:
2840
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2941
- name: Setup Python
@@ -34,18 +46,35 @@ jobs:
3446
- name: Install Python packages
3547
run: pip install packaging
3648

37-
- name: Generate release candidate versions
38-
id: version_rc
49+
# Compute version suffix based on inputs (default to 'rc')
50+
- name: Compute stable version suffix
51+
if: ${{ inputs.build_type == 'stable' }}
52+
run: |
53+
version_suffix=""
54+
echo "version_suffix=${version_suffix}" >> $GITHUB_ENV
55+
- name: Compute rc version suffix
56+
if: ${{ inputs.build_type == 'rc' || inputs.build_type == '' }}
3957
run: |
4058
version_suffix="$(printf 'rc%(%Y%m%d)T')"
59+
echo "version_suffix=${version_suffix}" >> $GITHUB_ENV
60+
- name: Compute dev version suffix
61+
if: ${{ inputs.build_type == 'dev' }}
62+
run: |
63+
version_suffix=".dev0+${{ github.sha }}"
64+
echo "version_suffix=${version_suffix}" >> $GITHUB_ENV
65+
66+
- name: Write version local files
67+
id: version_local
68+
run: |
4169
echo "version_suffix=${version_suffix}" >> $GITHUB_OUTPUT
4270
python3 build_tools/python_deploy/compute_local_version.py --version-suffix=${version_suffix} sharktank
4371
python3 build_tools/python_deploy/compute_local_version.py --version-suffix=${version_suffix} shortfin
4472
python3 build_tools/python_deploy/compute_common_version.py -rc --version-suffix=${version_suffix} --write-json
45-
- name: Upload version_local.json
73+
74+
- name: Upload version_local.json files
4675
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
4776
with:
48-
name: version_local
77+
name: version_local_files
4978
path: |
5079
sharktank/version_local.json
5180
shortfin/version_local.json
@@ -57,6 +86,8 @@ jobs:
5786
permissions:
5887
contents: write
5988
needs: [setup_metadata]
89+
env:
90+
OUTPUT_DIR: "${{ github.workspace }}/bindist"
6091
strategy:
6192
fail-fast: false
6293
matrix:
@@ -101,47 +132,59 @@ jobs:
101132
path: "c" # Windows can hit path length limits, so use a short path.
102133
submodules: false
103134

104-
- name: Download version_local.json
135+
- name: Download version_local.json files
105136
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
106137
with:
107-
name: version_local
138+
name: version_local_files
108139
path: ./c/
109140
merge-multiple: true
110141

142+
# Dev builds can use a cache and disable tracing to halve the build time.
143+
# Other build use no cache for supply chain security and keep tracing enabled.
144+
- name: Apply dev settings
145+
if: ${{ inputs.build_type == 'dev' }}
146+
run: |
147+
echo "CACHE_DIR=${{ github.workspace }}/.shark-ai-cache" >> $GITHUB_ENV
148+
echo "SHORTFIN_ENABLE_TRACING=OFF" >> $GITHUB_ENV
149+
- name: Setup cache
150+
if: ${{ inputs.build_type == 'dev' }}
151+
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
152+
with:
153+
path: ${{ env.CACHE_DIR }}
154+
key: build-packages-${{ matrix.package }}-${{ matrix.platform }}-${{ matrix.python-version }}-v1-${{ github.sha }}
155+
restore-keys: |
156+
build-packages-${{ matrix.package }}-${{ matrix.platform }}-${{ matrix.python-version }}-v1-
157+
158+
# Build packages.
111159
- name: Build shark-ai (Linux x86_64)
112160
if: "matrix.package == 'shark-ai' && matrix.platform == 'linux-x86_64'"
113-
env:
114-
OUTPUT_DIR: "${{ github.workspace }}/bindist"
115161
run: |
116162
[ -e ./bindist/* ] && rm ./bindist/*
117163
./c/build_tools/python_deploy/write_requirements.py --version-suffix=${{ needs.setup_metadata.outputs.version_suffix }}
118164
./c/shark-ai/build_tools/build_linux_package.sh
119-
120165
- name: Build sharktank (Linux x86_64)
121166
if: "matrix.package == 'sharktank' && matrix.platform == 'linux-x86_64'"
122-
env:
123-
OUTPUT_DIR: "${{ github.workspace }}/bindist"
124167
run: |
125168
[ -e ./bindist/* ] && rm ./bindist/*
126169
./c/sharktank/build_tools/build_linux_package.sh
127-
128170
- name: Build shortfin (Linux x86_64, ${{ matrix.python-version }})
129171
if: "matrix.package == 'shortfin' && matrix.platform == 'linux-x86_64'"
130172
env:
131-
OUTPUT_DIR: "${{ github.workspace }}/bindist"
132173
OVERRIDE_PYTHON_VERSIONS: "${{ matrix.python-version }}"
133174
run: |
134175
[ -e ./bindist/* ] && rm ./bindist/*
135176
./c/shortfin/build_tools/build_linux_package.sh
136177
178+
# Always upload to GitHub artifacts.
137179
- name: Upload python wheels
138180
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
139181
with:
140182
if-no-files-found: error
141183
name: snapshot-${{ matrix.package }}-${{ matrix.platform }}-${{ matrix.python-version }}
142184
path: bindist
143-
144-
- name: Release python wheels
185+
# Upload release candidate versions to a 'dev-wheels' GitHub release.
186+
- name: Release rc python wheels
187+
if: ${{ inputs.build_type == 'rc' || inputs.build_type == '' }}
145188
uses: ncipollo/release-action@2c591bcc8ecdcd2db72b97d6147f871fcd833ba5 # v1.14.0
146189
with:
147190
artifacts: bindist/*.whl

0 commit comments

Comments
 (0)