Skip to content

Commit 511e26e

Browse files
Merge pull request #158 from pagopa/allure-integration-reports
feat: adding allure integration reports
2 parents 739ed1a + 36ec21c commit 511e26e

File tree

11 files changed

+648
-298
lines changed

11 files changed

+648
-298
lines changed

.github/workflows/code_review.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ jobs:
8383
8484
cd ./integration-test
8585
chmod +x ./run_integration_test.sh
86-
./run_integration_test.sh local
86+
./run_integration_test.sh local old
8787
8888
8989
delete_github_deployments:

.github/workflows/integration_test.yml

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ on:
1414
- dev
1515
- uat
1616
- prod
17+
allure:
18+
description: 'generate the allure report'
19+
required: false
20+
type: boolean
21+
default: false
1722
canary:
1823
description: 'run the tests on canary version'
1924
required: false
@@ -47,22 +52,62 @@ jobs:
4752
# from https://github.com/Azure/login/commits/master
4853
uses: azure/login@92a5484dfaf04ca78a94597f4f19fea633851fa2
4954
with:
50-
client-id: ${{ secrets.CD_CLIENT_ID }}
55+
client-id: ${{ secrets.CI_CLIENT_ID }}
5156
tenant-id: ${{ secrets.TENANT_ID }}
5257
subscription-id: ${{ secrets.SUBSCRIPTION_ID }}
5358

59+
- name: Delete old reports
60+
if: ${{ inputs.allure }}
61+
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
62+
env:
63+
STORAGE_NAME: ${{ vars.INTEGRATION_TEST_STORAGE_ACCOUNT_NAME }}
64+
STORAGE_FOLDER: ${{ vars.INTEGRATION_TEST_REPORTS_FOLDER }}
65+
with:
66+
inlineScript: |
67+
az storage blob delete-batch \
68+
--source "${{ env.STORAGE_FOLDER }}" \
69+
--account-name "${{ env.STORAGE_NAME }}" \
70+
--subscription "${{ secrets.SUBSCRIPTION_ID }}" \
71+
--auth-mode login
72+
5473
- name: Run Integration Tests
5574
shell: bash
5675
run: |
5776
export SUBKEY=${{ secrets.SUBKEY }}
5877
export CANARY=${{ inputs.canary }}
78+
export TYPE=$([ ${{ inputs.allure }} = true ] && echo "allure" || echo "old")
5979
export CUCUMBER_PUBLISH_TOKEN=${{ secrets.CUCUMBER_PUBLISH_TOKEN }}
6080
export ISSUER_RANGE_TABLE=${{ vars.ISSUER_RANGE_TABLE }}
6181
export AFM_SA_CONNECTION_STRING='${{ secrets.AFM_SA_CONNECTION_STRING }}'
6282
6383
cd ./integration-test
6484
chmod +x ./run_integration_test.sh
65-
./run_integration_test.sh ${{( github.event.inputs == null && 'dev') || inputs.environment }}
85+
./run_integration_test.sh ${{( github.event.inputs == null && 'dev') || inputs.environment }} $TYPE
86+
87+
- name: Generate allure report
88+
if: ${{ inputs.allure }}
89+
shell: bash
90+
run: |
91+
cd ./integration-test
92+
docker build -t afm-calculator-allure-report-generator .
93+
docker run \
94+
-v ./allure:/app/allure afm-calculator-allure-report-generator
95+
96+
- name: Upload reports
97+
if: ${{ inputs.allure }}
98+
uses: azure/CLI@4db43908b9df2e7ac93c8275a8f9a448c59338dd # v1
99+
env:
100+
STORAGE_NAME: ${{ vars.INTEGRATION_TEST_STORAGE_ACCOUNT_NAME }}
101+
STORAGE_FOLDER: ${{ vars.INTEGRATION_TEST_REPORTS_FOLDER }}
102+
with:
103+
inlineScript: |
104+
az storage blob upload-batch \
105+
--destination '${{ env.STORAGE_FOLDER }}/reports' \
106+
--source ./integration-test/allure/reports \
107+
--account-name ${{ env.STORAGE_NAME }} \
108+
--subscription ${{ secrets.SUBSCRIPTION_ID }} \
109+
--overwrite true \
110+
--auth-mode login
66111
67112
notify:
68113
needs: [ integration_test ]

