Skip to content

Commit

Permalink
Add build workflows for dev, nightly, and release wheels (#2182)
Browse files Browse the repository at this point in the history
* sparseml pypi workflows

* oops, forgot to update package name

* quality
  • Loading branch information
dsikka authored Mar 14, 2024
1 parent 965bdfa commit 749e27c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/build-wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build PyPi Wheel
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
- 'release/[0-9]+.[0-9]+'
push:
branches:
- main
release:
types: [created, published]
schedule:
- cron: '0 0 * * *'

permissions:
id-token: write
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

# if not dev or release, will create a nightly build
# everything is pushed to internal unless created through a nightly scheduled cron job which creates the build or
# missing release tag workflow/needs to be added in
env:
INTERNAL: ${{ github.event_name != 'schedule' && github.event_name != 'release'}}
RELEASE: ${{ github.event_name =='release' || (startsWith(github.base_ref, 'release/') && github.event_name == 'pull_request')}}
DEV: ${{ github.base_ref == 'main' && github.event_name == 'pull_request'}}
NAME: ${{ github.event.number }}

jobs:
build_and_push:
runs-on: ubuntu-latest
outputs:
wheel: ${{ steps.push-wheel.outputs.wheel }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Login to s3
uses: aws-actions/configure-aws-credentials@v2
with:
role-to-assume: ${{ secrets.AWS_WEBIDENTITY_FOR_GITHUB_ACTIONS }}
aws-region: us-east-1
- name: Build PyPi Wheel
id: build-wheel
uses: neuralmagic/nm-actions/actions/pypi_build@main
with:
dev: $DEV
release: $RELEASE
name: $NAME
- name: Push to s3 bucket
id: push-wheel
uses: neuralmagic/nm-actions/actions/s3_push@main
with:
filename: dist/*.whl
internal: $INTERNAL
8 changes: 7 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# default variables to be overwritten by the version.py file
is_release = None
is_dev = None
version = "unknown"
version_major_minor = version

Expand All @@ -28,7 +29,12 @@
print(f"loaded version {version} from src/sparseml/version.py")
version_nm_deps = f"{version_major_minor}.0"

_PACKAGE_NAME = "sparseml" if is_release else "sparseml-nightly"
if is_release:
_PACKAGE_NAME = "sparseml"
elif is_dev:
_PACKAGE_NAME = "sparseml-dev"
else:
_PACKAGE_NAME = "sparseml-nightly"

_deps = [
"setuptools<=59.5.0",
Expand Down
13 changes: 8 additions & 5 deletions src/sparseml/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@

version_base = "1.7.0"
is_release = False # change to True to set the generated version as a release version
is_dev = False
dev_number = None


def _generate_version():
return (
version_base
if is_release
else f"{version_base}.{date.today().strftime('%Y%m%d')}"
)
if is_release:
return version_base
elif is_dev:
return f"{version_base}.dev{dev_number}"
else:
return f"{version_base}.{date.today().strftime('%Y%m%d')}"


__all__ = [
Expand Down

0 comments on commit 749e27c

Please sign in to comment.