-
Notifications
You must be signed in to change notification settings - Fork 0
141 lines (122 loc) · 4.74 KB
/
pypi_env.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
name: "PyPI Publish Environment"
on:
workflow_call:
inputs:
# Success Policy
distro_name:
required: true
type: string
# PEP 440 compliant version string
distro_version:
required: true
type: string
should_trigger:
required: true
type: boolean
pypi_env:
required: true
type: string
# Optional Inputs
allow_existing:
# Continue uploading files, if one already exists. (Only valid when
# uploading to PyPI. Other implementations may not support this.)
type: boolean
default: true
description: 'Continue uploading files, if one already exists, instead of Erroring'
required: false
require_wheel:
type: boolean
default: true
description: 'Require at least one Wheel Distribution to be uploaded'
required: false
artifacts_path:
type: string
default: 'downloaded-artifacts'
description: 'Where to download CI Artifacts into'
required: false
dist_folder:
required: false
type: string
secrets:
# Bypassing https://github.com/actions/runner/issues/1490
TWINE_PASSWORD:
required: false
jobs:
# https://github.com/marketplace/actions/pypi-publish
### PYPI UPLOAD JOB ###
pypi_env_publish:
runs-on: ubuntu-latest
if: always() && inputs.should_trigger
environment:
name: ${{ inputs.pypi_env }}
env:
DIST_DIR: ${{ inputs.dist_folder || 'dist' }}
steps:
- uses: actions/checkout@v4
# TODO only Download Build Artifacts
# For python, Builds typically are files: *.tar.gz, *.whl, cython builds, etc.
- name: Download Source & Wheel distributions
uses: actions/download-artifact@v3
with:
path: ${{ inputs.artifacts_path }}
- run: ls -laR ${{ inputs.artifacts_path }}
# Create DIST Dir folder, to Upload to PyPI
- run: mkdir ${DIST_DIR}
## PUT TAR.GZ file in DIST Dir ##
# Every Python Release must a Source Distro Build
- name: "Discover .tar.gz Source Distribution, from CI Artifacts"
run: |
targz_files=$(find ${{ inputs.artifacts_path }} -type f -name ${{ inputs.distro_name }}*.tar.gz)
targz_files_array=($targz_files)
SOURCE_DISTRO=${targz_files_array[0]} # a *.tar.gz file path
echo "[INFO] Sdist Build: ${SOURCE_DISTRO}"
DISTRO_DIR=$(dirname "$SOURCE_DISTRO")
DISTRO_FILE_NAME=$(basename "$SOURCE_DISTRO")
echo
echo "---> Selected Sdist Build: ${DISTRO_FILE_NAME} <---"
echo
echo "---> Taken from directory: ${DISTRO_DIR} <---"
echo
# Check if all source distribution (.tar.gz) files have the same name
for file in "${targz_files_array[@]}"; do
echo "[INFO] Checking file ${file}"
if [ "$DISTRO_FILE_NAME" != "$(basename "$file")" ]; then
echo "Error: Not all Source Distribution .tar.gz files have the same name!"
exit 1
fi
done
echo "SOURCE_DISTRO=$SOURCE_DISTRO" >> $GITHUB_ENV
echo "DISTRO_FILE_NAME=$DISTRO_FILE_NAME" >> $GITHUB_ENV
- name: "Copy .tar.gz SOURCE Distro '${{ env.DISTRO_FILE_NAME }}' file, into '${{ env.DIST_DIR }}' folder"
run: cp "${{ env.SOURCE_DISTRO }}" "${{ env.DIST_DIR }}"
## PUT WHEEL file(s) in DIST Dir ##
# A Python Release could have one or more Wheel Builds
- name: "Copy .whl WHEEL Distro(s) files, into '${{ env.DIST_DIR }}' folder"
run: |
echo " -> Downloaded Wheel(s):"
find ${{ inputs.artifacts_path }} -type f -name "${{ inputs.distro_name }}*.whl"
echo
res=$(find ${{ inputs.artifacts_path }} -type f -name "${{ inputs.distro_name }}*.whl")
for f in $res; do
echo "[INFO] Copying Wheel Distribution: $f";
cp $f ${DIST_DIR}
done
- run: ls -la ${DIST_DIR}
- name: Verify at least 1 Wheel Distribution, to be uploaded to PyPI
if: inputs.require_wheel
run: |
if [[ $(find ${DIST_DIR} -type f -name "${{ inputs.distro_name }}*.whl" | wc -l) -eq 0 ]]; then
echo "Error: No Wheel Distribution .whl files found!"
exit 1
fi
##
## PyPI Upload Command
- run: pip install tox==3.28
- name: "Publish '${{ inputs.distro_name }}' version ${{ inputs.distro_version }} to '${{ inputs.pypi_server }}' Server"
env:
PACKAGE_DIST_VERSION: ${{ inputs.distro_version }}
TWINE_USERNAME: ${{ vars.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
PYPI_SERVER: ${{ vars.PYPI_SERVER }}
run: tox -vv -s false -e deploy -- upload --non-interactive ${{ inputs.allow_existing && '--skip-existing' || '' }}
- run: echo "Published :\)"