Skip to content

Commit

Permalink
Update pyproject.toml to dynamically version based on git
Browse files Browse the repository at this point in the history
Add this repo to trusted publishers on testpypi. Build package only once

Update publish.yml

Remove outputs, use trusted publisher for pypi

Fixed dist path

Add checkout code back in
  • Loading branch information
kirilklein committed Sep 30, 2024
1 parent de78cf9 commit bd588d0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 12 deletions.
56 changes: 46 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
name: Publish to PyPI
name: Publish to TestPyPI and PyPI

on:
push:
tags:
- 'v*.*.*'
- "v*.*.*"

jobs:
publish:
build:
name: Build package
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Install build tools
run: |
python -m pip install --upgrade pip setuptools wheel setuptools-scm
python -m pip install --upgrade pip setuptools wheel setuptools-scm build
- name: Build package
run: python -m build
run: |
python -m build
- name: Publish to PyPI
- name: Upload package to GitHub artifacts
uses: actions/upload-artifact@v4
with:
name: python-package-distribution
path: dist/

testpypi-publish:
name: Publish to TestPyPI
runs-on: ubuntu-latest
needs: build
permissions:
id-token: write
steps:
- name: Download package from build job
uses: actions/download-artifact@v4
with:
name: python-package-distribution
path: dist/

- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
repository-url: https://test.pypi.org/legacy/

pypi-publish:
name: Publish to PyPI
runs-on: ubuntu-latest
needs: testpypi-publish # Only run after TestPyPI succeeds
permissions:
id-token: write
steps:
- name: Download package from build job
uses: actions/download-artifact@v4
with:
name: python-package-distribution
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1


6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "CausalEstimate"
version = "0.1.3"
dynamic = ["version"]
description = "A library for estimates of causal effects."
readme = { file = "README.md", content-type = "text/markdown" } # Combine file and content-type
authors = [
Expand Down Expand Up @@ -40,9 +40,11 @@ plotting = [
"seaborn",
"plotly",
]
[tool.setuptools_scm]
write_to = "CausalEstimate/_version.py"
[tool.setuptools.packages.find]
include = ["CausalEstimate"]
exclude = ["notebooks", "tests"]
# Add your project URLs here
[project.urls]
"Source" = "https://github.com/kirilklein/CausalEstimate.git"
"Source" = "https://github.com/kirilklein/CausalEstimate.git"

0 comments on commit bd588d0

Please sign in to comment.