-
Notifications
You must be signed in to change notification settings - Fork 13
121 lines (111 loc) · 4.57 KB
/
python-deploy.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
name: Deployment to PyPI
on:
push:
branches:
- "main"
tags:
- "**"
permissions:
contents: write
jobs:
# Keep the "build" job identical to "python-build.yml".
# TODO(clairbee): include "python-build.yml" instead
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ["3.11"]
runs-on: ${{ matrix.os }}
env:
BIN_DIR: ${{ matrix.os == 'windows-latest' && 'Scripts' || 'bin' }}
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- uses: actions/cache@v3
id: cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.*') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Prepare environments
run: |
python -m pip install --upgrade pip build
mkdir .venv
python -m venv .venv/build
(. .venv/build/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
python -m venv .venv/build-cli
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
python -m venv .venv/install
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --upgrade pip build && deactivate)
- name: Test building and packaging
run: |
(. .venv/build/${{ env.BIN_DIR }}/activate && cd partcad && python -m build && cd .. && deactivate)
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
cp README.md partcad-cli
(. .venv/build-cli/${{ env.BIN_DIR }}/activate && cd partcad-cli && python -m build && cd .. && deactivate)
- name: Test installation
run: |
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad/requirements.txt && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad/dist partcad && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install -r partcad-cli/requirements.txt && deactivate)
(. .venv/install/${{ env.BIN_DIR }}/activate && python -m pip install --no-index --find-links=partcad-cli/dist partcad-cli && deactivate)
# Upload artifact from the selected OS/Python version combination only
- name: Upload "partcad"
if: "matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'"
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: partcad/dist/
- name: Upload "partcad-cli"
if: "matrix.os == 'ubuntu-latest' && matrix.python-version == '3.11'"
uses: actions/upload-artifact@v3
with:
name: python-package-distributions
path: partcad-cli/dist/
publish-to-pypi:
name: Publish to PyPI
needs:
- build
runs-on: ubuntu-latest
environment:
name: pypi
steps:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Download all the dists
uses: actions/download-artifact@v3
with:
name: python-package-distributions
path: dist
- name: Determine the release tag
if: github.ref == 'refs/heads/main'
run: |
git clone https://github.com/openvmp/partcad partcad-git;
cd partcad-git;
echo "MERGED_TAG=$(git describe --abbrev=0)" >> $GITHUB_ENV
- name: Create GitHub Release
if: github.ref == 'refs/heads/main'
env:
GITHUB_TOKEN: ${{ github.token }}
run: |
gh release create '${{ env.MERGED_TAG }}' --repo '${{ github.repository }}' --notes "";
gh release upload '${{ env.MERGED_TAG }}' dist/** --repo '${{ github.repository }}'
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url:
"${{ github.ref == 'refs/heads/main' &&
'https://upload.pypi.org/legacy/' || 'https://test.pypi.org/legacy/'
}}"
user: __token__
password:
"${{ github.ref == 'refs/heads/main' && secrets.PYPI_KEY ||
secrets.TEST_PYPI_KEY }}"