-
Notifications
You must be signed in to change notification settings - Fork 14
150 lines (147 loc) · 6.73 KB
/
publish_pure_python.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
name: Build and publish pure Python package
on:
workflow_call:
inputs:
test_extras:
description: Any extras_requires modifier that should be used to install the package for testing
required: false
default: ''
type: string
test_command:
description: The command to run to test the package (will be run in a temporary directory)
required: false
default: ''
type: string
env:
description: A map of environment variables to be available when building and testing
required: false
default: ''
type: string
libraries:
description: Packages needed to build the source distribution for testing (installed using apt)
required: false
default: ''
type: string
runs-on:
description: Which runner image to use to build and test the sdist and wheel
required: false
default: 'ubuntu-latest'
type: string
upload_to_pypi:
description: A condition specifying whether to upload to PyPI
required: false
default: 'refs/tags/v'
type: string
repository_url:
description: The PyPI repository URL to use
required: false
default: ''
type: string
upload_to_anaconda:
description: A condition specifying whether to upload to Anaconda.org
required: false
default: false
type: boolean
anaconda_user:
description: Anaconda.org user or organisation
required: false
default: ''
type: string
anaconda_package:
description: Anaconda.org package name
required: false
default: ''
type: string
anaconda_keep_n_latest:
description: If specified, only this number of the most recent versions are kept
required: false
default: -1
type: number
timeout-minutes:
description: The maximum number of minutes to let the workflow run before GitHub automatically cancels it
required: false
default: 360
type: number
submodules:
description: Whether to checkout submodules
required: false
default: true
type: boolean
python-version:
description: The Python version to use for building and testing
required: false
default: '3.x'
type: string
checkout_ref:
description: The ref to checkout
required: false
default: ''
type: string
secrets:
pypi_token:
required: false
anaconda_token:
required: false
jobs:
build:
name: Build source and wheel distribution
runs-on: ${{ inputs.runs-on }}
timeout-minutes: ${{ inputs.timeout-minutes }}
steps:
- uses: actions/setup-python@v5
if: ${{ inputs.env != '' }}
with:
python-version: '3.12'
- id: set-env
if: ${{ inputs.env != '' }}
run: |
python -m pip install PyYAML
echo $SET_ENV_SCRIPT | base64 --decode > set_env.py
python set_env.py "${{ inputs.env }}"
rm set_env.py
shell: sh
env:
SET_ENV_SCRIPT: aW1wb3J0IGpzb24KaW1wb3J0IG9zCmltcG9ydCBzeXMKCmltcG9ydCB5YW1sCgpHSVRIVUJfRU5WID0gb3MuZ2V0ZW52KCJHSVRIVUJfRU5WIikKaWYgR0lUSFVCX0VOViBpcyBOb25lOgogICAgcmFpc2UgVmFsdWVFcnJvcigiR0lUSFVCX0VOViBub3Qgc2V0LiBNdXN0IGJlIHJ1biBpbnNpZGUgR2l0SHViIEFjdGlvbnMuIikKCkRFTElNSVRFUiA9ICJFT0YiCgoKZGVmIHNldF9lbnYoZW52KToKCiAgICBlbnYgPSB5YW1sLmxvYWQoZW52LCBMb2FkZXI9eWFtbC5CYXNlTG9hZGVyKQogICAgcHJpbnQoanNvbi5kdW1wcyhlbnYsIGluZGVudD0yKSkKCiAgICBpZiBub3QgaXNpbnN0YW5jZShlbnYsIGRpY3QpOgogICAgICAgIHRpdGxlID0gImBlbnZgIG11c3QgYmUgbWFwcGluZyIKICAgICAgICBtZXNzYWdlID0gZiJgZW52YCBtdXN0IGJlIG1hcHBpbmcgb2YgZW52IHZhcmlhYmxlcyB0byB2YWx1ZXMsIGdvdCB0eXBlIHt0eXBlKGVudil9IgogICAgICAgIHByaW50KGYiOjplcnJvciB0aXRsZT17dGl0bGV9Ojp7bWVzc2FnZX0iKQogICAgICAgIGV4aXQoMSkKCiAgICBmb3IgaywgdiBpbiBlbnYuaXRlbXMoKToKCiAgICAgICAgaWYgbm90IGlzaW5zdGFuY2Uodiwgc3RyKToKICAgICAgICAgICAgdGl0bGUgPSAiYGVudmAgdmFsdWVzIG11c3QgYmUgc3RyaW5ncyIKICAgICAgICAgICAgbWVzc2FnZSA9IGYiYGVudmAgdmFsdWVzIG11c3QgYmUgc3RyaW5ncywgYnV0IHZhbHVlIG9mIHtrfSBoYXMgdHlwZSB7dHlwZSh2KX0iCiAgICAgICAgICAgIHByaW50KGYiOjplcnJvciB0aXRsZT17dGl0bGV9Ojp7bWVzc2FnZX0iKQogICAgICAgICAgICBleGl0KDEpCgogICAgICAgIHYgPSB2LnNwbGl0KCJcbiIpCgogICAgICAgIHdpdGggb3BlbihHSVRIVUJfRU5WLCAiYSIpIGFzIGY6CiAgICAgICAgICAgIGlmIGxlbih2KSA9PSAxOgogICAgICAgICAgICAgICAgZi53cml0ZShmIntrfT17dlswXX1cbiIpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBmb3IgbGluZSBpbiB2OgogICAgICAgICAgICAgICAgICAgIGFzc2VydCBsaW5lLnN0cmlwKCkgIT0gREVMSU1JVEVSCiAgICAgICAgICAgICAgICBmLndyaXRlKGYie2t9PDx7REVMSU1JVEVSfVxuIikKICAgICAgICAgICAgICAgIGZvciBsaW5lIGluIHY6CiAgICAgICAgICAgICAgICAgICAgZi53cml0ZShmIntsaW5lfVxuIikKICAgICAgICAgICAgICAgIGYud3JpdGUoZiJ7REVMSU1JVEVSfVxuIikKCiAgICAgICAgcHJpbnQoZiJ7a30gd3JpdHRlbiB0byBHSVRIVUJfRU5WIikKCgppZiBfX25hbWVfXyA9PSAiX19tYWluX18iOgogICAgc2V0X2VudihzeXMuYXJndlsxXSkK
- uses: actions/checkout@v4
with:
fetch-depth: 0
lfs: true
submodules: ${{ inputs.submodules }}
ref: ${{ inputs.checkout_ref }}
- name: Install dependencies
if: ${{ inputs.libraries != '' }}
uses: ConorMacBride/install-package@main
with:
apt: ${{ inputs.libraries }}
- id: build
uses: OpenAstronomy/build-python-dist@main
with:
test_extras: ${{ inputs.test_extras }}
test_command: ${{ inputs.test_command }}
python-version: ${{ inputs.python-version }}
pure_python_wheel: true
- id: set-upload
run: |
if [ $UPLOAD_TO_PYPI == "true" ] || [ $UPLOAD_TAG == "true" ];
then
echo "upload_to_pypi=true" >> $GITHUB_OUTPUT
else
echo "upload_to_pypi=false" >> $GITHUB_OUTPUT
fi
env:
UPLOAD_TO_PYPI: ${{ inputs.upload_to_pypi }}
UPLOAD_TAG: ${{ startsWith(inputs.upload_to_pypi, 'refs/tags/') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || github.event_name == 'release' || github.event_name == 'create') && startsWith(github.ref, inputs.upload_to_pypi) }}
- uses: pypa/gh-action-pypi-publish@release/v1
name: Upload to PyPI
if: ${{ steps.set-upload.outputs.upload_to_pypi == 'true' }}
with:
user: __token__
password: ${{ secrets.pypi_token }}
repository-url: ${{ inputs.repository_url }}
- uses: OpenAstronomy/publish-wheels-anaconda@main
if: ${{ inputs.upload_to_anaconda }}
with:
anaconda_user: ${{ inputs.anaconda_user }}
anaconda_package: ${{ inputs.anaconda_package }}
anaconda_token: ${{ secrets.anaconda_token }}
keep_n_latest: ${{ inputs.anaconda_keep_n_latest }}