diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index a98b15e..d1cb1d8 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -1,5 +1,4 @@ name: CI/CD Pipeline - on: release: types: [ published ] @@ -8,7 +7,6 @@ on: - '**' tags-ignore: - '**' - jobs: lint: name: Lint Code @@ -19,6 +17,19 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + + - name: Lint with Ruff + run: ruff check app/ tests/ + test: name: Run Tests runs-on: ubuntu-latest @@ -28,6 +39,20 @@ jobs: - name: Checkout code uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + pip install pytest pytest-cov httpx + + - name: Run tests with coverage + run: pytest --cov=app --cov-report=term-missing --cov-fail-under=80 + build: name: Build Docker Image runs-on: ubuntu-latest @@ -40,3 +65,31 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Lowercase repository name + id: repo + run: echo "name=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_OUTPUT + + - name: Extract version tag + id: vars + run: | + if [[ "${{ github.event_name }}" == "release" ]]; then + echo "tags=ghcr.io/${{ steps.repo.outputs.name }}:${{ github.ref_name }},ghcr.io/${{ steps.repo.outputs.name }}:latest" >> $GITHUB_OUTPUT + else + echo "tags=ghcr.io/${{ steps.repo.outputs.name }}:${{ github.sha }}" >> $GITHUB_OUTPUT + fi + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + file: docker/Dockerfile + push: true + tags: ${{ steps.vars.outputs.tags }}