-
Notifications
You must be signed in to change notification settings - Fork 60
202 lines (178 loc) · 8.69 KB
/
pypi-cd.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# The cross platform build was created based on the [Packaging Rust Applications for the NPM Registry blog](https://blog.orhun.dev/packaging-rust-for-npm/).
name: Continuous Deployment
on:
pull_request:
paths:
- .github/workflows/pypi-cd.yml
- .github/workflows/build-python-wrapper/action.yml
- .github/workflows/start-self-hosted-runner/action.yml
push:
tags:
- "v*.*"
concurrency:
group: pypi-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
id-token: write
jobs:
load-platform-matrix:
runs-on: ubuntu-latest
outputs:
PLATFORM_MATRIX: ${{ steps.load-platform-matrix.outputs.PLATFORM_MATRIX }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: load-platform-matrix
id: load-platform-matrix
shell: bash
run: |
# Get the matrix from the matrix.json file, without the object that has the IMAGE key
export "PLATFORM_MATRIX=$(jq 'map(select(.PACKAGE_MANAGERS | contains(["pypi"])))' < .github/workflows/build-matrix.json | jq -c .)"
echo "PLATFORM_MATRIX=${PLATFORM_MATRIX}" >> $GITHUB_OUTPUT
start-self-hosted-runner:
if: github.repository_owner == 'aws'
runs-on: ubuntu-latest
environment: AWS_ACTIONS
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Start self hosted EC2 runner
uses: ./.github/workflows/start-self-hosted-runner
with:
role-to-assume: ${{ secrets.ROLE_TO_ASSUME }}
aws-region: ${{ secrets.AWS_REGION }}
ec2-instance-id: ${{ secrets.AWS_EC2_INSTANCE_ID }}
publish-binaries:
needs: [start-self-hosted-runner, load-platform-matrix]
if: github.repository_owner == 'aws'
name: Publish packages to PyPi
runs-on: ${{ matrix.build.RUNNER }}
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
build:
${{fromJson( needs.load-platform-matrix.outputs.PLATFORM_MATRIX )}}
steps:
- name: Setup self-hosted runner access
if: ${{ contains(matrix.build.RUNNER, 'self-hosted') }}
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/glide-for-redis
- name: Checkout
uses: actions/checkout@v4
with:
submodules: "true"
- name: Set the release version
shell: bash
run: |
export version=`if ${{ github.event_name == 'pull_request' }}; then echo '255.255.255'; else echo ${GITHUB_REF:11}; fi`
echo "RELEASE_VERSION=${version}" >> $GITHUB_ENV
# For NPM and Cargo we need the the rc version to be {version}-rc{number} while for PyPi we need it to be {version}rc{number}
# This is because PyPi does not allow the '-' character in the version name
# So the tag will be as NPM and Cargo ask: v1.0.0-rc1 and for PyPi we'll chnage it to: v1.0.0rc1
- name: Change and set realease version for RC
if: ${{ github.event_name != 'pull_request' && contains(github.ref, 'rc') }}
shell: bash
run: |
export py_version=`echo ${GITHUB_REF:11} | sed 's/-rc/rc/'`
echo "PY_RELEASE_VERSION=${py_version}" >> $GITHUB_ENV
- name: Check that the release version dont have typo init
if: ${{ github.event_name != 'pull_request' && contains(github.ref, '-') && !contains(github.ref, 'rc') }}
run: |
echo "The release version "${GITHUB_REF:11}" contains a typo, please fix it"
echo "The release version should be in the format v{major-version}.{minor-version}.{patch-version}-rc{release-candidate-number} when it a release candidate or v{major-version}.{minor-version}.{patch-version} in a stable release."
exit 1
- name: Set the package version for Python
working-directory: ./python
run: |
SED_FOR_MACOS=`if [[ "${{ matrix.build.OS }}" =~ .*"macos".* ]]; then echo "''"; fi`
sed -i $SED_FOR_MACOS "s|255.255.255|${{ env.RELEASE_VERSION }}|g" ./Cargo.toml
# Log the edited Cargo.toml file
cat Cargo.toml
- name: Set up Python
if: ${{ !contains(matrix.build.RUNNER, 'self-hosted') }}
uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Set up Python older versions for MacOS
if: startsWith(matrix.build.NAMED_OS, 'darwin')
run: |
brew update
brew upgrade || true
brew install [email protected] [email protected]
- name: Setup Python for self-hosted Ubuntu runners
if: contains(matrix.build.OS, 'ubuntu') && contains(matrix.build.RUNNER, 'self-hosted')
run: |
sudo apt update -y
sudo apt upgrade -y
sudo apt install python3 python3-venv python3-pip -y
- name: Update package version in config.toml
uses: ./.github/workflows/update-glide-version
with:
folder_path: "${{ github.workspace }}/python/.cargo"
named_os: ${{ matrix.build.NAMED_OS }}
- name: Build Python wrapper
uses: ./.github/workflows/build-python-wrapper
with:
os: ${{ matrix.build.OS }}
target: ${{ matrix.build.TARGET }}
publish: "true"
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Include protobuf files in the package
working-directory: ./python
run: |
SED_FOR_MACOS=`if [[ "${{ matrix.build.OS }}" =~ .*"macos".* ]]; then echo "''"; fi`
sed -i $SED_FOR_MACOS '/pb2.py/d' .gitignore
# Log the edited .gitignore file
cat .gitignore
- name: Build Python wheels (linux)
if: startsWith(matrix.build.NAMED_OS, 'linux')
uses: PyO3/maturin-action@v1
with:
working-directory: ./python
target: ${{ matrix.build.TARGET }}
args: --release --strip --out wheels -i ${{ github.event_name != 'pull_request' && 'python3.8 python3.9 python3.10 python3.11 python3.12' || 'python3.10' }}
manylinux: auto
container: ${{ matrix.build.CONTAINER != '' && matrix.build.CONTAINER || '2014' }}
before-script-linux: |
# Install protobuf compiler
if [[ $(`which apt`) != '' ]]
then
apt install protobuf-compiler -y
else
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
export PATH="$PATH:$HOME/.local/bin"
fi
- name: Build Python wheels (macos)
if: startsWith(matrix.build.NAMED_OS, 'darwin')
uses: PyO3/maturin-action@v1
with:
working-directory: ./python
target: ${{ matrix.build.TARGET }}
args: --release --strip --out wheels -i ${{ github.event_name != 'pull_request' && 'python3.8 python3.9 python3.10 python3.11 python3.12' || 'python3.10' }}
- name: Upload Python wheels
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@v3
with:
name: wheels
path: python/wheels
if-no-files-found: error
publish-to-pypi:
if: github.event_name != 'pull_request'
name: Publish the base PyPi package
runs-on: ubuntu-latest
needs: publish-binaries
steps:
- uses: actions/download-artifact@v3
with:
path: python/wheels
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.LIVEPYPI_API_TOKEN }}
MATURIN_REPOSITORY: pypi
with:
command: upload
args: --skip-existing python/wheels/*