From aef927c5c0684d68d75c14735577701fb64be5cd Mon Sep 17 00:00:00 2001 From: Shubha Rajan Date: Mon, 12 Dec 2022 13:16:09 -0800 Subject: [PATCH] manually install python if needed --- .github/workflows/sample-tests.yaml | 7 +++-- examples/java/install_python.sh | 47 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) create mode 100755 examples/java/install_python.sh diff --git a/.github/workflows/sample-tests.yaml b/.github/workflows/sample-tests.yaml index 5f4fa7c1..ac612ae9 100644 --- a/.github/workflows/sample-tests.yaml +++ b/.github/workflows/sample-tests.yaml @@ -140,9 +140,10 @@ jobs: service_account: ${{ secrets.SERVICE_ACCOUNT }} - name: Setup Python - uses: actions/setup-python@v4 - with: - python-version: '3.9' + run: | + if python -V | grep -q -L '3.10'; then + ./examples/java/install_python.sh + fi - name: 'Set up Cloud SDK' uses: 'google-github-actions/setup-gcloud@v1.0.1' diff --git a/examples/java/install_python.sh b/examples/java/install_python.sh new file mode 100755 index 00000000..ab34d495 --- /dev/null +++ b/examples/java/install_python.sh @@ -0,0 +1,47 @@ +#! /bin/bash +# Copyright 2022 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# `-e` enables the script to automatically fail when a command fails +set -ex + +sudo apt update + +# Install dependencies +sudo apt install -y \ + build-essential \ + zlib1g-dev \ + libncurses5-dev \ + libgdbm-dev libnss3-dev \ + libssl-dev \ + libreadline-dev \ + libffi-dev \ + libsqlite3-dev \ + wget \ + libbz2-dev + +# Download Source Code +wget https://www.python.org/ftp/python/3.10.0/Python-3.10.0.tgz +tar -xvf Python-3.10.0.tgz + +# Build from source +cd Python-3.10.0 +sudo ./configure --enable-optimizations +sudo make -j "$(nproc)" +sudo make altinstall + + +update-alternatives --install /usr/bin/python python /usr/local/bin/python3.10 1 +update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3.10 1 +python --version