Skip to content

Commit

Permalink
refine build and release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
juaduan committed Mar 29, 2024
1 parent 1fb3ba6 commit c996ec8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 939 deletions.
80 changes: 22 additions & 58 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,63 +10,27 @@ on:
required: true

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

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine cython numpy
- name: Build a binary wheel and a source tarball
run: |
python setup.py bdist_wheel sdist
- name: Rename wheel for manylinux compatibility (Ubuntu only)
if: runner.os == 'ubuntu-latest'
run: |
for file in *.whl; do
if [[ $file == *linux* ]]; then
mv "$file" "${file/-linux/-manylinux1}"
fi
done
- name: Publish artifacts
uses: actions/upload-artifact@v2
with:
name: dist
path: dist/

release:
needs: build
build_and_release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: dist
path: dist/

- name: Publish to GitHub Releases
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_KEY }}
run: >-
pwd && ls -lh && ls -lh dist/ &&
gh release create ${{ github.ref_name }} ./dist/*
"release binary and source artifacts"
--generate-notes
--title "Version ${{ github.ref_name }}"
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.10.8

- name: Install dependencies
run: pip install --upgrade setuptools wheel twine

- name: Build source distribution
run: python setup.py sdist

- name: Create release and upload distribution
uses: softprops/action-gh-release@v1
with:
files: dist/*
tag_name: v${{ github.ref }}
title: Release ${{ github.ref }}
body: ${{ github.event.pull_request.body }}
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,27 @@ jobs:
with:
python-version: "3.x"
- name: Install pypa/build
run: >-
python3 -m
pip install
build
--user
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
- name: Build a binary wheel and a source tarball
run: python3 -m build
run: python3 -m setup.py sdist
- 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
publish-to-testpypi:
name: Publish Python 🐍 distribution πŸ“¦ to TestPyPI
needs:
- build
runs-on: ubuntu-latest

environment:
name: pypi
url: https://pypi.org/p/<package-name> # Replace <package-name> with your PyPI project name
name: testpypi
url: https://test.pypi.org/p/anomaly-detector

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

Expand All @@ -46,15 +44,17 @@ jobs:
with:
name: python-package-distributions
path: dist/
- name: Publish distribution πŸ“¦ to PyPI
- name: Publish distribution πŸ“¦ to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/

github-release:
name: >-
Sign the Python 🐍 distribution πŸ“¦ with Sigstore
and upload them to GitHub Release
needs:
- publish-to-pypi
- publish-to-testpypi
runs-on: ubuntu-latest

permissions:
Expand Down Expand Up @@ -90,28 +90,4 @@ jobs:
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: testpypi
url: https://test.pypi.org/p/<package-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 TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
--repo '${{ github.repository }}'
Loading

0 comments on commit c996ec8

Please sign in to comment.