Wednesday, 22 December 2021

GitHub Actions unable to set up Python Virtual Environment

I need to setup a virtual environment, and install the requirements for my Flask app.

However, an error occurs here:

sudo apt install python3-venv
sudo python3.8 -m venv venv

This is the .yml file for my GitHub Actions.

name: TEST

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - name: Setup system group
      run: |
        if [ ! $( getent group uni ) ]; then sudo addgroup --system uni; fi
        
    - name: Setup system user
      run: |
        if [[ $(getent passwd uni) = "" ]]; then sudo adduser --no-create-home --force-badname --disabled-login --disabled-password --system uni; fi
    - name: Add user user to group
      run: |
        sudo usermod -g uni uni
    
    - name: Setup base directory
      working-directory: /
      run: |
        if [ ! -d ./uni/test/app ]; then sudo mkdir -p ./uni/test/app; fi
        sudo chown uni:uni -R /uni/test
        sudo chmod 775 -R /uni/test
      
    - name: Setup log directory
      working-directory: /var/log
      run: |
        if [ ! -d ./uni/test ]; then sudo mkdir -p ./uni/test; fi
        sudo chown uni:uni -R ./uni/test
        sudo chmod 755 -R ./uni/test
      
    - uses: actions/checkout@v2
    - name: Set up Python 3.8
      uses: actions/setup-python@v2
      with:
        python-version: 3.8
        
    - name: Setup Python virtual environment
      working-directory: /uni/test/app
      run: |
        sudo apt install python3-venv
        sudo python3.8 -m venv venv
    
    - name: Install dependencies
      working-directory: /uni/test/app/venv
      run: |
        source ./bin/activate
        pip install --upgrade pip
        pip install wheel
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
        deactivate

What am I doing wrong here?

And is there a way I can install python3-venv inside the block below?

- uses: actions/checkout@v2
- name: Set up Python 3.8
  uses: actions/setup-python@v2
  with:
    python-version: 3.8


from GitHub Actions unable to set up Python Virtual Environment

No comments:

Post a Comment