Skip to content

Commit

Permalink
Merge pull request #158 from pagopa/allure-integration-reports
Browse files Browse the repository at this point in the history
feat: adding allure integration reports
  • Loading branch information
FedericoRuzzier authored Feb 4, 2025
2 parents 739ed1a + 36ec21c commit 511e26e
Show file tree
Hide file tree
Showing 11 changed files with 648 additions and 298 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
cd ./integration-test
chmod +x ./run_integration_test.sh
./run_integration_test.sh local
./run_integration_test.sh local old
delete_github_deployments:
Expand Down
49 changes: 47 additions & 2 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ on:
- dev
- uat
- prod
allure:
description: 'generate the allure report'
required: false
type: boolean
default: false
canary:
description: 'run the tests on canary version'
required: false
Expand Down Expand Up @@ -47,22 +52,62 @@ jobs:
# from https://github.com/Azure/login/commits/master
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
with:
client-id: ${{ secrets.CD_CLIENT_ID }}
client-id: ${{ secrets.CI_CLIENT_ID }}
tenant-id: ${{ secrets.TENANT_ID }}
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}

- name: Delete old reports
if: ${{ inputs.allure }}
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
env:
STORAGE_NAME: ${{ vars.INTEGRATION_TEST_STORAGE_ACCOUNT_NAME }}
STORAGE_FOLDER: ${{ vars.INTEGRATION_TEST_REPORTS_FOLDER }}
with:
inlineScript: |
az storage blob delete-batch \
--source "${{ env.STORAGE_FOLDER }}" \
--account-name "${{ env.STORAGE_NAME }}" \
--subscription "${{ secrets.SUBSCRIPTION_ID }}" \
--auth-mode login
- name: Run Integration Tests
shell: bash
run: |
export SUBKEY=${{ secrets.SUBKEY }}
export CANARY=${{ inputs.canary }}
export TYPE=$([ ${{ inputs.allure }} = true ] && echo "allure" || echo "old")
export CUCUMBER_PUBLISH_TOKEN=${{ secrets.CUCUMBER_PUBLISH_TOKEN }}
export ISSUER_RANGE_TABLE=${{ vars.ISSUER_RANGE_TABLE }}
export AFM_SA_CONNECTION_STRING='${{ secrets.AFM_SA_CONNECTION_STRING }}'
cd ./integration-test
chmod +x ./run_integration_test.sh
./run_integration_test.sh ${{( github.event.inputs == null && 'dev') || inputs.environment }}
./run_integration_test.sh ${{( github.event.inputs == null && 'dev') || inputs.environment }} $TYPE
- name: Generate allure report
if: ${{ inputs.allure }}
shell: bash
run: |
cd ./integration-test
docker build -t afm-calculator-allure-report-generator .
docker run \
-v ./allure:/app/allure afm-calculator-allure-report-generator
- name: Upload reports
if: ${{ inputs.allure }}
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
env:
STORAGE_NAME: ${{ vars.INTEGRATION_TEST_STORAGE_ACCOUNT_NAME }}
STORAGE_FOLDER: ${{ vars.INTEGRATION_TEST_REPORTS_FOLDER }}
with:
inlineScript: |
az storage blob upload-batch \
--destination '${{ env.STORAGE_FOLDER }}/reports' \
--source ./integration-test/allure/reports \
--account-name ${{ env.STORAGE_NAME }} \
--subscription ${{ secrets.SUBSCRIPTION_ID }} \
--overwrite true \
--auth-mode login
notify:
needs: [ integration_test ]
Expand Down
12 changes: 9 additions & 3 deletions .identity/00_data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ data "azurerm_user_assigned_identity" "identity_cd" {
name = "${local.product}-${local.domain}-01-github-cd-identity"
}

data "azurerm_user_assigned_identity" "identity_ci" {
count = var.env_short == "p" ? 0 : 1
name = "${local.product}-${local.domain}-01-github-ci-identity"
resource_group_name = "${local.product}-identity-rg"
}