.identity/00_data.tf

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ data "azurerm_user_assigned_identity" "identity_cd" {
33
name = "${local.product}-${local.domain}-01-github-cd-identity"
44
}
55

6+
data "azurerm_user_assigned_identity" "identity_ci" {
7+
count = var.env_short == "p" ? 0 : 1
8+
name = "${local.product}-${local.domain}-01-github-ci-identity"
9+
resource_group_name = "${local.product}-identity-rg"
10+
}
11+
612
data "azurerm_resource_group" "dashboards" {
713
name = "dashboards"
814
}
@@ -32,9 +38,9 @@ data "azurerm_key_vault_secret" "key_vault_sonar" {
3238
key_vault_id = data.azurerm_key_vault.key_vault.id
3339
}
3440

35-
data "azurerm_key_vault_secret" "key_vault_bot_token" {
36-
name = "bot-token-github"
37-
key_vault_id = data.azurerm_key_vault.key_vault.id
41+
data "azurerm_key_vault_secret" "key_vault_bot_cd_token" {
42+
name = "pagopa-platform-domain-github-bot-cd-pat"
43+
key_vault_id = data.azurerm_key_vault.domain_key_vault.id
3844
}
3945

4046
data "azurerm_key_vault_secret" "key_vault_cucumber_token" {

.identity/03_github_environment.tf

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ resource "github_repository_environment" "github_repository_environment" {
2222
locals {
2323
env_secrets = {
2424
"CD_CLIENT_ID" : data.azurerm_user_assigned_identity.identity_cd.client_id,
25+
"CI_CLIENT_ID" : var.env_short != "p" ? data.azurerm_user_assigned_identity.identity_ci[0].client_id : "",
2526
"TENANT_ID" : data.azurerm_client_config.current.tenant_id,
2627
"SUBSCRIPTION_ID" : data.azurerm_subscription.current.subscription_id,
2728
"ISSUER_RANGE_TABLE" : "${local.prefix}${var.env_short}${local.location_short}${local.domain}saissuerrangetable",
@@ -34,6 +35,13 @@ locals {
3435
"CLUSTER_RESOURCE_GROUP" : local.aks_cluster.resource_group_name,
3536
"DOMAIN" : local.domain,
3637
"NAMESPACE" : local.domain,
38+
"INTEGRATION_TEST_STORAGE_ACCOUNT_NAME" : local.integration_test.storage_account_name
39+
"INTEGRATION_TEST_REPORTS_FOLDER" : local.integration_test.reports_folder
40+
}
41+
repo_secrets = {
42+
"SONAR_TOKEN" : data.azurerm_key_vault_secret.key_vault_sonar.value,
43+
"BOT_TOKEN_GITHUB" : data.azurerm_key_vault_secret.key_vault_bot_cd_token.value,
44+
"CUCUMBER_PUBLISH_TOKEN" : data.azurerm_key_vault_secret.key_vault_cucumber_token.value
3745
}
3846
}
3947

@@ -66,25 +74,9 @@ resource "github_actions_environment_variable" "github_environment_runner_variab
6674
# Secrets of the Repository #
6775
#############################
6876

69-
#tfsec:ignore:github-actions-no-plain-text-action-secrets # not real secret
70-
resource "github_actions_secret" "secret_sonar_token" {
71-
repository = local.github.repository
72-
secret_name = "SONAR_TOKEN"
73-
plaintext_value = data.azurerm_key_vault_secret.key_vault_sonar.value
74-
}
75-
76-
#tfsec:ignore:github-actions-no-plain-text-action-secrets # not real secret
77-
resource "github_actions_secret" "secret_bot_token" {
78-
79-
repository = local.github.repository
80-
secret_name = "BOT_TOKEN_GITHUB"
81-
plaintext_value = data.azurerm_key_vault_secret.key_vault_bot_token.value
82-
}
83-
84-
#tfsec:ignore:github-actions-no-plain-text-action-secrets # not real secret
85-
resource "github_actions_secret" "secret_cucumber_token" {
86-
77+
resource "github_actions_secret" "repo_secrets" {
78+
for_each = local.repo_secrets
8779
repository = local.github.repository
88-
secret_name = "CUCUMBER_PUBLISH_TOKEN"
89-
plaintext_value = data.azurerm_key_vault_secret.key_vault_cucumber_token.value
90-
}
80+
secret_name = each.key
81+
plaintext_value = each.value
82+
}

.identity/99_variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ locals {
1111

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

14+
integration_test = {
15+
storage_account_name = "${local.prefix}${var.env_short}${local.location_short}sharedtstdtsa"
16+
storage_account_rg = "${local.prefix}-${var.env_short}-${local.location_short}-shared-tst-dt-rg"
17+
reports_folder = local.github.repository
18+
}
19+
1420
aks_cluster = {
1521
name = "${local.product}-${local.location_short}-${var.env}-aks"
1622
resource_group_name = "${local.product}-${local.location_short}-${var.env}-aks-rg"

integration-test/Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
FROM alpine:latest
2+
3+
ARG ALLURE_RELEASE=2.25.0
4+
ARG ALLURE_REPO=https://repo.maven.apache.org/maven2/io/qameta/allure/allure-commandline
5+
COPY generate_allure_report.sh generate_allure_report.sh
6+
7+
RUN apk update && \
8+
apk add ca-certificates && \
9+
update-ca-certificates && \
10+
apk add openssl && \
11+
apk add unzip && \
12+
apk add --no-cache openjdk8-jre-base
13+
14+
RUN wget ${ALLURE_REPO}/${ALLURE_RELEASE}/allure-commandline-${ALLURE_RELEASE}.tgz -O allure-commandline.tgz
15+
RUN tar -zxvf allure-commandline.tgz -C /opt/
16+
RUN ln -s /opt/allure-${ALLURE_RELEASE}/bin/allure /usr/bin/allure
17+
RUN rm allure-commandline.tgz
18+
19+
RUN allure --version
20+
CMD ["sh", "generate_allure_report.sh"]
21+
22+
23+
24+
25+
26+

integration-test/README.MD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ If you use dev, uat or prod **you test the images on Azure ACR**
2121
sh ./run_integration_test.sh local
2222
```
2323

24+
## Allure report
25+
26+
It is possible to check the latest report for these integration tests at the following link:
27+
🔗 [Report with Allure](https://pagopadweusharedtstdtsa.blob.core.windows.net/pagopa-afm-calculator/reports/index.html)
28+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# generate allure report
4+
allure generate /app/allure/results -o /app/allure/reports --clean
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#!/bin/bash
22

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

6+
ENVIRONMENT=$1
7+
TYPE=$2
8+
69
# run integration tests
710
cd ./src || exit
811
yarn install
912
yarn add @azure/data-tables
10-
yarn test:"$1"
13+
yarn test-"$TYPE":"$ENVIRONMENT"

integration-test/src/package.json

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
"license": "MIT",
44
"version": "1.0.0",
55
"scripts": {
6-
"test:local": "dotenv -e ./config/.env.local yarn cucumber",
7-
"test:dev": "dotenv -e ./config/.env.dev yarn cucumber",
8-
"test:uat": "dotenv -e ./config/.env.uat yarn cucumber",
9-
"test:prod": "dotenv -e ./config/.env.prod yarn cucumber",
10-
"cucumber": "npx cucumber-js --publish -r step_definitions"
6+
"test-old:local": "dotenv -e ./config/.env.local yarn cucumber",
7+
"test-old:dev": "dotenv -e ./config/.env.dev yarn cucumber",
8+
"test-allure:dev": "dotenv -e ./config/.env.dev yarn cucumber-allure",
9+
"test-old:uat": "dotenv -e ./config/.env.uat yarn cucumber",
10+
"cucumber": "npx cucumber-js --publish -r step_definitions",
11+
"cucumber-allure": "npx cucumber-js --publish -r step_definitions --format allure-cucumberjs/reporter --format-options '{ \"resultsDir\": \"../allure/results\" }'"
1112
},
1213
"dependencies": {
13-
"@azure/data-tables": "^13.2.2",
14-
"@cucumber/cucumber": "^8.4.0",
14+
"@azure/data-tables": "^13.3.0",
15+
"@cucumber/cucumber": "^11.2.0",
16+
"@cucumber/messages": "^27.0.2",
17+
"allure-cucumberjs": "^3.0.9",
18+
"allure-js-commons": "^3.0.9",
1519
"axios": "^0.28.0",
1620
"dotenv": "^16.0.2",
1721
"dotenv-cli": "^3.2.0",

0 commit comments

Comments
 (0)