-
Notifications
You must be signed in to change notification settings - Fork 2
71 lines (65 loc) · 2.14 KB
/
pypi-publish.yaml
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
64
65
66
67
68
69
70
71
name: PyPi Publish
on:
workflow_call:
inputs:
python_version:
required: false
type: string
default: '3.10'
package_name:
required: true
type: string
secrets:
pypi_key:
required: true
description: API token for access to PyPI
jobs:
version:
runs-on: ubuntu-latest
outputs:
local-version: ${{ steps.local-version.outputs.version }}
remote-version: ${{ steps.remote-version.outputs.version }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up Python Version
uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: |
pip install packaging
- id: local-version
run: echo "::set-output name=version::$(cat VERSION)"
- id: remote-version
run: echo "::set-output name=version::$(curl -s -o - 'https://pypi.org/pypi/${{ inputs.package_name }}/json' | jq -r '.releases|keys[-1]')"
- id: version-check
shell: python
env:
REMOTE_VERSION: ${{ steps.remote-version.outputs.version }}
LOCAL_VERSION: ${{ steps.local-version.outputs.version }}
run: |
import os
from packaging import version
local = version.parse(os.environ['LOCAL_VERSION'])
remote = version.parse(os.environ['REMOTE_VERSION'])
print(f"Local Version: {local}")
print(f"Remote Version: {remote}")
print(f"Requires Publish: {int(local > remote)}")
print(f"::set-output name=needs-publish::{int(local > remote)}")
publish-package:
runs-on: ubuntu-latest
needs:
- version
if: needs.version.outputs.needs-publish
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Set up Python Version
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python_version }}
- name: setup
run: make install-publish
- name: publish
run: make publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.pypi_key }}