fix sonar #52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Lambda to AWS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| env: | |
| TF_WORKSPACE: default | |
| AWS_REGION: us-east-1 | |
| jobs: | |
| ########################################################### | |
| # BUILD + TEST + COVERAGE | |
| ########################################################### | |
| build-and-test: | |
| name: Build and Test | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| working-directory: app | |
| permissions: | |
| contents: read | |
| checks: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 17 | |
| distribution: temurin | |
| cache: maven | |
| - name: Build with Tests | |
| run: mvn -B clean verify | |
| working-directory: app | |
| - name: Publish Test Report | |
| uses: dorny/test-reporter@v1 | |
| if: always() | |
| with: | |
| name: Maven Tests | |
| path: app/target/surefire-reports/*.xml | |
| reporter: java-junit | |
| - name: Upload Coverage | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jacoco-report | |
| path: target/site/jacoco | |
| - name: Upload Lambda JAR | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: lambda-jar | |
| path: app/target/lambda-identification-auth.jar | |
| ########################################################### | |
| # SONARCLOUD | |
| ########################################################### | |
| sonarqube: | |
| name: SonarCloud Analysis | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: 17 | |
| distribution: temurin | |
| cache: maven | |
| - name: Cache Sonar packages | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.sonar/cache | |
| key: ${{ runner.os }}-sonar | |
| - name: SonarCloud Analysis | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| mvn -B verify sonar:sonar \ | |
| -Dsonar.projectKey=video2frames_lambda-identification-auth \ | |
| -Dsonar.organization=video2frames \ | |
| -Dsonar.host.url=https://sonarcloud.io \ | |
| -Dsonar.token=${SONAR_TOKEN} \ | |
| -Dsonar.coverage.jacoco.xmlReportPaths=app/target/site/jacoco/jacoco.xml | |
| ########################################################### | |
| # DEPLOY | |
| ########################################################### | |
| deploy: | |
| name: Deploy Lambda + Infra | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-and-test | |
| - sonarqube | |
| environment: Production | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Download Lambda Artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: lambda-jar | |
| path: app/target | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }} | |
| aws-secret-access-key: ${{ secrets.AWS_ACCESS_SECRET }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Setup Terraform | |
| uses: hashicorp/setup-terraform@v3 | |
| - name: Terraform Init | |
| run: terraform init | |
| - name: Terraform Plan | |
| run: terraform plan -out=tfplan | |
| env: | |
| TF_VAR_lambda_jar_path: app/target/lambda-identification-auth.jar | |
| - name: Terraform Apply | |
| run: terraform apply -auto-approve tfplan | |
| env: | |
| TF_VAR_lambda_jar_path: app/target/lambda-identification-auth.jar |