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
python --version
Step 3: Install VSCode Python Extension
Step 4: Set Up Bash
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:
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:
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.