From c3017c5bf45d6c26c0f86baa879db90b8aed10e6 Mon Sep 17 00:00:00 2001 From: ahmedgamalyousef Date: Tue, 14 Oct 2025 19:49:50 +0300 Subject: [PATCH] Creating Pre-commit file & Adding workflow Testing --- .github/workflows/cicd.yaml | 71 +++++++++++++++++++++++++++++++------ .pre-commit-config.yaml | 28 +++++++++++++++ 2 files changed, 88 insertions(+), 11 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml index b90030d..05e8d8f 100644 --- a/.github/workflows/cicd.yaml +++ b/.github/workflows/cicd.yaml @@ -1,36 +1,85 @@ +name: CI/CD Pipeline - Weather App ๐ŸŒค๏ธ + on: push: + branches: [ main ] pull_request: - + jobs: - build_and_push_image: + # ----------------------------- + # ๐Ÿงช 1. Test job + # ----------------------------- + test: + runs-on: ubuntu-latest steps: - - name: checkout code + - name: ๐Ÿงพ Checkout Code uses: actions/checkout@v5.0.0 - - name: login to dockerhub + - name: ๐Ÿ Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: ๐Ÿ“ฆ Install Dependencies + run: | + python -m venv venv + source venv/bin/activate + pip install -r requirements.txt + pip install pytest pytest-cov flake8 + + - name: ๐Ÿ” Run Code Linting + run: | + source venv/bin/activate + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + + - name: ๐Ÿงช Run Unit Tests + run: | + source venv/bin/activate + pytest --maxfail=1 --disable-warnings -q + + - name: ๐Ÿ“Š Generate Test Coverage Report + run: | + source venv/bin/activate + pytest --cov=app --cov-report=term-missing + + # ----------------------------- + # ๐Ÿณ 2. Build and Push Docker Image + # ----------------------------- + build_and_push_image: + runs-on: ubuntu-latest + needs: test + steps: + - name: ๐Ÿ“ฆ Checkout Code + uses: actions/checkout@v5.0.0 + + - name: ๐Ÿ” Login to DockerHub uses: docker/login-action@v3.6.0 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build and push + - name: ๐Ÿณ Build and Push Docker Image uses: docker/build-push-action@v6 with: context: . push: true tags: ahmedgamalyousef/firstcicd:latest - + + # ----------------------------- + # โ˜๏ธ 3. Deploy to Ghaymah Cloud + # ----------------------------- deploy: + runs-on: ubuntu-latest needs: build_and_push_image steps: - - name: checkout code + - name: ๐Ÿ“ฆ Checkout Code uses: actions/checkout@v5.0.0 - - name: install ghaymah cli + + - name: ๐ŸŒฉ๏ธ Install Ghaymah CLI run: curl -sSl https://cli.ghaymah.systems/install.sh | bash - - name: login to ghaymah - run: $HOME/ghaymah/bin/gy auth login --email "${{secrets.GHAYMAH_EMAIL}}" --password "${{secrets.GHAYMAH_PW}}" + - name: ๐Ÿ” Login to Ghaymah Cloud + run: $HOME/ghaymah/bin/gy auth login --email "${{ secrets.GHAYMAH_EMAIL }}" --password "${{ secrets.GHAYMAH_PW }}" - - name: deploy + - name: ๐Ÿš€ Deploy Application run: $HOME/ghaymah/bin/gy resource app launch diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..3ced254 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + - id: check-merge-conflict + - id: check-ast + + - repo: https://github.com/psf/black + rev: 23.9.1 + hooks: + - id: black + args: [--line-length=88] + + - repo: https://github.com/pycqa/flake8 + rev: 6.1.0 + hooks: + - id: flake8 + args: [--max-line-length=88, --extend-ignore=E203,W503] + + - repo: https://github.com/pycqa/isort + rev: 5.12.0 + hooks: + - id: isort + args: ["--profile", "black"] \ No newline at end of file