Skip to content

Commit

Permalink
Update pipeline for pypi publish (#22)
Browse files Browse the repository at this point in the history
* update gitignore

* update build pipeline to push to pypi
  • Loading branch information
juaduan authored Feb 20, 2024
1 parent db20c09 commit a7ce2a6
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 54 deletions.
145 changes: 107 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,118 @@
name: publish_release
on:
push:
branches: [ "main" ]
name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

on: push

jobs:
release:
runs-on: ubuntu-latest
build:
name: Build distribution 📦
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python-version: [3.9, 3.10.8, 3.11]

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install pypa/build
run: >-
python3 -m pip install build --user
- name: Build a binary wheel and a source tarball
run: python3 -m build
- name: Store the distribution packages
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: dist/

publish-to-pypi:
name: >-
Publish Python 🐍 distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
needs:
- build
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/ms-anomaly-detector # Replace <package-name> with your PyPI project name
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

# - name: Set up Python
# uses: actions/setup-python@v5
# with:
# python-version: 3.11
github-release:
name: >-
Sign the Python 🐍 distribution 📦 with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
runs-on: ubuntu-latest

- name: Build project
run: |
pip install Cython
pip install numpy
python setup.py sdist bdist_wheel
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

- name: Create Draft Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
# TODO
tag_name: 0.1.0
release_name: 0.1.0
draft: true
prerelease: false

- name: Upload Release Asset
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/[email protected]
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/anomaly_detector-0.1.0-cp310-cp310-linux_x86_64.whl
asset_name: anomaly_detector-0.1.0-cp310-cp310-linux_x86_64.whl
asset_content_type: application/whl

- uses: eregon/publish-release@v1
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
run: >-
gh release create
'${{ github.ref_name }}'
--repo '${{ github.repository }}'
--notes ""
- name: Upload artifact signatures to GitHub Release
env:
GITHUB_TOKEN: ${{ github.token }}
# Upload to GitHub Release using the `gh` CLI.
# `dist/` contains the built packages, and the
# sigstore-produced signatures and certificates.
run: >-
gh release upload
'${{ github.ref_name }}' dist/**
--repo '${{ github.repository }}'
publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: test-release
url: https://test.pypi.org/p/ms-anomaly-detector

permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

steps:
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
release_id: ${{ steps.create_release.outputs.id }}
repository-url: https://test.pypi.org/legacy/
15 changes: 7 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main", "dev" ]
branches: ["main", "dev"]
pull_request:
branches: [ "main", "dev" ]
branches: ["main", "dev"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -21,8 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.9', '3.10.8', '3.11']

python-version: ["3.9", "3.10.8", "3.11"]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -36,14 +35,14 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}
cache: 'poetry'
cache: "poetry"

- name: install dependence
working-directory: anomaly-detector
run: |
poetry env use ${{matrix.python-version}}
poetry lock --no-update
poetry install
poetry install
- name: compile .pyx file
run: |
Expand All @@ -67,15 +66,15 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.9', '3.10.8', '3.11']
python-version: ["3.9", "3.10.8", "3.11"]
steps:
- uses: actions/checkout@v4

- name: setup python ${{matrix.python-version}}
uses: actions/setup-python@v4
with:
python-version: ${{matrix.python-version}}
cache: 'pip'
cache: "pip"

- name: gen .whl file by setup
run: |
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ model/
venv/
dist/
temp/

build/
anomaly_detector.egg-info/
anomaly-detector/anomaly_detector/univariate/_anomaly_kernel_cython.c
.idea/


Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Environment
python-version: '3.9', '3.10.8', '3.11'

Tested on

[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![Python 3.10](https://img.shields.io/badge/python-3.10.8-blue.svg)](https://www.python.org/downloads/release/python-3108/)
[![Python 3.11](https://img.shields.io/badge/python-3.11-blue.svg)](https://www.python.org/downloads/release/python-3110/)


# Getting Started

## Installing from pip
Expand Down
7 changes: 2 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ def run(self):
version="0.1.0",
license="MIT",
description="Anomaly Detection",
# long_description=long_description,
# long_description_content_type="text/markdown",
# entry_points={"console_scripts": [""]},
author="test",
author_email="anomaly_detector@microsoft.com",
author_email="ad-oss@microsoft.com",
url="https://github.com/microsoft/anomaly-detector",
data_files=[
(".", ["README.md"]),
Expand All @@ -97,6 +94,6 @@ def run(self):
"Intended Audience :: Developers",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.9",
],
)

0 comments on commit a7ce2a6

Please sign in to comment.