-
Notifications
You must be signed in to change notification settings - Fork 12
150 lines (127 loc) · 4.07 KB
/
publish-package.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: publish distributions
on:
push:
branches:
- main
tags:
- '[0-9]+.[0-9]+'
- '[0-9]+.[0-9]+.[0-9]+'
pull_request:
branches:
- main
release:
types: [published]
workflow_dispatch:
inputs:
publish:
type: choice
description: 'Publish to TestPyPI?'
options:
- false
- true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build_sdist:
name: Build Python distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install python-build and twine
run: |
python -m pip install --upgrade pip setuptools
python -m pip install build twine
python -m pip list
- name: Install dependencies
run: python -m pip install -r requirements-dev.txt
- name: Build an sdist
run: |
PYTHONWARNINGS=error,default::DeprecationWarning python -m build --sdist .
- name: Verify the distribution
run: twine check --strict dist/*
- name: List contents of sdist
run: python -m tarfile --list dist/ndindex-*.tar.gz
- name: Get sdist filename
run: echo "SDIST_FILE=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
- name: Upload distribution artifact
uses: actions/upload-artifact@v4
with:
name: dist-artifact
path: dist
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
needs: [build_sdist]
strategy:
matrix:
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
steps:
- uses: actions/checkout@v4
- name: Download distribution artifact
uses: actions/download-artifact@v4
with:
name: dist-artifact
path: dist
- name: Get sdist filename
run: echo "SDIST_FILE=$(ls dist/*.tar.gz)" >> $GITHUB_ENV
- name: Build wheels
uses: pypa/cibuildwheel@v2.21.0
with:
package-dir: ${{ env.SDIST_FILE }}
output-dir: dist/
env:
CIBW_TEST_COMMAND: >
python -c "import ndindex; assert '1.' in ndindex.__version__"
- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./dist/*.whl
publish:
name: Publish Python distribution to (Test)PyPI
if: github.event_name != 'pull_request' && github.repository == 'Quansight-Labs/ndindex'
needs: [build_sdist, build_wheels]
runs-on: ubuntu-latest
# Mandatory for publishing with a trusted publisher
# c.f. https://docs.pypi.org/trusted-publishers/using-a-publisher/
permissions:
id-token: write
contents: write
# Restrict to the environment set for the trusted publisher
environment:
name: publish-package
steps:
- name: Download distribution artifact
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true
- name: List all files
run: ls -lh dist
- name: Publish distribution 📦 to Test PyPI
# Publish to TestPyPI on tag events of if manually triggered
# Compare to 'true' string as booleans get turned into strings in the console
if: >-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags'))
|| (github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true')
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
repository-url: https://test.pypi.org/legacy/
print-hash: true
- name: Create GitHub Release from a Tag
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*
- name: Publish distribution 📦 to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@v1.8.11
with:
print-hash: true