Skip to content

Commit aaaf4d7

Browse files
ci: implement aws tests on prs (#2406)
* test(cli): fix existing lambda test * ci(docker): allow publishing of ecs worker image from prs * ci(test): add workflow for running aws tests when pr is labeled * ci: pin check-user-permission action to specific sha
1 parent 6fd477f commit aaaf4d7

File tree

9 files changed

+110
-44
lines changed

9 files changed

+110
-44
lines changed

.github/workflows/docker-ecs-worker-image.yml

+10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ on:
55
push:
66
branches:
77
- main
8+
workflow_call:
9+
inputs:
10+
ref:
11+
description: 'Branch ref to checkout. Needed for pull_request_target to be able to pull correct ref.'
12+
type: string
13+
secrets:
14+
ECR_WORKER_IMAGE_PUSH_ROLE_ARN:
15+
description: 'ARN of the IAM role to assume to push the image to ECR.'
16+
required: true
817

918
permissions:
1019
id-token: write
@@ -16,6 +25,7 @@ jobs:
1625
steps:
1726
- uses: actions/checkout@v3
1827
with:
28+
ref: ${{ inputs.ref || null }}
1929
fetch-depth: 0
2030

2131
- name: Show git ref

.github/workflows/run-aws-tests.yml

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Run AWS tests
2+
3+
on:
4+
pull_request_target:
5+
branches: [main]
6+
#opened, reopened and synchronize will cause the workflow to fail on forks due to permissions
7+
#once labeled, that will then be overridden by the is-collaborator job
8+
types: [opened, labeled, synchronize, reopened]
9+
10+
jobs:
11+
is-collaborator:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Get User Permission
15+
id: checkAccess
16+
uses: actions-cool/check-user-permission@cd622002ff25c2311d2e7fb82107c0d24be83f9b
17+
with:
18+
require: write
19+
username: ${{ github.actor }}
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
- name: Check User Permission
23+
if: steps.checkAccess.outputs.require-result == 'false'
24+
run: |
25+
echo "${{ github.actor }} does not have permissions on this repo."
26+
echo "Current permission level is ${{ steps.checkAccess.outputs.user-permission }}"
27+
exit 1
28+
29+
publish-branch-image:
30+
if: contains( github.event.pull_request.labels.*.name, 'run-aws-tests' )
31+
needs: is-collaborator
32+
uses: ./.github/workflows/docker-ecs-worker-image.yml
33+
permissions:
34+
contents: read
35+
id-token: write
36+
secrets:
37+
ECR_WORKER_IMAGE_PUSH_ROLE_ARN: ${{ secrets.ECR_WORKER_IMAGE_PUSH_ROLE_ARN }}
38+
with:
39+
ref: ${{ github.event.pull_request.head.sha || null }} # this should only be run with this ref if is-collaborator has been run and passed
40+
41+
run-tests:
42+
if: contains( github.event.pull_request.labels.*.name, 'run-aws-tests' )
43+
needs: publish-branch-image
44+
timeout-minutes: 40
45+
runs-on: ubuntu-latest
46+
permissions:
47+
contents: read
48+
id-token: write
49+
steps:
50+
- uses: actions/checkout@v3
51+
with:
52+
ref: ${{ github.event.pull_request.head.sha || null }} # this should only be run with this ref if is-collaborator has been run and passed
53+
- name: Configure AWS Credentials
54+
uses: aws-actions/configure-aws-credentials@v2
55+
env:
56+
SHOW_STACK_TRACE: true
57+
with:
58+
aws-region: eu-west-1
59+
role-to-assume: ${{ secrets.ARTILLERY_AWS_CLI_ROLE_ARN_TEST1 }}
60+
role-session-name: OIDCSession
61+
mask-aws-account-id: true
62+
- name: Use Node.js 18.x
63+
uses: actions/setup-node@v2
64+
with:
65+
node-version: 18.x
66+
- run: npm install
67+
- run: npm run build
68+
- run: npm run test:aws --workspace artillery
69+
env:
70+
FORCE_COLOR: 1
71+
ECR_IMAGE_VERSION: ${{ github.sha }} # the image is published with the sha of the commit within this repo

packages/artillery/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"test:unit": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --timeout=420 --color test/unit/*.test.js",
4747
"test:acceptance": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --timeout=420 test/cli/*.test.js && bash test/lib/run.sh && tap --no-coverage --color test/testcases/plugins/*.test.js",
4848
"test": "npm run test:unit && npm run test:acceptance",
49-
"test:cloud": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --timeout=300 test/cloud-e2e/*.test.js",
49+
"test:aws": "export ARTILLERY_TELEMETRY_DEFAULTS='{\"source\":\"test-suite\"}' && tap --no-coverage --color --timeout=600 test/cloud-e2e/**/*.test.js",
5050
"lint": "eslint --ext \".js,.ts,.tsx\" .",
5151
"lint-fix": "npm run lint -- --fix"
5252
},
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
config:
22
target: http://asciiart.artillery.io:8080
3-
processor: ./helpers-blitz.js
3+
processor: ./helpers.js
44
payload:
55
- path: ./test.csv
66
fields:
77
- number
88
- name
9-
plugins:
10-
metrics-by-endpoint: {}
119
phases:
1210
- duration: 30
1311
arrivalRate: 1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
pony,tiki
22
dog,mali
3-
cat,faye
3+
cat,faye
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const tap = require('tap');
2+
const { execute } = require('../../cli/_helpers.js');
3+
4+
tap.test('Run a test on AWS Lambda', async (t) => {
5+
const [exitCode, output] = await execute([
6+
'run:lambda',
7+
'--count',
8+
'10',
9+
'--region',
10+
'eu-west-1',
11+
'--config',
12+
'./test/cloud-e2e/lambda/fixtures/quick-loop-with-csv/config.yml',
13+
'./test/cloud-e2e/lambda/fixtures/quick-loop-with-csv/blitz.yml'
14+
]);
15+
16+
t.equal(exitCode, 0, 'CLI should exit with code 0');
17+
18+
t.ok(
19+
output.stdout.indexOf('Summary report') > 0,
20+
'Should print summary report'
21+
);
22+
t.ok(
23+
output.stdout.indexOf('http.codes.200') > 0,
24+
'Should print http.codes.200'
25+
);
26+
});

packages/artillery/test/cloud-e2e/run-lambda.test.js

-39
This file was deleted.

0 commit comments

Comments
 (0)