From 833848aad42113ae91761ac1753899858c9650d3 Mon Sep 17 00:00:00 2001 From: Matt Ball Date: Fri, 8 Oct 2021 15:51:43 +0100 Subject: [PATCH] multiple fixes v1 --- README.md | 17 +++++++++++++++++ action.yml | 4 ++++ dist/index.js | 18 +++++++++--------- index.js | 18 +++++++++--------- package-lock.json | 2 +- package.json | 2 +- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index ed2b52bd..94176059 100644 --- a/README.md +++ b/README.md @@ -69,3 +69,20 @@ See [Workflow syntax for GitHub Actions](https://help.github.com/en/articles/wor ## Other settings As well as `apiKey`, `collection`, and `environment`, all other Newman settings are supported. You can find a full list [on the Newman docs](https://github.com/postmanlabs/newman#api-reference). This action uses the Node module under the hood, so ensure you are reading the API reference rather than the command line options. Alternatively, you can see the available options in `action.yml` in this repo. + +Note that: +- GitHub Actions only supports `string`, `number` and `boolean` types. For fields that require objects/arrays, you will need to stringify them appropriately. +- `environment` and `globals` are only supported as a `string` in this Action. They cannot be passed stringified objects. + +The following example demonstrates these notes in practice: + +``` +- uses: actions/checkout@master +- uses: matt-ball/newman-action@master + with: + collection: postman_collection.json + environment: postman_environment.json + reporters: '["emojitrain"]' + delayRequest: 5000 + envVar: '[{ "key": "url", "value": "http://localhost:3000" }]' +``` diff --git a/action.yml b/action.yml index b0f233d1..5ddfd745 100644 --- a/action.yml +++ b/action.yml @@ -12,8 +12,12 @@ inputs: required: true environment: description: 'Environment to use' + envVar: + description: 'Environment variables' globals: description: 'Globals to use' + globalVar: + description: 'Global variables' iterationCount: description: 'Number of iterations to run on the collection' iterationData: diff --git a/dist/index.js b/dist/index.js index ec28ba0c..f26ca1b8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -254216,10 +254216,12 @@ async function init () { apiKey: get('apiKey'), collection: get('collection', required), environment: get('environment'), + envVar: safeParse(get('envVar')), globals: get('globals'), + globalVar: safeParse(get('globalVar')), iterationCount: num(get('iterationCount')), iterationData: get('iterationData'), - folder: split(get('folder')), + folder: safeParse(get('folder')), workingDir: get('workingDir'), insecureFileRead: safeParse(get('insecureFileRead')), timeout: num(get('timeout')), @@ -254230,13 +254232,13 @@ async function init () { insecure: safeParse(get('insecure')), bail: safeParse(get('bail')), suppressExitCode: safeParse(get('suppressExitCode')), - reporters: split(get('reporters')), + reporters: safeParse(get('reporters')), reporter: safeParse(get('reporter')), color: get('color'), sslClientCert: get('sslClientCert'), sslClientKey: get('sslClientKey'), sslClientPassphrase: get('sslClientPassphrase'), - sslClientCertList: split(get('sslClientCertList')), + sslClientCertList: safeParse(get('sslClientCertList')), sslExtraCaCerts: get('sslExtraCaCerts'), requestAgents: safeParse(get('requestAgents')), cookieJar: get('cookieJar') @@ -254287,10 +254289,6 @@ function num (i) { return i } -function split (str) { - return str ? str.split(',') : null -} - function removeEmpty (obj) { return Object.entries(obj) .filter(([_, v]) => v != null) @@ -254298,9 +254296,11 @@ function removeEmpty (obj) { } function runNewman (options) { - newman.run(options).on('done', (err, summary) => { + newman.run(options, (err) => { + core.setFailed('Newman run failed! ' + (err || '')) + }).on('done', (err, summary) => { if (!options.suppressExitCode && (err || summary.run.failures.length)) { - core.setFailed('Newman run failed!' + (err || '')) + core.setFailed('Newman run failed! ' + (err || '')) } }) } diff --git a/index.js b/index.js index 923a2e18..43ebfc16 100644 --- a/index.js +++ b/index.js @@ -13,10 +13,12 @@ async function init () { apiKey: get('apiKey'), collection: get('collection', required), environment: get('environment'), + envVar: safeParse(get('envVar')), globals: get('globals'), + globalVar: safeParse(get('globalVar')), iterationCount: num(get('iterationCount')), iterationData: get('iterationData'), - folder: split(get('folder')), + folder: safeParse(get('folder')), workingDir: get('workingDir'), insecureFileRead: safeParse(get('insecureFileRead')), timeout: num(get('timeout')), @@ -27,13 +29,13 @@ async function init () { insecure: safeParse(get('insecure')), bail: safeParse(get('bail')), suppressExitCode: safeParse(get('suppressExitCode')), - reporters: split(get('reporters')), + reporters: safeParse(get('reporters')), reporter: safeParse(get('reporter')), color: get('color'), sslClientCert: get('sslClientCert'), sslClientKey: get('sslClientKey'), sslClientPassphrase: get('sslClientPassphrase'), - sslClientCertList: split(get('sslClientCertList')), + sslClientCertList: safeParse(get('sslClientCertList')), sslExtraCaCerts: get('sslExtraCaCerts'), requestAgents: safeParse(get('requestAgents')), cookieJar: get('cookieJar') @@ -84,10 +86,6 @@ function num (i) { return i } -function split (str) { - return str ? str.split(',') : null -} - function removeEmpty (obj) { return Object.entries(obj) .filter(([_, v]) => v != null) @@ -95,9 +93,11 @@ function removeEmpty (obj) { } function runNewman (options) { - newman.run(options).on('done', (err, summary) => { + newman.run(options, (err) => { + core.setFailed('Newman run failed! ' + (err || '')) + }).on('done', (err, summary) => { if (!options.suppressExitCode && (err || summary.run.failures.length)) { - core.setFailed('Newman run failed!' + (err || '')) + core.setFailed('Newman run failed! ' + (err || '')) } }) } diff --git a/package-lock.json b/package-lock.json index 4e0c9b04..027940eb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "newman-action", - "version": "0.3.7", + "version": "1.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3aa3f65d..64018c11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "newman-action", - "version": "0.3.7", + "version": "1.0.0", "description": "Run Postman collections with Newman as a GitHub Action", "main": "dist/index.js", "repository": {