-
Notifications
You must be signed in to change notification settings - Fork 13
63 lines (56 loc) · 1.71 KB
/
pypi-package.yaml
File metadata and controls
63 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
name: Build and Publish Python Package
on:
workflow_dispatch:
inputs:
version:
description: "Version to use for the Python package (e.g. 0.1.0)"
required: true
type: string
test-pypi:
description: "Publish to Test PyPI"
required: false
type: boolean
default: false
release:
types: [published]
jobs:
build-and-publish:
runs-on: ubuntu-latest
permissions:
id-token: write # mandatory for Pypi trusted publishing
contents: read
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- name: Install build dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install .[dev]
- name: Get version
id: get_version
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
VERSION="${{ github.event.release.tag_name }}"
else
VERSION="${{ github.event.inputs.version }}"
fi
VERSION=${VERSION#v}
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build
env:
VERSION: ${{ steps.get_version.outputs.version }}
run: |
python -m build --wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist
verbose: true
# Avoid workflow to fail if the version has already been published
skip-existing: true
# Upload to Test Pypi for testing
repository-url: ${{ github.event.inputs.test-pypi == 'true' && 'https://test.pypi.org/legacy/' || '' }}