From ed19e10c49d5b07521502420ab4cb054abd38a0e Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 15:49:42 +0200 Subject: [PATCH 01/16] added release and code_review --- .devops/deploy-pipelines.yml | 170 ------------------ .github/workflows/anchore.yml | 52 ------ .github/workflows/code-review.yml | 49 +++++ .../workflows/pr-title-linter-and-linker.yaml | 18 -- .github/workflows/release.yml | 39 ++++ Ping/function.json | 20 --- Ping/handler.ts | 32 ---- Ping/index.ts | 22 --- 8 files changed, 88 insertions(+), 314 deletions(-) delete mode 100644 .devops/deploy-pipelines.yml delete mode 100644 .github/workflows/anchore.yml create mode 100644 .github/workflows/code-review.yml delete mode 100644 .github/workflows/pr-title-linter-and-linker.yaml create mode 100644 .github/workflows/release.yml delete mode 100644 Ping/function.json delete mode 100644 Ping/handler.ts delete mode 100644 Ping/index.ts diff --git a/.devops/deploy-pipelines.yml b/.devops/deploy-pipelines.yml deleted file mode 100644 index a8ed4b19..00000000 --- a/.devops/deploy-pipelines.yml +++ /dev/null @@ -1,170 +0,0 @@ -# Azure DevOps pipeline to release a new version and deploy to production. - -variables: - NAMESPACE: "$(TF_NAMESPACE)" - DOCKER_IMAGE_NAME: "$(TF_DOCKER_IMAGE_NAME)" - CONTAINER_REGISTRY_FQDN_PROD: "$(TF_CONTAINER_REGISTRY_FQDN_PROD)" - CONTAINER_REGISTRY_SERVICE_CONN_PROD: "$(TF_CONTAINER_REGISTRY_SERVICE_CONN_PROD)" - KUBERNETES_SERVICE_CONN_WEU_BETA: "$(TF_KUBERNETES_SERVICE_CONN_WEU_BETA)" - KUBERNETES_SERVICE_CONN_WEU_PROD_01: "$(TF_KUBERNETES_SERVICE_CONN_WEU_PROD_01)" - KUBERNETES_SERVICE_CONN_WEU_PROD_02: "$(TF_KUBERNETES_SERVICE_CONN_WEU_PROD_02)" - APPINSIGHTS_SERVICE_CONN_PROD: "$(TF_APPINSIGHTS_SERVICE_CONN_PROD)" - APPINSIGHTS_RESOURCE_ID_PROD: "$(TF_APPINSIGHTS_RESOURCE_ID_PROD)" - -parameters: - - name: "RELEASE_SEMVER" - displayName: "When packing a release, define the version bump to apply" - type: string - values: - - major - - minor - - patch - default: minor - - name: "FORCE_REPLACE_DOCKER_IMAGE" - displayName: "Force the existing docker image to be replaced" - type: boolean - default: False - values: - - False - - True - - name: "SKIP_RELEASE" - displayName: "Skip release" - type: boolean - default: False - values: - - False - - True - - name: "ENVIRONMENT_WEU_BETA" - displayName: "Deploy to weu-beta" - type: boolean - default: True - values: - - False - - True - - name: "ENVIRONMENT_WEU_PROD_01" - displayName: "Deploy to weu-prod-01" - type: boolean - default: True - values: - - False - - True - - name: "ENVIRONMENT_WEU_PROD_02" - displayName: "Deploy to weu-prod-02" - type: boolean - default: False - values: - - False - - True - -# Only manual activations are intended -trigger: none -pr: none - -resources: - repositories: - - repository: pagopaCommons - type: github - name: pagopa/azure-pipeline-templates - ref: refs/tags/v2.10.1 - endpoint: "azure-devops-github-ro-payments" - -pool: - vmImage: "ubuntu-latest" - -stages: - # Release - - stage: Release - jobs: - - job: make_release - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - steps: - - ${{ if eq(parameters['SKIP_RELEASE'], False) }}: - - template: templates/node-job-setup/template.yaml@pagopaCommons - parameters: - persistCredentials: true - - template: templates/node-github-release/template.yaml@pagopaCommons - parameters: - semver: "${{ parameters.RELEASE_SEMVER }}" - gitEmail: $(GIT_EMAIL) - gitUsername: $(GIT_USERNAME) - gitHubConnection: $(GITHUB_CONNECTION) - release_branch: master - - ${{ if eq(parameters['SKIP_RELEASE'], True) }}: - - template: templates/node-github-current-version/template.yaml@pagopaCommons - - job: branch_version - condition: and(succeeded(), ne(variables['Build.SourceBranch'], 'refs/heads/master')) - steps: - - template: templates/node-github-current-version/template.yaml@pagopaCommons - - job: tag_version - condition: and(succeeded(), startsWith(variables['Build.SourceBranch'], 'refs/tags')) - steps: - - template: templates/node-github-current-version/template.yaml@pagopaCommons - - # Build - - stage: Build - dependsOn: Release - variables: - next_version: $[ stageDependencies.Release.make_release.outputs['next_version.value'] ] - current_version: $[ stageDependencies.Release.make_release.outputs['current_version.value'] ] - current_version_branch: $[ stageDependencies.Release.branch_version.outputs['current_version.value'] ] - current_version_tag: $[ stageDependencies.Release.tag_version.outputs['current_version.value'] ] - jobs: - - job: "build" - steps: - - template: templates/deploy-release-decision/template.yaml@pagopaCommons - parameters: - NEXT_VERSION: $(next_version) - CURRENT_VERSION: $(current_version) - CURRENT_VERSION_BRANCH: $(current_version_branch) - CURRENT_VERSION_TAG: $(current_version_tag) - BUILD_SOURCE_VERSION: $(Build.SourceVersion) - BUILD_SOURCE_BRANCH_NAME: $(Build.SourceBranchName) - - template: templates/docker-release/template.yaml@pagopaCommons - parameters: - CONTAINER_REGISTRY_SERVICE_CONN: $(CONTAINER_REGISTRY_SERVICE_CONN_PROD) - CONTAINER_REGISTRY_FQDN: $(CONTAINER_REGISTRY_FQDN_PROD) - DOCKER_IMAGE_NAME: $(DOCKER_IMAGE_NAME) - DOCKER_IMAGE_TAG: $(deploy_version_decision.value) - FORCE_REPLACE_DOCKER_IMAGE: ${{ parameters.FORCE_REPLACE_DOCKER_IMAGE }} - - # Deploy - - stage: "Deploy" - dependsOn: "Build" - variables: - deploy_version: $[ stageDependencies.Build.build.outputs['deploy_version_decision.value'] ] - jobs: - - deployment: "deploy" - pool: - name: io-prod-linux - environment: PROD - strategy: - runOnce: - deploy: - steps: - - checkout: self - displayName: "Checkout" - - template: templates/helm-microservice-chart-setup/template.yaml@pagopaCommons - parameters: - DEPLOY_VERSION: $(deploy_version) - - template: templates/helm-microservice-chart-deploy/template.yaml@pagopaCommons - parameters: - DO_DEPLOY: ${{ parameters.ENVIRONMENT_WEU_BETA }} - ENV: BETA - KUBERNETES_SERVICE_CONN: ${{ variables.KUBERNETES_SERVICE_CONN_WEU_BETA }} - NAMESPACE: $(NAMESPACE) - APP_NAME: $(DOCKER_IMAGE_NAME) - VALUE_FILE: "helm/values-beta.yaml" - DEPLOY_VERSION: $(deploy_version) - APPINSIGHTS_SERVICE_CONN: ${{ variables.APPINSIGHTS_SERVICE_CONN_PROD }} - APPINSIGHTS_RESOURCE_ID: ${{ variables.APPINSIGHTS_RESOURCE_ID_PROD }} - - template: templates/helm-microservice-chart-deploy/template.yaml@pagopaCommons - parameters: - DO_DEPLOY: ${{ parameters.ENVIRONMENT_WEU_PROD_01 }} - ENV: PROD_01 - KUBERNETES_SERVICE_CONN: ${{ variables.KUBERNETES_SERVICE_CONN_WEU_PROD_01 }} - NAMESPACE: $(NAMESPACE) - APP_NAME: $(DOCKER_IMAGE_NAME) - VALUE_FILE: "helm/values-prod01.yaml" - DEPLOY_VERSION: $(deploy_version) - APPINSIGHTS_SERVICE_CONN: ${{ variables.APPINSIGHTS_SERVICE_CONN_PROD }} - APPINSIGHTS_RESOURCE_ID: ${{ variables.APPINSIGHTS_RESOURCE_ID_PROD }} diff --git a/.github/workflows/anchore.yml b/.github/workflows/anchore.yml deleted file mode 100644 index 3f7246b0..00000000 --- a/.github/workflows/anchore.yml +++ /dev/null @@ -1,52 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -# This workflow checks out code, builds an image, performs a container image -# vulnerability scan with Anchore's Grype tool, and integrates the results with GitHub Advanced Security -# code scanning feature. For more information on the Anchore scan action usage -# and parameters, see https://github.com/anchore/scan-action. For more -# information on Anchore's container image scanning tool Grype, see -# https://github.com/anchore/grype -name: Anchore Container Scan - -on: - push: - branches: ["master", "main"] - pull_request: - # The branches below must be a subset of the branches above - branches: ["master", "main"] - schedule: - - cron: "00 07 * * *" - -permissions: - contents: read - -env: - DOCKERFILE: Dockerfile - -jobs: - Anchore-Build-Scan: - permissions: - contents: read # for actions/checkout to fetch code - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results - actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status - runs-on: ubuntu-latest - steps: - - name: Checkout the code - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file ${{ env.DOCKERFILE }} --tag localbuild/testimage:latest - - name: Run the Anchore scan action itself with GitHub Advanced Security code scanning integration enabled - uses: anchore/scan-action@v3 - with: - image: "localbuild/testimage:latest" - acs-report-enable: true - fail-build: true - severity-cutoff: "high" - - name: Upload Anchore Scan Report - uses: github/codeql-action/upload-sarif@v2 - if: always() - with: - sarif_file: results.sarif diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml new file mode 100644 index 00000000..edd8da29 --- /dev/null +++ b/.github/workflows/code-review.yml @@ -0,0 +1,49 @@ +name: "Code Review" + +on: + push: + branches: ["main"] + paths: + - apps/** + - packages/** + pull_request: + types: [opened, synchronize] + paths: + - apps/** + - packages/** + workflow_dispatch: {} + +jobs: + code_review: + timeout-minutes: 10 # temp fix + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Build app + uses: ./.github/actions/node-yarn + + - name: Lint + run: yarn lint + shell: bash + + - name: Validate Openapi Specs + run: | + npx oval validate -p openapi/index.yaml + npx oval validate -p openapi/index_external.yaml + shell: bash + + - name: Unit Tests + run: | + yarn generate + yarn test:coverage + bash <(curl -s https://codecov.io/bash) + shell: bash + + + + + + \ No newline at end of file diff --git a/.github/workflows/pr-title-linter-and-linker.yaml b/.github/workflows/pr-title-linter-and-linker.yaml deleted file mode 100644 index 920813bd..00000000 --- a/.github/workflows/pr-title-linter-and-linker.yaml +++ /dev/null @@ -1,18 +0,0 @@ -name: "Lint and Link PR title" - -on: - pull_request: - types: - - opened - - edited - - reopened - - synchronize - -jobs: - lint: - name: Validate PR title And link Jira Issue - runs-on: ubuntu-22.04 - steps: - - id: lint - # from https://github.com/pagopa/link-jira-issue-action/commits/main - uses: pagopa/link-jira-issue-action@37d5e40820eddd388864905bee9c45ef50cc7453 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..f621741b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release + +on: + # Trigger the workflow on push on the main branch + push: + branches: + - main + paths-ignore: + - 'CODEOWNERS' + - '**.md' + - '.**' + # Trigger the workflow by dispatching + workflow_dispatch: + +jobs: + release: + name: Release + runs-on: ubuntu-22.04 + + steps: + - name: Checkout + id: checkout + # from https://github.com/actions/checkout/commits/main + uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Release + id: release + # from https://github.com/cycjimmy/semantic-release-action/commits/main + uses: cycjimmy/semantic-release-action@bdd914ff2423e2792c73475f11e8da603182f32d + with: + semantic_version: 18.0.0 + extra_plugins: | + @semantic-release/release-notes-generator@10.0.3 + @semantic-release/git@10.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Ping/function.json b/Ping/function.json deleted file mode 100644 index 226e75e9..00000000 --- a/Ping/function.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "route": "live", - "methods": [ - "get" - ] - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ], - "scriptFile": "../dist/Ping/index.js" -} diff --git a/Ping/handler.ts b/Ping/handler.ts deleted file mode 100644 index 32117761..00000000 --- a/Ping/handler.ts +++ /dev/null @@ -1,32 +0,0 @@ -import * as express from "express"; - -import { wrapRequestHandler } from "@pagopa/io-functions-commons/dist/src/utils/request_middleware"; -import { - IResponseSuccessJson, - ResponseSuccessJson -} from "@pagopa/ts-commons/lib/responses"; -import * as packageJson from "../package.json"; - -interface IPing { - readonly name: string; - readonly version: string; -} - -type PingHandler = () => Promise>; - -// eslint-disable-next-line prefer-arrow/prefer-arrow-functions -export function PingHandler(): PingHandler { - // eslint-disable-next-line @typescript-eslint/explicit-function-return-type - return async () => - ResponseSuccessJson({ - name: packageJson.name, - version: packageJson.version - }); -} - -// eslint-disable-next-line prefer-arrow/prefer-arrow-functions -export function Ping(): express.RequestHandler { - const handler = PingHandler(); - - return wrapRequestHandler(handler); -} diff --git a/Ping/index.ts b/Ping/index.ts deleted file mode 100644 index 5c5fa07d..00000000 --- a/Ping/index.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { AzureFunction, Context } from "@azure/functions"; -import createAzureFunctionHandler from "@pagopa/express-azure-functions/dist/src/createAzureFunctionsHandler"; -import { secureExpressApp } from "@pagopa/io-functions-commons/dist/src/utils/express"; -import { setAppContext } from "@pagopa/io-functions-commons/dist/src/utils/middlewares/context_middleware"; -import * as express from "express"; -import { Ping } from "./handler"; - -// Setup Express -const app = express(); -secureExpressApp(app); - -// Add express route -app.get("/api/live", Ping()); - -const azureFunctionHandler = createAzureFunctionHandler(app); - -const httpStart: AzureFunction = (context: Context): void => { - setAppContext(app, context); - azureFunctionHandler(context); -}; - -export default httpStart; From 84e9609544055675ee10c8f79e072d7b5842b892 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 15:53:30 +0200 Subject: [PATCH 02/16] fixed triggers --- .github/workflows/code-review.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index edd8da29..188a7a7e 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -3,14 +3,8 @@ name: "Code Review" on: push: branches: ["main"] - paths: - - apps/** - - packages/** pull_request: types: [opened, synchronize] - paths: - - apps/** - - packages/** workflow_dispatch: {} jobs: From 735f52bab0a6e528682b4c796b6009dfc9ccd405 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 16:30:42 +0200 Subject: [PATCH 03/16] added integration tests --- .github/workflows/code-review.yml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 188a7a7e..782152c1 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -33,8 +33,27 @@ jobs: run: | yarn generate yarn test:coverage - bash <(curl -s https://codecov.io/bash) shell: bash + + integration_test: + timeout-minutes: 10 # temp fix + runs-on: ubuntu-latest + + steps: + - name: Start Functions + run: | + cd __integrations__ + sed -i 's/FF_TYPE=.*/FF_TYPE=none/g' environments/env.base + cp environments/env.base environments/.env + yarn install --frozen-lockfile + yarn start + shell: bash + - name: Run Integration Tests + run: | + cd __integrations__ + yarn install --frozen-lockfile + sleep 30s + docker exec fn-service-messages-testagent yarn test From 0e6bb077b97fa73dcf35b890a99d6644424a909d Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 16:32:45 +0200 Subject: [PATCH 04/16] fix --- .github/workflows/code-review.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 782152c1..deeedbe2 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -40,6 +40,12 @@ jobs: runs-on: ubuntu-latest steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + + - name: Build app + uses: ./.github/actions/node-yarn + - name: Start Functions run: | cd __integrations__ From c0607d83b4684f425a2dbdf41704cf37b1eb61e0 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 16:45:05 +0200 Subject: [PATCH 05/16] fix --- .github/workflows/code-review.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index deeedbe2..8205b982 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -54,12 +54,14 @@ jobs: yarn install --frozen-lockfile yarn start shell: bash + - name: Run Integration Tests run: | cd __integrations__ yarn install --frozen-lockfile sleep 30s docker exec fn-service-messages-testagent yarn test + shell: bash From ebf2db1de6fc2cdbe9dbe7f48905159038838363 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 16:51:17 +0200 Subject: [PATCH 06/16] fixed healthcheck for integration tests --- __integrations__/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__integrations__/docker-compose.yml b/__integrations__/docker-compose.yml index c4def9e1..44466e48 100644 --- a/__integrations__/docker-compose.yml +++ b/__integrations__/docker-compose.yml @@ -56,7 +56,7 @@ services: env_file: - ./environments/generated/env.function healthcheck: - test: ["CMD", "curl", "-f", "http://function:7071/api/live"] + test: ["CMD", "curl", "-f", "http://function:7071/api/v1/info"] interval: 12s timeout: 10s retries: 5 From fad811502dcbfd7dfafd5fb0b8ac01a8188f3425 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 17:21:11 +0200 Subject: [PATCH 07/16] fixed hc path for containers --- __integrations__/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__integrations__/docker-compose.yml b/__integrations__/docker-compose.yml index 44466e48..0f7f1554 100644 --- a/__integrations__/docker-compose.yml +++ b/__integrations__/docker-compose.yml @@ -56,7 +56,7 @@ services: env_file: - ./environments/generated/env.function healthcheck: - test: ["CMD", "curl", "-f", "http://function:7071/api/v1/info"] + test: ["CMD", "curl", "-f", "http://function:7071/api/info"] interval: 12s timeout: 10s retries: 5 From bbc13f1568ab7ed11c48f4cb80cd851d98cdd47f Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 18:37:40 +0200 Subject: [PATCH 08/16] fixes --- .github/workflows/anchore.yml | 52 +++++++++++++++++++++++++++++ Ping/function.json | 20 +++++++++++ Ping/handler.ts | 32 ++++++++++++++++++ Ping/index.ts | 22 ++++++++++++ __integrations__/docker-compose.yml | 2 +- __integrations__/package.json | 2 +- 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/anchore.yml create mode 100644 Ping/function.json create mode 100644 Ping/handler.ts create mode 100644 Ping/index.ts diff --git a/.github/workflows/anchore.yml b/.github/workflows/anchore.yml new file mode 100644 index 00000000..3f7246b0 --- /dev/null +++ b/.github/workflows/anchore.yml @@ -0,0 +1,52 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +# This workflow checks out code, builds an image, performs a container image +# vulnerability scan with Anchore's Grype tool, and integrates the results with GitHub Advanced Security +# code scanning feature. For more information on the Anchore scan action usage +# and parameters, see https://github.com/anchore/scan-action. For more +# information on Anchore's container image scanning tool Grype, see +# https://github.com/anchore/grype +name: Anchore Container Scan + +on: + push: + branches: ["master", "main"] + pull_request: + # The branches below must be a subset of the branches above + branches: ["master", "main"] + schedule: + - cron: "00 07 * * *" + +permissions: + contents: read + +env: + DOCKERFILE: Dockerfile + +jobs: + Anchore-Build-Scan: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file ${{ env.DOCKERFILE }} --tag localbuild/testimage:latest + - name: Run the Anchore scan action itself with GitHub Advanced Security code scanning integration enabled + uses: anchore/scan-action@v3 + with: + image: "localbuild/testimage:latest" + acs-report-enable: true + fail-build: true + severity-cutoff: "high" + - name: Upload Anchore Scan Report + uses: github/codeql-action/upload-sarif@v2 + if: always() + with: + sarif_file: results.sarif diff --git a/Ping/function.json b/Ping/function.json new file mode 100644 index 00000000..d8c2d694 --- /dev/null +++ b/Ping/function.json @@ -0,0 +1,20 @@ +{ + "bindings": [ + { + "authLevel": "anonymous", + "type": "httpTrigger", + "direction": "in", + "name": "req", + "route": "v1/ping", + "methods": [ + "get" + ] + }, + { + "type": "http", + "direction": "out", + "name": "res" + } + ], + "scriptFile": "../dist/Ping/index.js" +} diff --git a/Ping/handler.ts b/Ping/handler.ts new file mode 100644 index 00000000..32117761 --- /dev/null +++ b/Ping/handler.ts @@ -0,0 +1,32 @@ +import * as express from "express"; + +import { wrapRequestHandler } from "@pagopa/io-functions-commons/dist/src/utils/request_middleware"; +import { + IResponseSuccessJson, + ResponseSuccessJson +} from "@pagopa/ts-commons/lib/responses"; +import * as packageJson from "../package.json"; + +interface IPing { + readonly name: string; + readonly version: string; +} + +type PingHandler = () => Promise>; + +// eslint-disable-next-line prefer-arrow/prefer-arrow-functions +export function PingHandler(): PingHandler { + // eslint-disable-next-line @typescript-eslint/explicit-function-return-type + return async () => + ResponseSuccessJson({ + name: packageJson.name, + version: packageJson.version + }); +} + +// eslint-disable-next-line prefer-arrow/prefer-arrow-functions +export function Ping(): express.RequestHandler { + const handler = PingHandler(); + + return wrapRequestHandler(handler); +} diff --git a/Ping/index.ts b/Ping/index.ts new file mode 100644 index 00000000..5844b63a --- /dev/null +++ b/Ping/index.ts @@ -0,0 +1,22 @@ +import { AzureFunction, Context } from "@azure/functions"; +import createAzureFunctionHandler from "@pagopa/express-azure-functions/dist/src/createAzureFunctionsHandler"; +import { secureExpressApp } from "@pagopa/io-functions-commons/dist/src/utils/express"; +import { setAppContext } from "@pagopa/io-functions-commons/dist/src/utils/middlewares/context_middleware"; +import * as express from "express"; +import { Ping } from "./handler"; + +// Setup Express +const app = express(); +secureExpressApp(app); + +// Add express route +app.get("/api/v1/ping", Ping()); + +const azureFunctionHandler = createAzureFunctionHandler(app); + +const httpStart: AzureFunction = (context: Context): void => { + setAppContext(app, context); + azureFunctionHandler(context); +}; + +export default httpStart; diff --git a/__integrations__/docker-compose.yml b/__integrations__/docker-compose.yml index 0f7f1554..712e1f28 100644 --- a/__integrations__/docker-compose.yml +++ b/__integrations__/docker-compose.yml @@ -56,7 +56,7 @@ services: env_file: - ./environments/generated/env.function healthcheck: - test: ["CMD", "curl", "-f", "http://function:7071/api/info"] + test: ["CMD", "curl", "-f", "http://function:7071/api/v1/ping"] interval: 12s timeout: 10s retries: 5 diff --git a/__integrations__/package.json b/__integrations__/package.json index 979e1a54..84cf68d7 100644 --- a/__integrations__/package.json +++ b/__integrations__/package.json @@ -7,7 +7,7 @@ "author": "", "scripts": { "prestart": "npm-run-all generate-env generate", - "start": "docker-compose --env-file environments/.env up -d", + "start": "docker-compose --env-file environments/.env up --build -d", "stop": "docker-compose --env-file environments/.env down", "stop:all": "docker-compose --env-file environments/.env down && docker image prune -a -f && docker volume prune -f", "test": "jest --verbose --runInBand", From f3ed8c35ec3fd520460ce8e9c225e21f401333db Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 18:47:13 +0200 Subject: [PATCH 09/16] added integration tests with FFs --- .devops/code-review-pipelines.yml | 112 ------------------------------ .github/workflows/code-review.yml | 30 ++++++-- 2 files changed, 26 insertions(+), 116 deletions(-) delete mode 100644 .devops/code-review-pipelines.yml diff --git a/.devops/code-review-pipelines.yml b/.devops/code-review-pipelines.yml deleted file mode 100644 index 17f51038..00000000 --- a/.devops/code-review-pipelines.yml +++ /dev/null @@ -1,112 +0,0 @@ -# Azure DevOps pipeline to build, check source codes and run tests. -# -# To make Danger JS run on a pull request you need to add the following pipeline -# variable and set it with a GitHub access token (scope public_repo); otherwise -# set its value to 'skip' without marking it secret: -# - DANGER_GITHUB_API_TOKEN -# - -# Automatically triggered on PR -# https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#pr-trigger -trigger: none - -# Execute agents (jobs) on latest Ubuntu version. -# To change OS for a specific, ovverride "pool" attribute inside the job definition -pool: - vmImage: 'ubuntu-latest' - -resources: - repositories: - - repository: pagopaCommons - type: github - name: pagopa/azure-pipeline-templates - ref: refs/tags/v18 - endpoint: 'io-azure-devops-github-ro' - -stages: - - stage: Build - dependsOn: [] - jobs: - - job: make_build - pool: - # As we deploy on Wondows machines, we use Windows to build - vmImage: 'windows-2019' - steps: - - template: templates/node-job-setup/template.yaml@pagopaCommons - - script: | - yarn build - displayName: 'Build' - - - stage: Static_analysis - dependsOn: [] - jobs: - - - job: lint - steps: - - template: templates/node-job-setup/template.yaml@pagopaCommons - - script: | - yarn lint - displayName: 'Lint' - - - job: validate_api_specification - steps: - - script: | - npx oval validate -p openapi/index.yaml - displayName: 'Validate API specification' - - # B) Run unit tests if there is a push or pull request on any branch. - - stage: Test - dependsOn: [] - jobs: - - job: unit_tests - steps: - - template: templates/node-job-setup/template.yaml@pagopaCommons - - - script: | - yarn generate - displayName: 'Generate definitions' - - - script: | - yarn test:coverage - displayName: 'Unit tests exec' - - - bash: | - bash <(curl -s https://codecov.io/bash) - displayName: 'Code coverage' - - - stage: Integration_Tests - dependsOn: [] - jobs: - - job: integration_tests_ff_NONE - steps: - - template: templates/node-job-setup/template.yaml@pagopaCommons - - script: | - cd __integrations__ - sed -i 's/FF_TYPE=.*/FF_TYPE=none/g' environments/env.base - cp environments/env.base environments/.env - yarn install --frozen-lockfile - yarn start - displayName: 'Start test resources' - - script: | - cd __integrations__ - yarn install --frozen-lockfile - sleep 30s - docker exec fn-service-messages-testagent yarn test - displayName: 'Execute tests' - - - job: integration_tests_ff_PROD - steps: - - template: templates/node-job-setup/template.yaml@pagopaCommons - - script: | - cd __integrations__ - sed -i 's/FF_TYPE=.*/FF_TYPE=prod/g' environments/env.base - cp environments/env.base environments/.env - yarn install --frozen-lockfile - yarn start - displayName: 'Start test resources' - - script: | - cd __integrations__ - yarn install --frozen-lockfile - sleep 30s - docker exec fn-service-messages-testagent yarn test - displayName: 'Execute tests' diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 8205b982..1430920c 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -35,7 +35,7 @@ jobs: yarn test:coverage shell: bash - integration_test: + integration_test_ff_none: timeout-minutes: 10 # temp fix runs-on: ubuntu-latest @@ -54,7 +54,7 @@ jobs: yarn install --frozen-lockfile yarn start shell: bash - + - name: Run Integration Tests run: | cd __integrations__ @@ -63,8 +63,30 @@ jobs: docker exec fn-service-messages-testagent yarn test shell: bash - + integration_test_ff_prod: + timeout-minutes: 10 # temp fix + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 + - name: Build app + uses: ./.github/actions/node-yarn + + - name: Start Functions + run: | + cd __integrations__ + sed -i 's/FF_TYPE=.*/FF_TYPE=prod/g' environments/env.base + cp environments/env.base environments/.env + yarn install --frozen-lockfile + yarn start + shell: bash - \ No newline at end of file + - name: Run Integration Tests + run: | + cd __integrations__ + yarn install --frozen-lockfile + sleep 30s + docker exec fn-service-messages-testagent yarn test + shell: bash From 7222089ed6e0f68b98cc82a3f7fd7191ace54c03 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Tue, 16 Apr 2024 18:50:46 +0200 Subject: [PATCH 10/16] added readme --- Ping/README.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Ping/README.md diff --git a/Ping/README.md b/Ping/README.md new file mode 100644 index 00000000..c1842aa5 --- /dev/null +++ b/Ping/README.md @@ -0,0 +1,2 @@ +# Purpose +This functions is needed for integration tests's functions healthcheck. \ No newline at end of file From 1adac05e4b316849d3e07adcfdd0d73146037a38 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Wed, 17 Apr 2024 09:47:00 +0200 Subject: [PATCH 11/16] added names --- .github/workflows/code-review.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 1430920c..0c07c0da 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -9,6 +9,7 @@ on: jobs: code_review: + name: Run linting and unit tests timeout-minutes: 10 # temp fix runs-on: ubuntu-latest @@ -36,6 +37,7 @@ jobs: shell: bash integration_test_ff_none: + name: Run integration tests with FF_TYPE=none timeout-minutes: 10 # temp fix runs-on: ubuntu-latest @@ -64,6 +66,7 @@ jobs: shell: bash integration_test_ff_prod: + name: Run integration tests with FF_TYPE=prod timeout-minutes: 10 # temp fix runs-on: ubuntu-latest From 0dcd8a70d13262ee64b6becc0b920e3583ed00f9 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Wed, 17 Apr 2024 11:38:59 +0200 Subject: [PATCH 12/16] fixes --- .github/workflows/code-review.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/code-review.yml b/.github/workflows/code-review.yml index 0c07c0da..b50669e8 100644 --- a/.github/workflows/code-review.yml +++ b/.github/workflows/code-review.yml @@ -1,8 +1,6 @@ name: "Code Review" on: - push: - branches: ["main"] pull_request: types: [opened, synchronize] workflow_dispatch: {} @@ -61,7 +59,6 @@ jobs: run: | cd __integrations__ yarn install --frozen-lockfile - sleep 30s docker exec fn-service-messages-testagent yarn test shell: bash @@ -90,6 +87,5 @@ jobs: run: | cd __integrations__ yarn install --frozen-lockfile - sleep 30s docker exec fn-service-messages-testagent yarn test shell: bash From 6a18c4cd02ed2c7d95f8d2fabc50ef7b74c70d07 Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Wed, 17 Apr 2024 11:41:15 +0200 Subject: [PATCH 13/16] removed autorelease on push --- .github/workflows/release.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f621741b..18c2f4bc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,14 +1,6 @@ name: Release on: - # Trigger the workflow on push on the main branch - push: - branches: - - main - paths-ignore: - - 'CODEOWNERS' - - '**.md' - - '.**' # Trigger the workflow by dispatching workflow_dispatch: From 810288666a13663754c13795f3c6da4b69da26bd Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Wed, 17 Apr 2024 15:24:34 +0200 Subject: [PATCH 14/16] changed release action to be selfcontained --- .github/workflows/release.yml | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18c2f4bc..759e8f20 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,8 +1,16 @@ name: Release on: - # Trigger the workflow by dispatching workflow_dispatch: + inputs: + release_type: + description: The type of this release + required: true + type: choice + options: + - major + - minor + - patch jobs: release: @@ -12,20 +20,20 @@ jobs: steps: - name: Checkout id: checkout - # from https://github.com/actions/checkout/commits/main uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 - with: - persist-credentials: false - fetch-depth: 0 - name: Release id: release - # from https://github.com/cycjimmy/semantic-release-action/commits/main - uses: cycjimmy/semantic-release-action@bdd914ff2423e2792c73475f11e8da603182f32d - with: - semantic_version: 18.0.0 - extra_plugins: | - @semantic-release/release-notes-generator@10.0.3 - @semantic-release/git@10.0.1 + run: | + npm version ${{ inputs.release_type }} --no-git-tag-version + NEXT_VERSION=$(node -p "require('./package.json').version") + RELEASE_TAG="v$NEXT_VERSION-RELEASE" + TITLE="Release $NEXT_VERSION" + git add package.json + git tag $RELEASE_TAG + git commit -m "Bump version to $RELEASE_TAG [skip ci]" + git push origin master && git push --tags + gh release create $RELEASE_TAG --title $TITLE + shell: bash env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From a579c7c2a434c74e0c13884db6b01cd2afb9ee7c Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Wed, 17 Apr 2024 15:37:37 +0200 Subject: [PATCH 15/16] build before releasing --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 759e8f20..4d9e1f68 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,9 @@ jobs: id: checkout uses: actions/checkout@1f9a0c22da41e6ebfa534300ef656657ea2c6707 + - name: Build app + uses: ./.github/actions/node-yarn + - name: Release id: release run: | From aead5fcad459ef6fd5b971e5b32a450716cf25ad Mon Sep 17 00:00:00 2001 From: Michael Disaro Date: Wed, 17 Apr 2024 15:56:46 +0200 Subject: [PATCH 16/16] added git user name and email --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4d9e1f68..ba0c3b14 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -28,6 +28,8 @@ jobs: - name: Release id: release run: | + git config user.email "github-bot@pagopa.it" + git config user.name "pagopa-github-bot" npm version ${{ inputs.release_type }} --no-git-tag-version NEXT_VERSION=$(node -p "require('./package.json').version") RELEASE_TAG="v$NEXT_VERSION-RELEASE"