[WIP] APIv4 server #272
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: package-server | |
on: | |
workflow_call: | |
inputs: | |
version: | |
description: The version to use | |
type: string | |
required: true | |
# PS: If you trigger manually the packaging, take into account that it will use the workflow as defined in the main branch not in the target branch. | |
workflow_dispatch: | |
inputs: | |
version: | |
description: The version to use (if not provided will generated one from the code space version) | |
type: string | |
required: false | |
pull_request: | |
paths: | |
- .github/workflows/package-server.yml | |
- server/packaging | |
- server/build.py | |
- server/pyproject.toml | |
# We set `concurrency` to prevent having this workflow being run on code that is not up-to-date on a PR (a user make multiple push in a quick manner). | |
# But on the main branch, we don't want that behavior. | |
# Having the workflow run on each merge commit is something we would like, that could help us where a regression was made and missed by previous checks. | |
# | |
# For that we use `head_ref` that is only defined on `pull-request` and fallback to `run_id` (this is a counter, so it's value is unique between workflow call). | |
concurrency: | |
group: package-server-${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
cancel-in-progress: true | |
env: | |
node-version: 18.12.0 | |
poetry-version: 1.5.1 | |
permissions: | |
contents: read | |
jobs: | |
package-wheel: | |
strategy: | |
fail-fast: false | |
matrix: | |
include: | |
- name: 🐧 Linux | |
platform: linux | |
os: ubuntu-22.04 | |
- name: 🍎 macOS | |
platform: macos | |
os: macos-12 | |
- name: 🏁 Windows | |
platform: windows | |
os: windows-2022 | |
name: "${{ matrix.name }}: 📦 Packaging (build Wheel)" | |
runs-on: ${{ matrix.os }} | |
outputs: | |
wheel-version: ${{ steps.version.outputs.full }} | |
steps: | |
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin v4.1.1 | |
timeout-minutes: 5 | |
- uses: ./.github/actions/setup-python-poetry | |
with: | |
poetry-version: ${{ env.poetry-version }} | |
project-path: ./server | |
timeout-minutes: 10 | |
- name: Get wheel version | |
id: version | |
shell: bash | |
run: | | |
set -eux | |
function parse_version { | |
PYTHONPATH=. python3 misc/releaser.py version "$@" | |
} | |
if [ -n "${{ inputs.version }}" ]; then | |
parse_version "${{ inputs.version }}" | tee -a $GITHUB_OUTPUT | |
else | |
case "${{ github.event_name }}" in | |
workflow_call) | |
echo "The top workflow should have provided the version to use" | |
exit 2 | |
;; | |
workflow_dispatch) | |
# No version provided, fallback to the version in the repository | |
parse_version --uniq-dev | tee -a $GITHUB_OUTPUT | |
;; | |
pull_request) | |
parse_version --uniq-dev | tee -a $GITHUB_OUTPUT | |
;; | |
*) | |
echo 'Unsupported event type ${{ github.event_name }}' >&2 | |
exit 1 | |
;; | |
esac | |
fi | |
- name: Set parsec version ${{ steps.version.outputs.full }} | |
run: python3 misc/version_updater.py --tool parsec --version ${{ steps.version.outputs.full }} | |
- name: Build wheel | |
uses: pypa/cibuildwheel@fff9ec32ed25a9c576750c91e06b410ed0c15db7 # pin v2.16.2 | |
with: | |
package-dir: server | |
output-dir: dist | |
timeout-minutes: 50 | |
- name: Set file for wheel version | |
run: echo ${{ steps.version.outputs.full }} > dist/version | |
- name: Hack the wheel macos version | |
if: startsWith(matrix.os, 'macos-') | |
shell: bash | |
run: | | |
set -eux | |
# Old wheel name | |
OLD_WHEEL_NAME=$(basename dist/parsec_cloud-*.whl) | |
# Unzip the wheel | |
mkdir temp | |
cd temp | |
unzip ../dist/$OLD_WHEEL_NAME | |
# Get platform new wheel name | |
python -m pip install wheel | |
PLATFORM=$(python -c "from wheel.bdist_wheel import get_platform; print(get_platform('.'))") | |
NEW_WHEEL_NAME=$(basename ../dist/parsec_cloud-*.whl | sed "s/macosx_.*_x86_64/$PLATFORM/") | |
# Update archive and zip back | |
sed -i "" "s/macosx_.*_x86_64/$PLATFORM/" parsec_cloud-*.dist-info/WHEEL | |
zip -r $NEW_WHEEL_NAME * | |
cd .. | |
# Replace old wheel with the new one | |
mv temp/$NEW_WHEEL_NAME dist/ | |
rm dist/$OLD_WHEEL_NAME | |
rm -rf temp | |
- name: Generate requirements & constraints infos | |
run: python server/packaging/wheel/wheel_it.py ./server --output dist --skip-wheel | |
# Install syft | |
- uses: taiki-e/install-action@4d8504289abd3a644c6237dea6005f9f28fba01b # pin v2.21.11 | |
with: | |
tool: [email protected] | |
- name: Generate SBOM | |
run: syft packages --config=.syft.yaml --output=spdx-json=dist/Parsec-SBOM-Wheel-${{ matrix.platform }}.spdx.json . | |
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # pin v3.1.3 | |
with: | |
name: ${{ runner.os }}-${{ runner.arch }}-wheel | |
path: | | |
dist/ | |
if-no-files-found: error | |
timeout-minutes: 5 |