diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 90d44cd..e6ddfe2 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -1,32 +1,33 @@ -# This workflow will install Python dependencies, run tests and lint with a single version of Python +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python application +name: Python package on: - # push: - # branches: [ "main" ] + # push: + # branches: [ "main" ] pull_request: branches: [ "main" ] -permissions: - contents: read - jobs: - build: + build-and-test-python-app: runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v4 - - name: Set up Python 3.10 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: - python-version: "3.10" + python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip - pip install flake8 pytest + python -m pip install flake8 pytest if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | @@ -37,6 +38,7 @@ jobs: - name: Test with pytest run: | pytest + sonarqube-scanner: name: Build and analyze runs-on: ubuntu-latest @@ -45,13 +47,35 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - uses: SonarSource/sonarqube-scan-action@v4 + - uses: sonarsource/sonarqube-scan-action@v4 env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} # If you wish to fail your job when the Quality Gate is red, uncomment the # following lines. This would typically be used to fail a deployment. - # - uses: SonarSource/sonarqube-quality-gate-action@v1 - # timeout-minutes: 5 - # env: - # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - uses: sonarsource/sonarqube-quality-gate-action@v1 + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + docker-build-and-push-to-dockerhub: + runs-on: ubuntu-latest + needs: [build-and-test-python-app, sonarqube-scanner ] + steps: + - name: Docker Setup QEMU + uses: docker/setup-qemu-action@v3.0.0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: thehiddenboy143/gfgdevops20flask:latest diff --git a/sonar-project.properties b/sonar-project.properties index d30192b..a5d6f43 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1 +1,3 @@ sonar.projectKey=gfg20pythonci-cd +sonar.ws.timeout=600 +