├── .github ├── PULL_REQUEST_TEMPLATE.md └── release.yaml ├── package.json ├── action.yml ├── .gitignore ├── index.js └── README.md /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | > *For `description`, provide a brief explanation of the context around this change.* 4 | 5 | ## Verification 6 | 7 | > *Include screenshots, log messages, etc. to show how this change was tested/verified.* 8 | 9 | ## Ready for Code Review Checklist 10 | 11 | - [ ] Includes unit tests 12 | - [ ] Includes related documentation 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RapidAPI-testing-github-action", 3 | "version": "1.0.0", 4 | "description": "Executes RapidAPI tests as a GitHub action", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "@actions/core": "^1.2.6", 14 | "@actions/github": "^4.0.0", 15 | "axios": "^0.20.0" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.github/release.yaml: -------------------------------------------------------------------------------- 1 | changelog: 2 | exclude: 3 | labels: 4 | - ignore-for-release 5 | authors: 6 | - octocat 7 | categories: 8 | - title: 🛠 Breaking Changes 🛠 9 | labels: 10 | - Version-Major 11 | - title: 🎉 Enhancements 🎉 12 | labels: 13 | - Version-Minor 14 | - title: 🩹 Patches 🩹 15 | labels: 16 | - Version-Patch 17 | - title: 📖 Documentation 📖 18 | labels: 19 | - documentation 20 | - title: 🤷 Other Changes 🤷 21 | labels: 22 | - "*" 23 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'RapidAPI Testing Trigger' 2 | description: 'Trigger an API test on RapidAPI Testing' 3 | branding: 4 | icon: 'globe' 5 | color: 'blue' 6 | inputs: 7 | test: 8 | description: 'ID of the test to run' 9 | required: true 10 | location: 11 | description: 'The location the test will be executed in' 12 | required: true 13 | default: 'AWS-US-EAST-1' 14 | tenant: 15 | description: 'The Rapid tenant to run the tests against' 16 | required: false 17 | default: 'rapidapi.com' 18 | environment: 19 | description: 'The environment ID the test will run in' 20 | required: false 21 | outputs: 22 | time: 23 | description: 'How long the test took to execute' 24 | successful: 25 | description: 'True or false based on the outcome of the test execution' 26 | reportUrl: 27 | description: 'Url for the full test execution URL' 28 | runs: 29 | using: 'node16' 30 | main: 'index.js' 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | jspm_packages/ 42 | 43 | # TypeScript v1 declaration files 44 | typings/ 45 | 46 | # TypeScript cache 47 | *.tsbuildinfo 48 | 49 | # Optional npm cache directory 50 | .npm 51 | 52 | # Optional eslint cache 53 | .eslintcache 54 | 55 | # Microbundle cache 56 | .rpt2_cache/ 57 | .rts2_cache_cjs/ 58 | .rts2_cache_es/ 59 | .rts2_cache_umd/ 60 | 61 | # Optional REPL history 62 | .node_repl_history 63 | 64 | # Output of 'npm pack' 65 | *.tgz 66 | 67 | # Yarn Integrity file 68 | .yarn-integrity 69 | 70 | # dotenv environment variables file 71 | .env 72 | .env.test 73 | 74 | # parcel-bundler cache (https://parceljs.org/) 75 | .cache 76 | 77 | # Next.js build output 78 | .next 79 | 80 | # Nuxt.js build / generate output 81 | .nuxt 82 | dist 83 | 84 | # Gatsby files 85 | .cache/ 86 | # Comment in the public line in if your project uses Gatsby and *not* Next.js 87 | # https://nextjs.org/blog/next-9-1#public-directory-support 88 | # public 89 | 90 | # vuepress build output 91 | .vuepress/dist 92 | 93 | # Serverless directories 94 | .serverless/ 95 | 96 | # FuseBox cache 97 | .fusebox/ 98 | 99 | # DynamoDB Local files 100 | .dynamodb/ 101 | 102 | # TernJS port file 103 | .tern-port -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const core = require('@actions/core'); 2 | const github = require('@actions/github'); 3 | const axios = require('axios'); 4 | 5 | // CONSTS 6 | const WAIT_TIME = 1000; 7 | const MAX_TRIES = 300; 8 | const FIRST_WAIT = 2000; 9 | 10 | // INPUTS 11 | const TEST_ID = core.getInput('test'); 12 | console.log(`Executing Test ID: ${TEST_ID}`); 13 | 14 | const LOCATION = core.getInput('location'); 15 | console.log(`Executing In Location: ${LOCATION}`); 16 | 17 | const ENVIRONMENT = core.getInput('environment') || null; 18 | console.log(`Executing In Env: ${ENVIRONMENT}`); 19 | 20 | const API_URL = `https://${core.getInput('tenant')}/testing/api/trigger`; 21 | console.log(`Executing Test Against: ${API_URL}`); 22 | 23 | function sleep(time) { 24 | return new Promise((res, rej) => { 25 | setTimeout(() => { 26 | res(); 27 | }, time); 28 | }); 29 | } 30 | 31 | core.group('Execute Test', async () => { 32 | // 1. Trigger Test 33 | const envString = ENVIRONMENT ? `&enviroment=${ENVIRONMENT}` : ''; 34 | const testTrigger = (await axios.get(`${API_URL}/test/${TEST_ID}/execute?source=gh_action&location=${LOCATION}${envString}`)).data; 35 | const reportUrl = testTrigger.reportUrl; 36 | console.log(testTrigger.message); 37 | core.setOutput("reportUrl", reportUrl); 38 | const executionId = testTrigger.executionId; 39 | 40 | // 2. Perform initial wait -- this is to avoid multiple checks while test is ramping up 41 | await sleep(FIRST_WAIT-WAIT_TIME); 42 | 43 | let testResult = null; 44 | let tries = 0; 45 | while ( 46 | (!testResult || testResult.status == 'pending' || testResult.status == 'started') && 47 | tries < MAX_TRIES // safety 48 | ) { 49 | await sleep(WAIT_TIME); 50 | testResult = (await axios.get(`${API_URL}/execution/${executionId}/status`)).data; 51 | } 52 | delete testResult.report; 53 | console.log(testResult); 54 | 55 | // 3. Set Response Data 56 | core.setOutput("time", testResult.executionTime); 57 | core.setOutput("succesful", testResult.succesful); 58 | core.setOutput("successful", testResult.successful); 59 | core.setOutput("computedStatus", testResult.computedStatus); 60 | 61 | // 4. Fail action if test failed 62 | if (!testResult.successful) { 63 | core.setFailed(`Test execution failed. View report here: ${testTrigger.reportUrl}`); 64 | } 65 | }); 66 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RapidAPI Testing GitHub Actions 2 | 3 | This GitHub Action allows you to trigger the execution of [RapidAPI Testing](https://rapidapi.com/testing) tests. This is especially useful 4 | during CI/CD to ensure new deployments are functioning as expected. 5 | 6 | ## Complete example 7 | 8 | ```yaml 9 | on: [push] 10 | 11 | jobs: 12 | run_api_test: 13 | runs-on: ubuntu-latest 14 | name: Execute RapidAPI API Tests 15 | steps: 16 | - name: Execute Tests 17 | id: tstExec 18 | uses: RapidAPI/gh-api-testing-trigger@v0.0.3 19 | with: 20 | test: 'YOUR_TEST_ID' 21 | location: 'AWS-US-WEST-2' 22 | environment: 'ENV_ID(OPTIONAL)' 23 | - name: Show Results 24 | run: echo "The test took ${{ steps.tstExec.outputs.time }}ms to run"; echo "The test result was ${{ steps.tstExec.outputs.computedStatus }}"; echo "View Report - ${{ steps.tstExec.outputs.reportUrl }}" 25 | ``` 26 | 27 | ## Inputs 28 | 29 | ### `test` 30 | 31 | **Required** The ID of the test you wish to execute. 32 | 33 | ### `location` 34 | 35 | **Required** The location the test will be executed in. Options: 36 | 37 | - `AWS-US-EAST-1` : N. Virginia 38 | - `AWS-US-WEST-2` : Oregon 39 | - `AWS-AP-EAST-1` : Hong Kong 40 | - `AWS-AP-SOUTH-1` : Mumbai 41 | - `AWS-AP-SOUTHEAST-1` : Singapore 42 | - `AWS-AP-NORTHEAST-1` : Tokyo 43 | - `AWS-EU-CENTRAL-1` : Frankfurt 44 | - `AWS-EU-WEST-3` : Paris 45 | - `AWS-SA-EAST-1` : São Paulo 46 | 47 | ### `environment` 48 | 49 | The environment you want to run the test in. If you don't use environment omit this parameter 50 | 51 | ### `tenant` 52 | 53 | The tenant to run the test against. Defaults to the public Hub `rapidapi.com`. For example for an enterprise 54 | it may be `tenant: ${ENTERPRISE_DOMAIN}.hub.rapidapi.com`. Likewise, for different regions: 55 | 56 | ```yaml 57 | US: https://acme.hub.rapidapi.com 58 | CA: https://acme.hub-ca.rapidapi.com 59 | EU: https://acme.hub-eu.rapidapi.com 60 | ``` 61 | 62 | With `acme` being a mock domain used as an example. 63 | ## Outputs 64 | 65 | ### `time` 66 | 67 | The time it took the test to execute, in milliseconds (1000ms=s) 68 | 69 | ### `successful` 70 | 71 | True/false based on the result of the test execution 72 | 73 | ### `reportUrl` 74 | 75 | URL of a human-readable report of the test execution 76 | 77 | ### `computedStatus` 78 | 79 | A human-readable test status that matches the status values on the test dashboard in the UI 80 | 81 | ## Help 82 | 83 | For any help using this integration, reach out to `support@rapidapi.com`. You can also see RapidAPI Testing Guide in our [Help Center](https://docs.rapidapi.com/docs/creating-test-flows). 84 | --------------------------------------------------------------------------------