From 6b870a1d8b6ba4d3d195888fc772b31265554e4f Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 19 Feb 2024 14:13:28 +0100 Subject: [PATCH] feat: Initial custom PR tests check status --- .github/workflows/performance-tests-pr.yml | 49 +++++++++++++------ .../generate-github-actions.mjs | 29 ++++++++++- .../graphql/DataCubeComponents.js | 6 +++ .../graphql/DataCubeMetadata.js | 6 +++ .../graphql/DataCubeObservations.js | 6 +++ .../graphql/DataCubePreview.js | 6 +++ .../graphql/PossibleFilters.js | 6 +++ 7 files changed, 92 insertions(+), 16 deletions(-) diff --git a/.github/workflows/performance-tests-pr.yml b/.github/workflows/performance-tests-pr.yml index 6181e436c..166c1be60 100644 --- a/.github/workflows/performance-tests-pr.yml +++ b/.github/workflows/performance-tests-pr.yml @@ -2,6 +2,9 @@ name: GraphQL performance tests (PR) on: [deployment_status] +env: + SUMMARY: '' + jobs: run_tests: if: github.event.deployment_status.state == 'success' @@ -19,18 +22,34 @@ jobs: image: grafana/k6:latest options: -v ${{ github.workspace }}:/root run: | - k6 run --tag testid=DataCubeComponents --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeComponents --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeComponents --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeMetadata --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeMetadata --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeMetadata --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeObservations --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeObservations --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubeObservations --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubePreview --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubePreview --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=DataCubePreview --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=PossibleFilters --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/sfoe/bfe_ogd84_einmalverguetung_fuer_photovoltaikanlagen/9 --env CUBE_LABEL=Photovoltaikanlagen/9 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=PossibleFilters --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://environment.ld.admin.ch/foen/nfi/nfi_C-20/cube/2023-3 --env CUBE_LABEL=NFI/2023-3 --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV && + echo "SUMMARY=$SUMMARY$(k6 run --tag testid=PossibleFilters --env ENV=PR --env ENDPOINT=${{ github.event.deployment_status.target_url }}/api/graphql --env CUBE_IRI=https://energy.ld.admin.ch/elcom/electricityprice --env CUBE_LABEL=Elcom --env ROOT_PATH=/root/ --env CHECK_TIMING=true - > $GITHUB_ENV + - name: GQL performance tests ✅ + if: ${{ env.SUMMARY == '' }} + run: | + curl --request POST --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --header 'content-type: application/json' --data '{ + "context": "GQL performance tests", + "state": "success", + "description": "GQL performance tests passed" + }' + - name: GQL performance tests 🚨 + if: ${{ env.SUMMARY != '' }} + run: | + curl --request POST --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --header 'content-type: application/json' --data '{ + "context": "GQL performance tests", + "state": "failure", + "description": "GQL performance tests failed for the following queries: ${{ env.SUMMARY }}" + }' diff --git a/k6/performance-tests/generate-github-actions.mjs b/k6/performance-tests/generate-github-actions.mjs index 691913158..0524ca3c6 100644 --- a/k6/performance-tests/generate-github-actions.mjs +++ b/k6/performance-tests/generate-github-actions.mjs @@ -77,12 +77,15 @@ const generatePRTests = () => { ) ) ) - + .map((command) => `echo "SUMMARY=$SUMMARY$(${command})" >> $GITHUB_ENV`) .join(" &&\n "); const file = `name: GraphQL performance tests (PR) on: [deployment_status] +env: + SUMMARY: '' + jobs: run_tests: if: github.event.deployment_status.state == 'success' @@ -101,6 +104,30 @@ jobs: options: -v \${{ github.workspace }}:/root run: | ${commands} + - name: GQL performance tests ✅ + if: \${{ env.SUMMARY == '' }} + run: | + curl --request POST \ + --url https://api.github.com/repos/\${{ github.repository }}/statuses/\${{ github.sha }} \ + --header 'authorization: Bearer \${{ secrets.GITHUB_TOKEN }}' \ + --header 'content-type: application/json' \ + --data '{ + "context": "GQL performance tests", + "state": "success", + "description": "GQL performance tests passed" + }' + - name: GQL performance tests 🚨 + if: \${{ env.SUMMARY != '' }} + run: | + curl --request POST \ + --url https://api.github.com/repos/\${{ github.repository }}/statuses/\${{ github.sha }} \ + --header 'authorization: Bearer \${{ secrets.GITHUB_TOKEN }}' \ + --header 'content-type: application/json' \ + --data '{ + "context": "GQL performance tests", + "state": "failure", + "description": "GQL performance tests failed for the following queries: \${{ env.SUMMARY }}" + }' `; fs.writeFileSync("./.github/workflows/performance-tests-pr.yml", file); diff --git a/k6/performance-tests/graphql/DataCubeComponents.js b/k6/performance-tests/graphql/DataCubeComponents.js index cae1d0b58..a48e00c2e 100644 --- a/k6/performance-tests/graphql/DataCubeComponents.js +++ b/k6/performance-tests/graphql/DataCubeComponents.js @@ -78,3 +78,9 @@ export default function Components() { }); } } + +export function handleSummary(data) { + return { + stdout: `DataCubeComponents`, + }; +} diff --git a/k6/performance-tests/graphql/DataCubeMetadata.js b/k6/performance-tests/graphql/DataCubeMetadata.js index 38c058e0a..1eed13da5 100644 --- a/k6/performance-tests/graphql/DataCubeMetadata.js +++ b/k6/performance-tests/graphql/DataCubeMetadata.js @@ -75,3 +75,9 @@ export default function Components() { }); } } + +export function handleSummary(data) { + return { + stdout: `DataCubeMetadata`, + }; +} diff --git a/k6/performance-tests/graphql/DataCubeObservations.js b/k6/performance-tests/graphql/DataCubeObservations.js index 72a193521..fed47589a 100644 --- a/k6/performance-tests/graphql/DataCubeObservations.js +++ b/k6/performance-tests/graphql/DataCubeObservations.js @@ -78,3 +78,9 @@ export default function Observations() { }); } } + +export function handleSummary(data) { + return { + stdout: `DataCubeObservations`, + }; +} diff --git a/k6/performance-tests/graphql/DataCubePreview.js b/k6/performance-tests/graphql/DataCubePreview.js index 169d2ee6d..30417b65a 100644 --- a/k6/performance-tests/graphql/DataCubePreview.js +++ b/k6/performance-tests/graphql/DataCubePreview.js @@ -81,3 +81,9 @@ export default function Components() { }); } } + +export function handleSummary(data) { + return { + stdout: `DataCubePreview`, + }; +} diff --git a/k6/performance-tests/graphql/PossibleFilters.js b/k6/performance-tests/graphql/PossibleFilters.js index 97e3b81be..2f1621ba0 100644 --- a/k6/performance-tests/graphql/PossibleFilters.js +++ b/k6/performance-tests/graphql/PossibleFilters.js @@ -78,3 +78,9 @@ export default function Observations() { }); } } + +export function handleSummary(data) { + return { + stdout: `PossibleFilters`, + }; +}