test unit #42
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 | |
| # ------------------------------- | |
| # RUN TESTS | |
| # ------------------------------- | |
| - name: Run Unit Tests | |
| working-directory: app | |
| run: mvn -B test | |
| # ------------------------------- | |
| # TEST REPORT | |
| # ------------------------------- | |
| - name: Publish Test Report | |
| uses: dorny/test-reporter@v1 | |
| if: always() | |
| with: | |
| name: Maven Tests | |
| path: app/target/surefire-reports/*.xml | |
| reporter: java-junit | |
| # ------------------------------- | |
| # COVERAGE | |
| # ------------------------------- | |
| - name: Generate Coverage | |
| working-directory: app | |
| run: mvn jacoco:report | |
| - name: Upload Coverage Report | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: coverage-report | |
| path: app/target/site/jacoco | |
| # ------------------------------- | |
| # BUILD JAR | |
| # ------------------------------- | |
| - name: Build fat JAR | |
| working-directory: app | |
| run: | | |
| mvn -B clean package | |
| ls -lh target/*.jar | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: lambda-jar | |
| path: app/target/*.jar | |
| # ========================================================= | |
| # 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 |