-
Notifications
You must be signed in to change notification settings - Fork 48
167 lines (150 loc) · 7.42 KB
/
build_upload_test.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
# "Template" workflow that can be called by other workflows as well as manually triggered
# https://docs.github.com/en/actions/learn-github-actions/reusing-workflows
name: Build & Upload to Test PyPI
on:
# NOTICE: accessing input/secret variables differ between workflow_call and
# workflow_dispatch. See https://github.community/t/inconsistent-inputs-context-for-workflow-dispatch-and-workflow-call/207835
workflow_call: # allows calls from other workflows
# to access inputs: {{ inputs.<variable_name> }}
# to access secrets: {{ secrets.token }}
inputs:
package-dir:
description: "Directory of package to build & upload"
required: true
type: string
package-name:
description: "Import name of package (e.g. klio_core, not klio-core)"
required: true
type: string
secrets:
token:
required: true
workflow_dispatch: # manual trigger
# to access inputs: {{ github.event.inputs.<variable_name> }}
# to access secrets: {{ secrets.TEST_PYPI_API_TOKEN }}
inputs:
package-dir:
description: "Directory of package to build & upload"
required: true
type: string
package-name:
description: "Import name of package (e.g. klio_core, not klio-core)"
required: true
type: string
jobs:
build_install:
name: "Build & Install ${{ inputs.package-name || github.event.inputs.package-name }}"
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v2"
- name: "Set up Python 3.8"
uses: "actions/setup-python@v2"
with:
python-version: 3.8
- name: "Install dependencies"
run: |
set -xe
python -VV
python -m pip install build virtualenv twine --user
- name: "${{ inputs.package-name || github.event.inputs.package-name }}: Build wheel & sdist"
run: |
set -xe
pwd
python -VV
python -m build --sdist --wheel --outdir ${{ inputs.package-dir || github.event.inputs.package-dir }}/dist/ ${{ inputs.package-dir || github.event.inputs.package-dir }}
- name: "${{ inputs.package-name || github.event.inputs.package-name }}: Check Long Description"
run: |
set -xe
python -VV
python -m twine check ${{ inputs.package-dir || github.event.inputs.package-dir }}/dist/*
- name: "${{ inputs.package-name || github.event.inputs.package-name }}: Test sdist installation from local build"
run: |
set -xe
python -VV
python -m virtualenv sdist-test
source sdist-test/bin/activate
python -m pip install ${{ inputs.package-dir || github.event.inputs.package-dir }}/dist/*.tar.gz
python -c 'import ${{ inputs.package-name || github.event.inputs.package-name }}; print(${{ inputs.package-name || github.event.inputs.package-name }}.__version__)'
deactivate
- name: "${{ inputs.package-name || github.event.inputs.package-name }}: Test wheel installation from local build"
run: |
set -xe
python -VV
python -m virtualenv wheel-test
source wheel-test/bin/activate
python -m pip install ${{ inputs.package-dir || github.event.inputs.package-dir }}/dist/*.whl
python -c 'import ${{ inputs.package-name || github.event.inputs.package-name }}; print(${{ inputs.package-name || github.event.inputs.package-name }}.__version__)'
deactivate
# Upload artifact so it can be downloaded & used in the following job
- name: "Archive artifacts"
uses: actions/upload-artifact@v2
with:
name: dist-${{ inputs.package-name || github.event.inputs.package-name }}
path: ${{ inputs.package-dir || github.event.inputs.package-dir }}/dist/*
retention-days: 1
upload_test_pypi:
name: "Upload ${{ inputs.package-name || github.event.inputs.package-name }} to PyPI Test Server"
needs: build_install
outputs:
version: ${{ steps.version.outputs.version }}
runs-on: "ubuntu-latest"
steps:
- name: "Download ${{ inputs.package-name || github.event.inputs.package-name }} artifacts from GH"
id: download
uses: actions/download-artifact@v2
with:
name: dist-${{ inputs.package-name || github.event.inputs.package-name }}
# Save the version as a variable we can use later when we test
# the installation
- name: "Grab Package Version for ${{ inputs.package-name || github.event.inputs.package-name }}"
id: version
shell: bash
run: |
set -xe
FULL_PATH=$(ls ${{ steps.download.outputs.download-path }}/*.whl)
BASE_NAME=$(basename ${FULL_PATH} .whl)
VERSION=$(echo ${BASE_NAME} | cut -d- -f2)
echo ::set-output name=version::$(echo ${VERSION})
- name: "Upload ${{ inputs.package-name || github.event.inputs.package-name }} artifacts to Test PyPI"
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.token || secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
verbose: true
packages_dir: ${{ steps.download.outputs.download-path }}
install_test_pypi:
name: "Test installation of ${{ inputs.package-name || github.event.inputs.package-name }} from Test PyPI"
needs: upload_test_pypi
runs-on: "ubuntu-latest"
steps:
- name: Set up Python 3.8
uses: "actions/setup-python@v2"
with:
python-version: 3.8
- name: "Sleep to wait for propagation"
run: |
set -xe
sleep 120
- name: "Install dependencies"
run: |
set -xe
python -VV
python -m pip install virtualenv --user
# Since not all of our dependencies are on the Test PyPI, we pass in
# an `--extra-index-url` to include prod so the klio* package can be properly installed
- name: "Test wheel install of ${{ inputs.package-name || github.event.inputs.package-name }} from Test PyPI"
run: |
set -xe
python -m virtualenv test-pypi-wheel
source test-pypi-wheel/bin/activate
python -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --only-binary=${{ inputs.package-name || github.event.inputs.package-name }} ${{ inputs.package-name || github.event.inputs.package-name }}==${{ needs.upload_test_pypi.outputs.version }}
python -c 'import ${{ inputs.package-name || github.event.inputs.package-name }}; assert ${{ inputs.package-name || github.event.inputs.package-name }}.__version__ == "${{ needs.upload_test_pypi.outputs.version }}"'
deactivate
- name: "Test sdist install of ${{ inputs.package-name || github.event.inputs.package-name }} from Test PyPI"
run: |
set -xe
python -m virtualenv test-pypi-sdist
source test-pypi-sdist/bin/activate
python -m pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple --no-binary=${{ inputs.package-name || github.event.inputs.package-name }} ${{ inputs.package-name || github.event.inputs.package-name }}==${{ needs.upload_test_pypi.outputs.version }}
python -c 'import ${{ inputs.package-name || github.event.inputs.package-name }}; assert ${{ inputs.package-name || github.event.inputs.package-name }}.__version__ == "${{ needs.upload_test_pypi.outputs.version }}"'
deactivate