Skip to content

Commit

Permalink
Merge pull request #8032 from OpenMined/setup-syftcli-binary-release
Browse files Browse the repository at this point in the history
setup for syftcli binary release
  • Loading branch information
rasswanth-s authored Aug 29, 2023
2 parents df0d070 + 4f25327 commit 7592297
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/cd-syftcli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ jobs:
if: always() && (needs.call-pr-tests-linting.result == 'success' || github.event.inputs.skip_tests == 'true')
runs-on: ubuntu-latest

outputs:
deployed_version: ${{ steps.bump-version.outputs.deployed_version }}
current_hash: ${{ steps.get-hashes.outputs.current_hash }}
previous_hash: ${{ steps.get-hashes.outputs.previous_hash }}

steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -65,10 +70,12 @@ jobs:
- name: Bump the Version
if: ${{steps.get-hashes.outputs.current_hash != steps.get-hashes.outputs.previous_hash }}
id: bump-version
run: |
python3 src/syftcli/version.py
bump2version patch --allow-dirty --no-commit
tox -e lint || true
echo "deployed_version=$(python3 src/syftcli/version.py)" >> $GITHUB_OUTPUT
python3 src/syftcli/version.py
working-directory: ./packages/syftcli

Expand All @@ -94,3 +101,92 @@ jobs:
run: |
tox -e syftcli.publish
twine upload packages/syftcli/dist/*
create-syftcli-binaries:
needs: [deploy-syft-cli]
if: always() && (needs.deploy-syft-cli.result == 'success' && ${{needs.deploy-syft-cli.outputs.current_hash != needs.deploy-syft-cli.outputs.previous_hash }})
strategy:
max-parallel: 99
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
fail-fast: true
runs-on: ${{matrix.os}}

steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.SYFT_BUMP_TOKEN }}

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"

- name: Install build dependencies for syftcli
run: |
pip install --upgrade pip
- name: Install Tox
run: |
pip install -U tox
- name: Build syftcli
env:
SYFT_CLI_VERSION: ${{ needs.deploy-syft-cli.outputs.deployed_version }}
run: |
tox -e syftcli.build
- name: upload binaries
uses: actions/upload-artifact@v3
with:
name: syftcli-binaries-${{needs.deploy-syft-cli.outputs.deployed_version}}
path: ./packages/syftcli/dist/cli/*
if-no-files-found: error

create-syftcli-github-release:
needs: [create-syftcli-binaries]
if: always() && (needs.create-syftcli-binaries.result == 'success')
runs-on: ubuntu-latest
permissions:
contents: write # For tag and release notes.

steps:
- uses: actions/checkout@v3
with:
token: ${{ secrets.SYFT_BUMP_TOKEN }}

- name: Check if version is released on Pypi
id: check-pypi
run: |
VERSION=${{needs.deploy-syft-cli.outputs.deployed_version}}
RESPONSE=$(curl -s --head https://pypi.org/pypi/syftcli/$VERSION/json)
if [[ $RESPONSE == *"HTTP/2 200"* ]]; then
echo "released=true" >> $GITHUB_OUTPUT
else
echo "released=false" >> $GITHUB_OUTPUT
fi
- name: Make sure directory exists
if: steps.check-pypi.outputs.released == 'true'
run: |
mkdir -p ./downloaded-binaries
- name: Download binary
if: steps.check-pypi.outputs.released == 'true'
uses: actions/download-artifact@v3
with:
name: syftcli-binaries-${{needs.deploy-syft-cli.outputs.deployed_version}}
path: ./downloaded-binaries/

- name: GitHub Release
if: steps.check-pypi.outputs.released == 'true'
uses: softprops/action-gh-release@v1
with:
name: syftcli-v${{ needs.deploy-syft-cli.outputs.deployed_version }}
generate_release_notes: false
prerelease: false
files: |
./downloaded-binaries/*
tag_name: syftcli-v${{ needs.deploy-syft-cli.outputs.deployed_version }}
46 changes: 46 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ envlist =
syft.test.helm
syftcli.test.unit
syftcli.publish
syftcli.build
skipsdist = True

[testenv]
Expand Down Expand Up @@ -80,6 +81,51 @@ commands =
python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)'
python -m build .

[testenv:syftcli.build]
basepython = python3
changedir = {toxinidir}/packages/syftcli
description = Build SyftCLI Binary for each platform
allowlist_externals =
bash
setenv =
SYFT_CLI_VERSION = {env:SYFT_CLI_VERSION}
commands =
python -m pip install --upgrade pip
pip install -e ".[build]"
python -c 'from shutil import rmtree; rmtree("build", True); rmtree("dist", True)'


;Since we build universal binary for MacOS,we need to check the python is universal2 or not
bash -c 'if [[ "$OSTYPE" == "darwin"* ]]; then \
arch_info=$(lipo -info "$(which python3)"); \
echo "Arch: $arch_info"; \
if [[ "$arch_info" == *"Non-fat"* ]]; then \
echo "Building on MacOS Requires Universal2 python"; \
echo "Please install universal2 python from https://www.python.org/downloads/macos/"; \
exit 1; \
fi; \
fi'

;check the platform and build accordingly by naming the binary as syftcli plus the extension
; Check if SYFT_CLI_VERSION is set or choosing the current version available
bash -c 'if [ -z $SYFT_CLI_VERSION ]; then \
echo "SYFT_CLI_VERSION is not set"; \
SYFT_CLI_VERSION=$(python3 src/syftcli/version.py); \
echo "Setting SYFT_CLI_VERSION to $SYFT_CLI_VERSION"; \
else \
echo "SYFT_CLI_VERSION is already set to $SYFT_CLI_VERSION"; \
fi && \
echo "Building syftcli-$SYFT_CLI_VERSION for $OSTYPE" && \
if [[ "$OSTYPE" == "darwin"* ]]; then \
pyinstaller --clean --onefile --name syftcli-$SYFT_CLI_VERSION-macos-universal2 --distpath ./dist/cli src/syftcli/cli.py --target-arch universal2; \
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then \
pyinstaller --clean --onefile --name syftcli-$SYFT_CLI_VERSION-linux-x86_64 --distpath ./dist/cli src/syftcli/cli.py; \
else \
pyinstaller --clean --onefile --name syftcli-$SYFT_CLI_VERSION-windows-x86_64 --distpath ./dist/cli src/syftcli/cli.py; \
fi'


[testenv:lint]
description = Linting
Expand Down

0 comments on commit 7592297

Please sign in to comment.