Skip to content

Commit

Permalink
chore: Add gh action
Browse files Browse the repository at this point in the history
  • Loading branch information
andrea-putzu committed Nov 12, 2024
1 parent 0d5050d commit 3125503
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 18 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/call_integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
on:
workflow_call:
inputs:
environment:
type: string
required: true
short_env:
type: string
required: true
description: add '-pnpg' if workflow is related to pnpg

variables:
postmanEnvFile: integration_environment

# ${{ if eq(variables['Build.SourceBranch'], 'refs/heads/uat') }}:
# # selfHostedAgentPool: $(UAT_AGENT_POOL)


# ${{ else }}:
# # selfHostedAgentPool: $(DEV_AGENT_POOL)
# postmanEnvFile: integration_environment.json

stages:
- stage: stage_postman_test
environment: ${{ inputs.environment }}-ci
displayName: 'Test_e2e_on_${{ variables.environment }}'
dependsOn: [ stage_deploy ]
condition: and(succeeded(),or(eq(variables.environment, 'DEV'), eq(variables.environment, 'UAT')))
jobs:
- job: 'Run_Postman_collection_on_${{ variables.environment }}'
displayName: 'Run Postman collection on ${{ variables.environment }}'
# pool:
# name: $(selfHostedAgentPool)
steps:
- task: NodeTool@0
inputs:
versionSpec: '16.x'
- task: Npm@1
displayName: Install newman
inputs:
command: custom
customCommand: install -g newman
- task: DownloadSecureFile@1
displayName: 'download postman environment'
name: postman_env
inputs:
secureFile: $(postmanEnvFile)
- task: CmdLine@2
displayName: Run newman
continueOnError: true # Useful to avoid the skipping of result publishing task
inputs:
script: newman run selfcare-onboarding/test/newman/Selfcare-Integration.postman_collection.json -e $(postman_env.secureFilePath) --reporters cli,junit --reporter-junit-export result/test-result.xml
- task: PublishTestResults@2
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '**/test-*.xml'
searchFolder: '$(System.DefaultWorkingDirectory)/result/'
testRunTitle: 'Publish Newman Test Results'
# - task: 'Bash@3'
# displayName: 'Send message on Slack'
# condition: in(variables['Agent.JobStatus'], 'SucceededWithIssues', 'Failed')
# inputs:
# targetType: 'inline'
# script: >
# curl -X POST \
# -H "Content-type: application/json" \
# --data '{"text": "*Attention: There is an error in pipeline $(System.DefinitionName) in step _postman test_!*\nCheck the logs for more details $(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId) to view the build results."}' \
# $(SLACK_WEBHOOK_URL)

29 changes: 29 additions & 0 deletions .github/workflows/integration_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Integration test

on:
push:
branches:
- main
- releases/*

workflow_dispatch:
inputs:
env:
type: choice
description: Environment
options:
- dev
- uat

jobs:

test_dev:
uses: ./.github/workflows/call_integration_test.yml
name: '[Dev] Integration test'
if: ${{ (startsWith(github.ref_name, 'releases/') != true && inputs.env == null) || inputs.env == 'dev' }}
secrets: inherit
with:
environment: dev
short_env: d


64 changes: 64 additions & 0 deletions infra/test/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 8 additions & 15 deletions infra/test/integration_test.tf
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
resource "azurerm_resource_group" "onboarding_fn_rg" {
name = "${local.app_name}-rg"
location = var.location

tags = var.tags
}

data "azurerm_key_vault" "key_vault" {
resource_group_name = var.key_vault.resource_group_name
name = var.key_vault.name
}

data "azurerm_key_vault_secret" "apim_product_pn" {
name = "anac-ftp-known-host"
data "azurerm_key_vault_secret" "apim_product_pn_sk" {
name = "apim-product-pn-sk"
key_vault_id = data.azurerm_key_vault.key_vault.id
}

Expand Down Expand Up @@ -55,14 +48,14 @@ resource "github_actions_environment_secret" "integration_environment" {
repository = data.github_repository.repo.name
environment = github_repository_environment.repo_environment.environment
secret_name = "integration_environment"
encrypted_value = templatefile("Selfcare-Integration.postman_environment.json",
plaintext_value = base64encode(templatefile("Selfcare-Integration.postman_environment.json",
{
env = "${local.env_url}"
apimKeyPN = "ciao" //data.azurerm_key_vault_secret.apim_product_pn.value
})
apimKeyPN = data.azurerm_key_vault_secret.apim_product_pn_sk.value
}))
}


/*
data "azurerm_api_management" "apim" {
name = format("%s-apim-v2", local.project)
resource_group_name = format("%s-api-v2-rg", local.project)
Expand All @@ -80,10 +73,10 @@ data "azurerm_api_management_user" "admin" {
resource_group_name = data.azurerm_api_management.apim.resource_group_name
}
resource "azurerm_api_management_subscription" "example" {
resource "azurerm_api_management_subscription" "admin_product_pn" {
api_management_name = data.azurerm_api_management.apim.name
resource_group_name = data.azurerm_api_management.apim.resource_group_name
user_id = data.azurerm_api_management_user.admin.id
product_id = data.azurerm_api_management_product.product_pn.id
display_name = "Parser API"
}
}*/
3 changes: 1 addition & 2 deletions infra/test/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ locals {
pnpg_domain_suffix = var.is_pnpg == true ? "-weu-pnpg" : ""
pnpg_domain_vnet_suffix = var.is_pnpg == true ? "-weu" : ""
project = "${var.prefix}-${var.env_short}"
env_url = var.env_short == "p" ? "https://api.selfcare.pagopa.it" :
"https://api.${var.env}.selfcare.pagopa.it"
env_url = var.env_short == "p" ? "" : ".${var.env}"

app_name = "${local.project}${local.pnpg_suffix}-onboarding-fn"
base_domain_name = "${local.project}${local.pnpg_domain_suffix}"
Expand Down
2 changes: 1 addition & 1 deletion infra/test/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ variable "env" {
type = string
validation {
condition = (
length(var.env_short) <= 4
length(var.env) <= 4
)
error_message = "Max length is 4 chars."
}
Expand Down

0 comments on commit 3125503

Please sign in to comment.