From 614a608f7fda617c856d8641b345614db8d9c135 Mon Sep 17 00:00:00 2001 From: Sean Fern Date: Wed, 31 Jan 2024 10:26:27 -0500 Subject: [PATCH] PLT-311 Add unit test workflow for opt-out-import (#78) --- .../workflows/opt-out-import-deploy-dev.yml | 27 ++++++--------- .../workflows/opt-out-import-deploy-prod.yml | 7 ++-- .../workflows/opt-out-import-deploy-sbx.yml | 7 ++-- .../workflows/opt-out-import-deploy-test.yml | 27 ++++++--------- .../workflows/opt-out-import-test-unit.yml | 33 +++++++++++++++++++ 5 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/opt-out-import-test-unit.yml diff --git a/.github/workflows/opt-out-import-deploy-dev.yml b/.github/workflows/opt-out-import-deploy-dev.yml index 6c48278..cef4d0f 100644 --- a/.github/workflows/opt-out-import-deploy-dev.yml +++ b/.github/workflows/opt-out-import-deploy-dev.yml @@ -1,4 +1,4 @@ -name: Build and deploy opt-out-import to dev +name: opt-out-import dev deploy on: workflow_dispatch: @@ -7,19 +7,16 @@ jobs: deploy: runs-on: self-hosted environment: dev - + defaults: + run: + working-directory: ./optout steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up JDK - uses: actions/setup-java@v3 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' - - - name: Set env vars from AWS params - uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main + - uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main env: AWS_REGION: ${{ vars.AWS_REGION }} with: @@ -27,17 +24,13 @@ jobs: ARTIFACTORY_URL=/artifactory/url ARTIFACTORY_USER=/artifactory/user ARTIFACTORY_PASSWORD=/artifactory/password - - name: Build opt-out-import zip file - run: ./gradlew buildZip -b optout/build.gradle --console=plain - - - name: Assume role in target account - uses: aws-actions/configure-aws-credentials@v3 + run: ../gradlew buildZip + - uses: aws-actions/configure-aws-credentials@v3 with: aws-region: ${{ vars.AWS_REGION }} role-to-assume: ${{ vars.ACCOUNT_ROLE }} - - name: Upload and reload run: | - aws s3 cp --no-progress optout/build/distributions/optout.zip s3://${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }}/function.zip + aws s3 cp --no-progress build/distributions/optout.zip s3://${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }}/function.zip aws lambda update-function-code --function-name ab2d-dev-opt-out-import --s3-bucket ${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }} --s3-key function.zip diff --git a/.github/workflows/opt-out-import-deploy-prod.yml b/.github/workflows/opt-out-import-deploy-prod.yml index 7a2937a..ad48335 100644 --- a/.github/workflows/opt-out-import-deploy-prod.yml +++ b/.github/workflows/opt-out-import-deploy-prod.yml @@ -1,4 +1,4 @@ -name: Deploy opt-out-import to prod +name: opt-out-import prod deploy on: workflow_dispatch: @@ -10,14 +10,11 @@ jobs: id-token: write runs-on: ubuntu-latest environment: prod - steps: - - name: Assume role in target account - uses: aws-actions/configure-aws-credentials@v3 + - uses: aws-actions/configure-aws-credentials@v3 with: aws-region: ${{ vars.AWS_REGION }} role-to-assume: ${{ vars.ACCOUNT_ROLE }} - - name: Promote lambda code from test to prod run: | aws s3 cp --no-progress s3://${{ vars.OPT_OUT_IMPORT_TEST_ZIP_BUCKET }}/function.zip s3://${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }}/function.zip diff --git a/.github/workflows/opt-out-import-deploy-sbx.yml b/.github/workflows/opt-out-import-deploy-sbx.yml index 2827c3d..71973ed 100644 --- a/.github/workflows/opt-out-import-deploy-sbx.yml +++ b/.github/workflows/opt-out-import-deploy-sbx.yml @@ -1,4 +1,4 @@ -name: Deploy opt-out-import to sbx (sandbox) +name: opt-out-import sbx (sandbox) deploy on: workflow_dispatch: @@ -10,14 +10,11 @@ jobs: id-token: write runs-on: ubuntu-latest environment: sbx - steps: - - name: Assume role in target account - uses: aws-actions/configure-aws-credentials@v3 + - uses: aws-actions/configure-aws-credentials@v3 with: aws-region: ${{ vars.AWS_REGION }} role-to-assume: ${{ vars.ACCOUNT_ROLE }} - - name: Promote lambda code from test to sbx run: | aws s3 cp --no-progress s3://${{ vars.OPT_OUT_IMPORT_TEST_ZIP_BUCKET }}/function.zip s3://${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }}/function.zip diff --git a/.github/workflows/opt-out-import-deploy-test.yml b/.github/workflows/opt-out-import-deploy-test.yml index 0dc8853..fe5b01f 100644 --- a/.github/workflows/opt-out-import-deploy-test.yml +++ b/.github/workflows/opt-out-import-deploy-test.yml @@ -1,4 +1,4 @@ -name: Build and deploy opt-out-import to test (impl) +name: opt-out-import test (impl) deploy on: push: @@ -12,19 +12,16 @@ jobs: deploy: runs-on: self-hosted environment: test - + defaults: + run: + working-directory: ./optout steps: - - name: Checkout code - uses: actions/checkout@v3 - - - name: Set up JDK - uses: actions/setup-java@v3 + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 with: java-version: '17' distribution: 'temurin' - - - name: Set env vars from AWS params - uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main + - uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main env: AWS_REGION: ${{ vars.AWS_REGION }} with: @@ -32,17 +29,13 @@ jobs: ARTIFACTORY_URL=/artifactory/url ARTIFACTORY_USER=/artifactory/user ARTIFACTORY_PASSWORD=/artifactory/password - - name: Build opt-out-import zip file - run: ./gradlew buildZip -b optout/build.gradle --console=plain - - - name: Assume role in target account - uses: aws-actions/configure-aws-credentials@v3 + run: ../gradlew buildZip + - uses: aws-actions/configure-aws-credentials@v3 with: aws-region: ${{ vars.AWS_REGION }} role-to-assume: ${{ vars.ACCOUNT_ROLE }} - - name: Upload and reload run: | - aws s3 cp --no-progress optout/build/distributions/optout.zip s3://${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }}/function.zip + aws s3 cp --no-progress build/distributions/optout.zip s3://${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }}/function.zip aws lambda update-function-code --function-name ab2d-test-opt-out-import --s3-bucket ${{ vars.OPT_OUT_IMPORT_ZIP_BUCKET }} --s3-key function.zip diff --git a/.github/workflows/opt-out-import-test-unit.yml b/.github/workflows/opt-out-import-test-unit.yml new file mode 100644 index 0000000..475cf0b --- /dev/null +++ b/.github/workflows/opt-out-import-test-unit.yml @@ -0,0 +1,33 @@ +name: opt-out-import unit tests + +on: + pull_request: + paths: + - .github/workflows/opt-out-import-test-unit.yml + - optout/** + workflow_dispatch: + +jobs: + test: + runs-on: self-hosted + defaults: + run: + working-directory: ./optout + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + - uses: cmsgov/ab2d-bcda-dpc-platform/actions/aws-params-env-action@main + env: + AWS_REGION: ${{ vars.AWS_REGION }} + with: + params: | + ARTIFACTORY_URL=/artifactory/url + ARTIFACTORY_USER=/artifactory/user + ARTIFACTORY_PASSWORD=/artifactory/password + SONAR_HOST_URL=/sonarqube/url + SONAR_TOKEN=/sonarqube/token + - name: Run unit tests for opt-out-import lambda + run: ../gradlew test