diff --git a/.github/workflows/performance-tests-pr.yml b/.github/workflows/performance-tests-pr.yml new file mode 100644 index 000000000..0b8b8210d --- /dev/null +++ b/.github/workflows/performance-tests-pr.yml @@ -0,0 +1,33 @@ +name: GraphQL performance tests (PR) + +on: [deployment_status] + +jobs: + run_tests: + if: github.event.deployment_status.state == 'success' + name: Run tests + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v2 + - name: Run k6 + uses: addnab/docker-run-action@v3 + with: + 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 - - queries.flatMap((query) => - cubes.map((cube) => - getRunCommand( - env, - query, - cube, - `https://${ - env === "prod" ? "" : `${env}.` - }visualize.admin.ch/api/graphql` +const generateAutoTests = () => { + const commands = envs + .flatMap((env) => + queries.flatMap((query) => + cubes.map((cube) => + getRunCommand( + env, + query, + cube, + `https://${ + env === "prod" ? "" : `${env}.` + }visualize.admin.ch/api/graphql` + ) ) ) ) - ) - .join(" &&\n "); - -const generate = () => { + .join(" &&\n "); const file = `name: GraphQL performance tests (auto) on: @@ -54,13 +53,61 @@ jobs: -e K6_PROMETHEUS_RW_SERVER_URL=\${{ secrets.K6_PROMETHEUS_RW_SERVER_URL }} -e K6_PROMETHEUS_RW_TREND_STATS=avg run: | - ${commands}`; + ${commands} +`; fs.writeFileSync("./.github/workflows/performance-tests.yml", file); }; -generate(); +generateAutoTests(); + +const generatePRTests = () => { + const commands = queries + .flatMap((query) => + cubes.map((cube) => + getRunCommand( + "PR", + query, + cube, + "${{ github.event.deployment_status.target_url }}/api/graphql", + false + ) + ) + ) + + .join(" &&\n "); + const file = `name: GraphQL performance tests (PR) + +on: [deployment_status] + +jobs: + run_tests: + if: github.event.deployment_status.state == 'success' + name: Run tests + runs-on: ubuntu-latest + steps: + - name: Check out + uses: actions/checkout@v2 + - name: Run k6 + uses: addnab/docker-run-action@v3 + with: + image: grafana/k6:latest + options: -v \${{ github.workspace }}:/root + run: | + ${commands} +`; + + fs.writeFileSync("./.github/workflows/performance-tests-pr.yml", file); +}; + +generatePRTests(); -function getRunCommand(env, query, cube, endpoint) { - return `k6 run -o experimental-prometheus-rw --tag testid=${query} --env ENV=${env} --env ENDPOINT=${endpoint} --env CUBE_IRI=${cube.iri} --env CUBE_LABEL=${cube.label} -