Skip to content

Commit

Permalink
Updated yaml file
Browse files Browse the repository at this point in the history
  • Loading branch information
EdgarHarutyunian committed Feb 7, 2025
1 parent bb2feee commit 0035e2c
Showing 1 changed file with 109 additions and 94 deletions.
203 changes: 109 additions & 94 deletions .github/workflows/build-laplaciannb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,119 +2,134 @@ name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI

## from packaging tutorial: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/

on: push
# Trigger the workflow on push to a tag (used for releases)
on:
push:
tags:
- "v*" # Push events to matching v*, like v1.0, v20.15.10

jobs:
build:
name: Build distribution 📦
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install pdm
run: >-
python3 -m
pip install
pdm
--user
- name: Build a binary wheel and a source tarball
run: pdm build
- name: Store the distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
# Step 1: Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4

# Step 2: Set up Python
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

# Step 3: Install pdm
- name: Install pdm
run: python3 -m pip install --upgrade pip pdm

# Step 4: Build a binary wheel and a source tarball
- name: Build a binary wheel and a source tarball
run: pdm build

# Step 5: Validate the distribution
- name: Validate the distribution
run: python3 -m twine check dist/*

# Step 6: Store the distribution artifacts for later use
- name: Store the distribution artifacts
uses: actions/upload-artifact@v4
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
name: Publish Python 🐍 distribution 📦 to PyPI
needs: build
runs-on: ubuntu-latest
if: "! contains(github.ref_name, '-')" # Only run for stable tags (no '-' in tag name)
environment:
name: pypi
url: https://pypi.org/p/laplaciannb # 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@v4
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

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

url: https://pypi.org/project/laplaciannb/
permissions:
contents: write # IMPORTANT: mandatory for making GitHub Releases
id-token: write # IMPORTANT: mandatory for sigstore

id-token: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Sign the dists with Sigstore
uses: sigstore/gh-action-sigstore-python@v3.0.0
with:
inputs: >-
./dist/*.tar.gz
./dist/*.whl
- name: Create GitHub Release
env:
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 }}'
# Step 1: Download the distribution artifacts
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

# Step 2: Publish distribution 📦 to PyPI
- name: Publish distribution 📦 to PyPI
env:
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
run: python3 -m twine upload --non-interactive --repository-url https://upload.pypi.org/legacy/ dist/*

publish-to-testpypi:
name: Publish Python 🐍 distribution 📦 to TestPyPI
needs:
- build
needs: build
runs-on: ubuntu-latest

if: contains(github.ref_name, '-') # Only run for beta tags (contains '-' in tag name)
environment:
name: testpypi
url: https://test.pypi.org/p/laplaciannb

url: https://test.pypi.org/project/laplaciannb/
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

id-token: write
steps:
# Step 1: Download the distribution artifacts
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

# Step 2: Publish distribution 📦 to TestPyPI
- name: Publish distribution 📦 to TestPyPI
env:
TEST_PYPI_TOKEN: ${{ secrets.TEST_PYPI_API_TOKEN }}
run: python3 -m twine upload --non-interactive --repository-url https://test.pypi.org/legacy/ dist/*

# Step 3: Validate after publishing to TestPyPI
- name: Install from TestPyPI
run: python3 -m pip install --index-url https://test.pypi.org/simple/ laplaciannb

github-release:
name: Create a GitHub release
needs: build
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Download all the dists
uses: actions/download-artifact@v4
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/
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
# Step 1: Checkout the repository
- name: Checkout the repository
uses: actions/checkout@v4

# Step 2: Download the distribution artifacts
- name: Download all the dists
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/

# Step 3: Create a GitHub release
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: |
## Chnages in this Release
- This is the automatically generated release notes.
draft: false
prerelease: ${{ contains(github.ref_name, '-') }} # Set to true for beta releases

# Step 4: Attach the distribution artifacts to the GitHub release
- name: Attach the distribution artifacts to the GitHub release
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./dist/*
asset_name: $(basename $file)
asset_content_type: application/octet-stream

0 comments on commit 0035e2c

Please sign in to comment.