-
Notifications
You must be signed in to change notification settings - Fork 27
177 lines (170 loc) · 7.15 KB
/
build.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
name: build
on:
pull_request:
push:
branches:
- '**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
jobs:
prepare-build-info:
if: true
name: Prepare Build Information
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Obtain tag name (if set), version, and human readable name
id: got-tag
run: |
git tag --format='%(refname:strip=2)%09%(objectname:short)%09%(creatordate:short)%09%(authorname)%09%(subject)' --sort=-creatordate
echo "tagname=`git tag --points-at ${{ github.sha }} | head -n 1`" >> "$GITHUB_OUTPUT"
echo "anyname=`git describe --abbrev=0 --tags --always ${{ github.sha }} | head -n 1`" >> "$GITHUB_OUTPUT"
echo "anyversion=`git describe --abbrev=0 --tags --always ${{ github.sha }} | head -n 1 | sed 's/^v//'`" >> "$GITHUB_OUTPUT"
- name: Do not break process if obtained `anyversion` is valid
run: |
re='^([0-9]+\.)([0-9]+\.)([0-9]+)(-(dev|prod))?$'
if ! [[ "${{ steps.got-tag.outputs.anyversion }}" =~ $re ]] ; then
echo "Error: Incorrect version obtained from git tag; must be in the format of '#.#.#' (for git tag 'v#.#.#'): ${{ steps.got-tag.outputs.anyversion }}" >&2; exit 1
else
echo "Obtained version from git tag: ${{ steps.got-tag.outputs.anyversion }}"
fi
outputs:
tagname: ${{ steps.got-tag.outputs.tagname }}
anyname: ${{ steps.got-tag.outputs.anyname }}
anyversion: ${{ steps.got-tag.outputs.anyversion }}
branchname: ${{ github.head_ref || github.ref_name }}
build:
runs-on: ubuntu-latest
name: Build Universal Wheel
needs: [prepare-build-info]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: pip
cache-dependency-path: '**/pyproject.toml'
- name: Set project version from git tag/readable name
run: echo "__version__ = '${{ needs.prepare-build-info.outputs.anyversion }}'" > src/topologicpy/version.py
- name: Install dependencies
run: |
pip install setuptools wheel build
- name: Build distibutive
run: |
python -m build
- name: List files
run: |
ls -R dist/
- name: Upload universal wheel artifact (py3, any platform)
uses: actions/upload-artifact@v4
with:
name: topologicpy-${{ needs.prepare-build-info.outputs.anyversion }}-py3-none-any.whl
path: dist/topologicpy-${{ needs.prepare-build-info.outputs.anyversion }}-py3-none-any.whl
if-no-files-found: error
retention-days: 60
test:
name: Test with Python ${{ matrix.python-version }} on ${{ startsWith(matrix.os, 'macos-') && 'macOS' || startsWith(matrix.os, 'windows-') && 'Windows' || 'Linux' }}
runs-on: ${{ matrix.os }}
needs:
- prepare-build-info
- build
strategy:
fail-fast: false
matrix:
# Add "3.13" when 'numpy' starts working with Python 3.13.
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
env:
# Reference: https://github.com/actions/setup-python/issues/862
# To solve: "A new release of pip is available: ... -> ..."
PIP_DISABLE_PIP_VERSION_CHECK: 1
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
cache: pip
cache-dependency-path: '**/pyproject.toml'
- name: Ensure latest pip
run: python -m pip install --upgrade pip
- name: Set version from git tag/readable name (${{ needs.prepare-build-info.outputs.anyversion }})
run: echo "__version__ = '${{ needs.prepare-build-info.outputs.anyversion }}'" > src/topologicpy/version.py
- name: Install dependencies
run: |
pip install -e '.[test]'
- name: Run tests
run: pytest
publish-pypi-release:
runs-on: ubuntu-latest
if: ${{ startsWith(needs.prepare-build-info.outputs.tagname, 'v') && github.event_name != 'pull_request' && (needs.prepare-build-info.outputs.branchname == 'prerelease' || needs.prepare-build-info.outputs.branchname == 'main') }}
needs:
- prepare-build-info
- build
- test
name: Consider & Publish PyPI Release
permissions:
id-token: write
environment:
name: release
url: https://pypi.org/p/topologicpy
steps:
- name: Download all artifact files (.whl)
uses: actions/download-artifact@v4
with:
path: all-artifacts
- name: Display new structure of downloaded files
# Skip '-linux_' builds if found, PyPI rejects them; use -manylinux*.
run: |
mkdir -p dist
find ./all-artifacts/ -type f -iname "*.whl" -exec mv {} ./dist/ \;
find ./dist/ -type f -iname "*-linux_*.whl" -exec rm {} \;
ls -R dist
- name: Publish package ${{ needs.prepare-build-info.outputs.tagname }} distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: dist/
print-hash: true
draft-github-release:
needs:
- prepare-build-info
- publish-pypi-release
if: ${{ startsWith(needs.prepare-build-info.outputs.tagname, 'v') && github.event_name != 'pull_request' && needs.prepare-build-info.outputs.branchname == 'main' }}
name: Consider & Draft GitHub Release Page
runs-on: ubuntu-latest
permissions:
# IMPORTANT: mandatory for GitHub Releases
contents: write
steps:
- name: Download all artifact files (.whl)
uses: actions/download-artifact@v4
with:
path: all-artifacts
- name: Display structure of downloaded files
run: ls -R all-artifacts
- name: Draft GitHub Release Page ${{ needs.prepare-build-info.outputs.tagname }}
uses: actions/create-release@v1
id: create_release
with:
draft: true
prerelease: false
release_name: ${{ needs.prepare-build-info.outputs.tagname }}
tag_name: ${{ needs.prepare-build-info.outputs.tagname }}
body: Changes in this Release
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Release artifact topologicpy-${{ needs.prepare-build-info.outputs.anyversion }}-py3-none-any.whl
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ github.token }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: all-artifacts/topologicpy-${{ needs.prepare-build-info.outputs.anyversion }}-py3-none-any.whl/topologicpy-${{ needs.prepare-build-info.outputs.anyversion }}-py3-none-any.whl
asset_name: topologicpy-${{ needs.prepare-build-info.outputs.anyversion }}-py3-none-any.whl
asset_content_type: application/zip