-
Notifications
You must be signed in to change notification settings - Fork 81
115 lines (103 loc) · 2.9 KB
/
build_pypi.yml
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: "Build PYPI"
on:
workflow_call:
inputs:
version:
description: 'Version'
type: string
required: true
ref:
description: 'Ref'
type: string
required: true
upload_to_pypi:
description: "Upload to PyPi"
type: boolean
required: false
release-id:
description: "Attach Artifact to Release"
type: string
required: false
workflow_dispatch:
inputs:
version:
description: 'Version'
type: string
required: true
ref:
description: 'Ref'
type: string
required: true
upload_to_pypi:
description: "Upload to PyPi"
type: boolean
default: false
required: false
release-id:
description: "Attach Artifact to Release"
type: string
required: false
env:
PYTHON_VERSION_FILE: "pyproject.toml"
jobs:
ReleaseNotification:
name: "PyPI"
runs-on: ubuntu-latest
steps:
- uses: hmarr/[email protected]
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Manage version
env:
PROVIDED_VERSION: ${{ inputs.version }}
run: |
set -x
version=$(sed "s/^v//g" <<< ${PROVIDED_VERSION})
sed -i "s/^version[ ]*=.*/version = \"${version}\"/g" ${{ env.PYTHON_VERSION_FILE }}
- name: "Install poetry"
run: pipx install poetry
- name: "Set up Python"
id: setup_python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- name: Install dependencies
run: |
poetry install --without dev
- name: Package
run: poetry build
- name: Upload to PYPI
if: inputs.upload_to_pypi
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_APIKEY }}
run: |
poetry config pypi-token.pypi "${POETRY_PYPI_TOKEN_PYPI}"
poetry publish --no-interaction
- name: Attach artifacts to release
if: inputs.release-id
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GIT_PAT }}
script: |
const { repo, owner } = context.repo;
const fs = require('fs');
const release_id = '${{ inputs.release-id }}';
for (let file of await fs.readdirSync('./dist/')) {
console.log('uploadReleaseAsset', file);
await github.rest.repos.uploadReleaseAsset({
owner,
repo,
release_id: release_id,
name: file,
data: await fs.readFileSync(`./dist/${file}`)
});
}
- name: Upload to artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: Dist
path: dist/