Merge pull request #22 from Video2Frames/feature/2.0.0 #47
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 | |
| # ========================================================= | |
| build: | |
| name: Build Lambda | |
| runs-on: ubuntu-latest | |
| 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 | |
| ########################################################### | |
| # BUILD + TEST + COVERAGE | |
| ########################################################### | |
| build-and-test: | |
| name: Build and Test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - 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 | |
| - name: Publish Test Report | |
| uses: dorny/test-reporter@v1 | |
| if: always() | |
| with: | |
| name: Maven Tests | |
| path: target/surefire-reports/*.xml | |
| reporter: java-junit | |
| - name: Upload Coverage | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: jacoco-report | |
| path: target/site/jacoco | |
| ########################################################### | |
| # SONARCLOUD | |
| ########################################################### | |
| sonarqube: | |
| name: SonarCloud Analysis | |
| runs-on: ubuntu-latest | |
| needs: build-and-test | |
| environment: production | |
| if: github.ref == 'refs/heads/main' | |
| steps: | |
| - 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: Debug SONAR_TOKEN | |
| run: | | |
| if [ -z "${{ secrets.SONAR_TOKEN }}" ]; then | |
| echo "Token exists: false" | |
| else | |
| echo "Token exists: true" | |
| fi | |
| - name: SonarCloud Analysis | |
| env: | |
| SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
| run: | | |
| mvn -B clean 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=target/site/jacoco/jacoco.xml | |
| # ========================================================= | |
| # DEPLOY | |
| # ========================================================= | |
| deploy: | |
| name: Deploy Lambda + Infra | |
| runs-on: ubuntu-latest | |
| needs: build | |
| environment: Production | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| - name: Download 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 |