Guide to Set Up Visual Studio Code (VSCode) for Python and Bash, Plus Setting Up a CI Pipeline with GitHub Actions for a simple Python apps

Set Up Visual Studio Code (VSCode) for Python and Bash

Step 1: Download and Install VSCode

Download VSCode:

Step 2: Install Python

  • Go to the Python website.
  • Download the latest version suitable for your OS.
  • Run the installer and ensure you check the option to Add Python to PATH during the installation.
  • Open a terminal (Command Prompt, PowerShell, or your system's terminal) and type:

python --version

Step 3: Install VSCode Python Extension

Step 4: Set Up Bash

  • Download Git for Windows from the Git website and install it.


Setting Up a CI Pipeline with GitHub Actions


Step 1: Create a Simple Python Application

open the terminal in Visual Studio Code using a keyboard shortcut

Windows/Linux: Ctrl + ` (backtick)

Create a New Directory for Your Project:

mkdir PYTHON-APP
cd PYTHON-APP        

Create a Simple Application:

  • Create a file named app.py and add the following code:

def hello():
    return "Hello, Shakti!"
if __name__ == "__main__":
        print(hello())        

Create a Simple Test:

Create a file named test.py and add the following code:

from app import hello
def test():
    assert hello() == "Hello, Shakti!"        

Install Testing Library (pytest):

pip install pytest


Step 2: Push Your Code to GitHub:

git init

git add .

git commit -m "My first commit"

git remote add DevOps https://github.com/shaktia/DevOps.git

git push DevOps master


Step 3: Configure GitHub Actions

In your project directory, create a directory for GitHub Actions

mkdir -p .github/workflows

Create a Workflow File:

  • Create a file named python_ci.yml in .github/workflows and add the following configuration:

name: CI

on:

push:

branches:

- master

jobs:

build:

runs-on: ubuntu-latest

steps:

- name: Checkout code

uses: actions/checkout@v2

- name: Set up Python

uses: actions/setup-python@v2

with:

python-version: '3.9'

- name: Install dependencies

run: |

python -m pip install --upgrade pip

pip install pytest

- name: Run tests

run: |

pytest test.py


Step 4: Push Changes and Trigger CI

git add .github/workflows/ci.yml

git commit -m "Python CI workflow"

git push DevOps master

Check GitHub Actions:

Go to your GitHub repository, click on the "Actions" tab, and you should see your CI pipeline running. It will build your application and run the tests automatically whenever you push new code to the master branch.






To view or add a comment, sign in

Explore content categories