data "azurerm_resource_group" "dashboards" {
name = "dashboards"
}
Expand Down Expand Up @@ -32,9 +38,9 @@ data "azurerm_key_vault_secret" "key_vault_sonar" {
key_vault_id = data.azurerm_key_vault.key_vault.id
}

data "azurerm_key_vault_secret" "key_vault_bot_token" {
name = "bot-token-github"
key_vault_id = data.azurerm_key_vault.key_vault.id
data "azurerm_key_vault_secret" "key_vault_bot_cd_token" {
name = "pagopa-platform-domain-github-bot-cd-pat"
key_vault_id = data.azurerm_key_vault.domain_key_vault.id
}

data "azurerm_key_vault_secret" "key_vault_cucumber_token" {
Expand Down
34 changes: 13 additions & 21 deletions .identity/03_github_environment.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "github_repository_environment" "github_repository_environment" {
locals {
env_secrets = {
"CD_CLIENT_ID" : data.azurerm_user_assigned_identity.identity_cd.client_id,
"CI_CLIENT_ID" : var.env_short != "p" ? data.azurerm_user_assigned_identity.identity_ci[0].client_id : "",
"TENANT_ID" : data.azurerm_client_config.current.tenant_id,
"SUBSCRIPTION_ID" : data.azurerm_subscription.current.subscription_id,
"ISSUER_RANGE_TABLE" : "${local.prefix}${var.env_short}${local.location_short}${local.domain}saissuerrangetable",
Expand All @@ -34,6 +35,13 @@ locals {
"CLUSTER_RESOURCE_GROUP" : local.aks_cluster.resource_group_name,
"DOMAIN" : local.domain,
"NAMESPACE" : local.domain,
"INTEGRATION_TEST_STORAGE_ACCOUNT_NAME" : local.integration_test.storage_account_name
"INTEGRATION_TEST_REPORTS_FOLDER" : local.integration_test.reports_folder
}
repo_secrets = {
"SONAR_TOKEN" : data.azurerm_key_vault_secret.key_vault_sonar.value,
"BOT_TOKEN_GITHUB" : data.azurerm_key_vault_secret.key_vault_bot_cd_token.value,
"CUCUMBER_PUBLISH_TOKEN" : data.azurerm_key_vault_secret.key_vault_cucumber_token.value
}
}

Expand Down Expand Up @@ -66,25 +74,9 @@ resource "github_actions_environment_variable" "github_environment_runner_variab
# Secrets of the Repository #
#############################

#tfsec:ignore:github-actions-no-plain-text-action-secrets # not real secret
resource "github_actions_secret" "secret_sonar_token" {
repository = local.github.repository
secret_name = "SONAR_TOKEN"
plaintext_value = data.azurerm_key_vault_secret.key_vault_sonar.value
}

#tfsec:ignore:github-actions-no-plain-text-action-secrets # not real secret
resource "github_actions_secret" "secret_bot_token" {

repository = local.github.repository
secret_name = "BOT_TOKEN_GITHUB"
plaintext_value = data.azurerm_key_vault_secret.key_vault_bot_token.value
}

#tfsec:ignore:github-actions-no-plain-text-action-secrets # not real secret
resource "github_actions_secret" "secret_cucumber_token" {

resource "github_actions_secret" "repo_secrets" {
for_each = local.repo_secrets
repository = local.github.repository
secret_name = "CUCUMBER_PUBLISH_TOKEN"
plaintext_value = data.azurerm_key_vault_secret.key_vault_cucumber_token.value
}
secret_name = each.key
plaintext_value = each.value
}
6 changes: 6 additions & 0 deletions .identity/99_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ locals {

app_name = "github-${local.github.org}-${local.github.repository}-${var.prefix}-${local.domain}-${var.env}-aks"

integration_test = {
storage_account_name = "${local.prefix}${var.env_short}${local.location_short}sharedtstdtsa"
storage_account_rg = "${local.prefix}-${var.env_short}-${local.location_short}-shared-tst-dt-rg"
reports_folder = local.github.repository
}

aks_cluster = {
name = "${local.product}-${local.location_short}-${var.env}-aks"
resource_group_name = "${local.product}-${local.location_short}-${var.env}-aks-rg"
Expand Down
26 changes: 26 additions & 0 deletions integration-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM alpine:latest

ARG ALLURE_RELEASE=2.25.0
ARG ALLURE_REPO=https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline
COPY generate_allure_report.sh generate_allure_report.sh

RUN apk update && \
apk add ca-certificates && \
update-ca-certificates && \
apk add openssl && \
apk add unzip && \
apk add --no-cache openjdk8-jre-base

RUN wget ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.tgz -O allure-commandline.tgz
RUN tar -zxvf allure-commandline.tgz -C /opt/
RUN ln -s /opt/allure-${ALLURE_RELEASE}/bin/allure /usr/bin/allure
RUN rm allure-commandline.tgz

RUN allure --version
CMD ["sh", "generate_allure_report.sh"]






5 changes: 5 additions & 0 deletions integration-test/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ If you use dev, uat or prod **you test the images on Azure ACR**
sh ./run_integration_test.sh local
```

## Allure report

It is possible to check the latest report for these integration tests at the following link:
🔗 [Report with Allure](https://pagopadweusharedtstdtsa.blob.core.windows.net/pagopa-afm-calculator/reports/index.html)

4 changes: 4 additions & 0 deletions integration-test/generate_allure_report.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

# generate allure report
allure generate /app/allure/results -o /app/allure/reports --clean
7 changes: 5 additions & 2 deletions integration-test/run_integration_test.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/bash

# example: sh ./run_integration_test.sh <local|dev|uat|prod>
# example: sh ./run_integration_test.sh <local|dev|uat|prod> <old|allure>
set -e

ENVIRONMENT=$1
TYPE=$2

# run integration tests
cd ./src || exit
yarn install
yarn add @azure/data-tables
yarn test:"$1"
yarn test-"$TYPE":"$ENVIRONMENT"
18 changes: 11 additions & 7 deletions integration-test/src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
"license": "MIT",
"version": "1.0.0",
"scripts": {
"test:local": "dotenv -e ./config/.env.local yarn cucumber",
"test:dev": "dotenv -e ./config/.env.dev yarn cucumber",
"test:uat": "dotenv -e ./config/.env.uat yarn cucumber",
"test:prod": "dotenv -e ./config/.env.prod yarn cucumber",
"cucumber": "npx cucumber-js --publish -r step_definitions"
"test-old:local": "dotenv -e ./config/.env.local yarn cucumber",
"test-old:dev": "dotenv -e ./config/.env.dev yarn cucumber",
"test-allure:dev": "dotenv -e ./config/.env.dev yarn cucumber-allure",
"test-old:uat": "dotenv -e ./config/.env.uat yarn cucumber",
"cucumber": "npx cucumber-js --publish -r step_definitions",
"cucumber-allure": "npx cucumber-js --publish -r step_definitions --format allure-cucumberjs/reporter --format-options '{ \"resultsDir\": \"../allure/results\" }'"
},
"dependencies": {
"@azure/data-tables": "^13.2.2",
"@cucumber/cucumber": "^8.4.0",
"@azure/data-tables": "^13.3.0",
"@cucumber/cucumber": "^11.2.0",
"@cucumber/messages": "^27.0.2",
"allure-cucumberjs": "^3.0.9",
"allure-js-commons": "^3.0.9",
"axios": "^0.28.0",
"dotenv": "^16.0.2",
"dotenv-cli": "^3.2.0",
Expand Down
Loading

0 comments on commit 511e26e

Please sign in to comment.