diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..93f63e5d1 --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 88 +extend-ignore = E501 +exclude = .venv, frontend +ignore = E203, W503, G004, G200 \ No newline at end of file diff --git a/.github/workflows/docker-build-and-push.yml b/.github/workflows/docker-build-and-push.yml new file mode 100644 index 000000000..747181fb8 --- /dev/null +++ b/.github/workflows/docker-build-and-push.yml @@ -0,0 +1,83 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - dev + - demo + - hotfix + pull_request: + types: + - opened + - ready_for_review + - reopened + - synchronize + branches: + - main + - dev + - demo + - hotfix + workflow_dispatch: + +jobs: + build-and-push: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Log in to Azure Container Registry + if: ${{ github.ref_name == 'main' }} + uses: azure/docker-login@v2 + with: + login-server: ${{ secrets.ACR_LOGIN_SERVER }} + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_PASSWORD }} + + - name: Log in to Azure Container Registry (Dev/Demo) + if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} + uses: azure/docker-login@v2 + with: + login-server: ${{ secrets.ACR_DEV_LOGIN_SERVER }} + username: ${{ secrets.ACR_DEV_USERNAME }} + password: ${{ secrets.ACR_DEV_PASSWORD }} + + - name: Set Docker image tag + run: | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "TAG=latest" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == "refs/heads/dev" ]]; then + echo "TAG=dev" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == "refs/heads/demo" ]]; then + echo "TAG=demo" >> $GITHUB_ENV + elif [[ "${{ github.ref }}" == "refs/heads/hotfix" ]]; then + echo "TAG=hotfix" >> $GITHUB_ENV + fi + - name: Build and push Docker images + if: ${{ github.ref_name == 'main' }} + run: | + cd src/backend + docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} -f Dockerfile . && \ + docker push ${{ secrets.ACR_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} && \ + echo "Backend image built and pushed successfully." + cd ../frontend + docker build -t ${{ secrets.ACR_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} -f Dockerfile . && \ + docker push ${{ secrets.ACR_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} && \ + echo "Frontend image built and pushed successfully." + - name: Build and push Docker images (Dev/Demo/hotfix) + if: ${{ github.ref_name == 'dev' || github.ref_name == 'demo' || github.ref_name == 'hotfix' }} + run: | + cd src/backend + docker build -t ${{ secrets.ACR_DEV_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} -f Dockerfile . && \ + docker push ${{ secrets.ACR_DEV_LOGIN_SERVER }}/macae-backend:${{ env.TAG }} && \ + echo "Dev/Demo/Hotfix Backend image built and pushed successfully." + cd ../frontend + docker build -t ${{ secrets.ACR_DEV_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} -f Dockerfile . && \ + docker push ${{ secrets.ACR_DEV_LOGIN_SERVER }}/mac-webapp:${{ env.TAG }} && \ + echo "Dev/Demo/Hotfix Frontend image built and pushed successfully." + diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 000000000..74fc73c7a --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,27 @@ +name: Pylint and Flake8 + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] + steps: + - uses: actions/checkout@v4 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r src/backend/requirements.txt + pip install flake8 # Ensure flake8 is installed explicitly + + - name: Run flake8 and pylint + run: | + flake8 --config=.flake8 src/backend # Specify the directory to lint diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 000000000..daf9bfd1f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,61 @@ +name: Test Workflow with Coverage + +on: + push: + branches: + - main + - dev + - demo + - hotfix + pull_request: + types: + - opened + - ready_for_review + - reopened + - synchronize + branches: + - main + - main + - dev + - demo + - hotfix + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r src/backend/requirements.txt + pip install pytest-cov + + - name: Check if test files exist + id: check_tests + run: | + if [ -z "$(find src -type f -name 'test_*.py')" ]; then + echo "No test files found, skipping tests." + echo "skip_tests=true" >> $GITHUB_ENV + else + echo "Test files found, running tests." + echo "skip_tests=false" >> $GITHUB_ENV + fi + + - name: Run tests with coverage + if: env.skip_tests == 'false' + run: | + pytest --cov=. --cov-report=term-missing --cov-report=xml + + - name: Skip coverage report if no tests + if: env.skip_tests == 'true' + run: | + echo "Skipping coverage report because no tests were found."