Compare commits

...

9 Commits

Author SHA1 Message Date
Frank Jogeleit
8e939c608a dependency updates
Signed-off-by: Frank Jogeleit <fj@move-elevator.de>
2021-09-09 14:42:30 +02:00
Frank Jogeleit
7c5a3f2e70 Merge pull request #30 from fjogeleit/dependabot/npm_and_yarn/axios-0.21.2
Bump axios from 0.21.1 to 0.21.2
2021-09-09 14:30:28 +02:00
dependabot[bot]
78bba76cbe Bump axios from 0.21.1 to 0.21.2
Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.2.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.21.1...v0.21.2)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-09 11:38:52 +00:00
Frank Jogeleit
3e3e6b3eec Update test.yml 2021-07-22 14:52:06 +02:00
Frank Jogeleit
0929a0c636 Ignored status codes (#26)
* Implement StatusCode ignore list
2021-03-19 17:28:53 +01:00
Frank Jogeleit
bd043fe286 Build new version 2021-02-19 12:51:47 +01:00
Frank Jogeleit
7626a13e42 Disable MaxContentLength and MaxBodyLength check (#23)
* Disable MaxContentLength and MaxBodyLength check
2021-02-19 11:36:10 +01:00
Scott W Harden
48dc3972df more documentation with code sample (#21)
* improve debug logging documentation
* document how to log response content
* add syntax highlighting
* improve description

This action can be used to do more than just interact with Ansible AWS. I rephrased the description to emphasize its general utility.
2021-01-26 17:49:24 +01:00
Frank Jogeleit
84e61f1a56 Update version 2021-01-24 14:09:17 +01:00
8 changed files with 797 additions and 166 deletions

View File

@@ -10,20 +10,20 @@ jobs:
with: with:
ref: ${{ github.ref }} ref: ${{ github.ref }}
- name: Request Postment Echo GET - name: Request Postman Echo GET
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/get' url: 'https://postman-echo.com/get'
method: 'GET' method: 'GET'
- name: Request Postment Echo POST - name: Request Postman Echo POST
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/post' url: 'https://postman-echo.com/post'
method: 'POST' method: 'POST'
data: '{ "key": "value" }' data: '{ "key": "value" }'
- name: Request Postment Echo POST with Unescaped Newline - name: Request Postman Echo POST with Unescaped Newline
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/post' url: 'https://postman-echo.com/post'
@@ -35,7 +35,7 @@ jobs:
text" text"
} }
- name: Request Postment Echo BasicAuth - name: Request Postman Echo BasicAuth
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/basic-auth' url: 'https://postman-echo.com/basic-auth'
@@ -43,12 +43,18 @@ jobs:
username: 'postman' username: 'postman'
password: 'password' password: 'password'
- name: Request Postman Echo with 404 Response and ignore failure code
uses: ./
with:
url: 'https://postman-echo.com/status/404'
method: 'GET'
ignoreStatusCodes: '404'
- name: Create Test File - name: Create Test File
id: image
run: | run: |
echo "test" > testfile.txt echo "test" > testfile.txt
- name: Request Postment Echo POST Multipart - name: Request Postman Echo POST Multipart
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/post' url: 'https://postman-echo.com/post'

View File

@@ -1,9 +1,9 @@
# HTTP Request Action # HTTP Request Action
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX **Create HTTP Requests from GitHub Actions.** This action allows GitHub events to engage with tools like Ansible AWX that use HTTP APIs.
Example Usage: ### Example
``` ```yaml
jobs: jobs:
deployment: deployment:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -17,7 +17,7 @@ jobs:
password: ${{ secrets.AWX_PASSWORD }} password: ${{ secrets.AWX_PASSWORD }}
``` ```
### Input Arguments ### Request Configuration
|Argument| Description | Default | |Argument| Description | Default |
|--------|---------------|-----------| |--------|---------------|-----------|
@@ -31,17 +31,33 @@ jobs:
|password| Password for Basic Auth || |password| Password for Basic Auth ||
|bearerToken| Bearer Authentication Token (without Bearer Prefix) || |bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|customHeaders| Additional header values as JSON string, keys in this object overwrite default headers like Content-Type |'{}'| |customHeaders| Additional header values as JSON string, keys in this object overwrite default headers like Content-Type |'{}'|
|preventFailureOnNoResponse| Prevent this Action to fail if the request respond without an response. Use 'true' (string) as value to enable it ||
|escapeData| Escape newlines in data string content. Use 'true' (string) as value to enable it || |escapeData| Escape newlines in data string content. Use 'true' (string) as value to enable it ||
|preventFailureOnNoResponse| Prevent this Action to fail if the request respond without an response. Use 'true' (string) as value to enable it ||
|ignoreStatusCodes| Prevent this Action to fail if the request respond with one of the configured Status Codes. Example: '404,401' ||
### Output ### Response
- `response` Request Response as JSON String | Variable | Description |
|---|---|
`response` | Response as JSON String
To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`
### Debug Informations ```yaml
steps:
- name: Make Request
id: myRequest
uses: fjogeleit/http-request-action@master
with:
url: "http://yoursite.com/api"
- name: Show Response
run: echo ${{ steps.myRequest.outputs.response }}
```
Enable Debug mode to get informations about ### Additional Information
Additional information is available if debug logging is enabled:
- Instance Configuration (Url / Timeout / Headers) - Instance Configuration (Url / Timeout / Headers)
- Request Data (Body / Auth / Method) - Request Data (Body / Auth / Method)
To [enable debug logging in GitHub Actions](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging) create a secret `ACTIONS_RUNNER_DEBUG` with a value of `true`

View File

@@ -38,6 +38,9 @@ inputs:
preventFailureOnNoResponse: preventFailureOnNoResponse:
description: 'Prevent this Action to fail if the request respond without an response' description: 'Prevent this Action to fail if the request respond without an response'
required: false required: false
ignoreStatusCodes:
description: 'Prevent this Action to fail if the request respond with one of the configured StatusCodes'
required: false
escapeData: escapeData:
description: 'Escape newlines in data string content' description: 'Escape newlines in data string content'
required: false required: false

682
dist/index.js vendored

File diff suppressed because one or more lines are too long

156
package-lock.json generated
View File

@@ -1,13 +1,125 @@
{ {
"name": "http-request-action", "name": "http-request-action",
"version": "1.7.0", "version": "1.8.0",
"lockfileVersion": 1, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": {
"": {
"version": "1.8.0",
"license": "MIT",
"dependencies": {
"@zeit/ncc": "^0.22",
"axios": "^0.21.4",
"form-data": "^4.0.0"
},
"devDependencies": {
"@actions/core": "^1.2.6"
}
},
"node_modules/@actions/core": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.5.0.tgz",
"integrity": "sha512-eDOLH1Nq9zh+PJlYLqEMkS/jLQxhksPNmUGNBHfa4G+tQmnIhzpctxmchETtVGyBOvXgOVVpYuE40+eS4cUnwQ==",
"dev": true
},
"node_modules/@zeit/ncc": {
"version": "0.22.3",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==",
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
"bin": {
"ncc": "dist/ncc/cli.js"
}
},
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"node_modules/axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"dependencies": {
"follow-redirects": "^1.14.0"
}
},
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/follow-redirects": {
"version": "1.14.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz",
"integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/mime-db": {
"version": "1.49.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
"integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.32",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
"dependencies": {
"mime-db": "1.49.0"
},
"engines": {
"node": ">= 0.6"
}
}
},
"dependencies": { "dependencies": {
"@actions/core": { "@actions/core": {
"version": "1.2.6", "version": "1.5.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.5.0.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==", "integrity": "sha512-eDOLH1Nq9zh+PJlYLqEMkS/jLQxhksPNmUGNBHfa4G+tQmnIhzpctxmchETtVGyBOvXgOVVpYuE40+eS4cUnwQ==",
"dev": true "dev": true
}, },
"@zeit/ncc": { "@zeit/ncc": {
@@ -21,11 +133,11 @@
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"axios": { "axios": {
"version": "0.21.1", "version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"requires": { "requires": {
"follow-redirects": "^1.10.0" "follow-redirects": "^1.14.0"
} }
}, },
"combined-stream": { "combined-stream": {
@@ -42,14 +154,14 @@
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"follow-redirects": { "follow-redirects": {
"version": "1.13.1", "version": "1.14.3",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.3.tgz",
"integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==" "integrity": "sha512-3MkHxknWMUtb23apkgz/83fDoe+y+qr0TdgacGIA7bew+QLBo3vdgEN2xEsuXNivpFy4CyDhBBZnNZOtalmenw=="
}, },
"form-data": { "form-data": {
"version": "3.0.0", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.0.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"requires": { "requires": {
"asynckit": "^0.4.0", "asynckit": "^0.4.0",
"combined-stream": "^1.0.8", "combined-stream": "^1.0.8",
@@ -57,16 +169,16 @@
} }
}, },
"mime-db": { "mime-db": {
"version": "1.45.0", "version": "1.49.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.45.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.49.0.tgz",
"integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==" "integrity": "sha512-CIc8j9URtOVApSFCQIF+VBkX1RwXp/oMMOrqdyXSBXq5RWNEsRfyj1kiRnQgmNXmHxPoFIxOroKA3zcU9P+nAA=="
}, },
"mime-types": { "mime-types": {
"version": "2.1.28", "version": "2.1.32",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
"integrity": "sha512-0TO2yJ5YHYr7M2zzT7gDU1tbwHxEUWBCLt0lscSNpcdAfFyJOVEpRYNS7EXVcTLNj/25QO8gulHC5JtTzSE2UQ==", "integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
"requires": { "requires": {
"mime-db": "1.45.0" "mime-db": "1.49.0"
} }
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "http-request-action", "name": "http-request-action",
"version": "1.7.0", "version": "1.8.0",
"description": "", "description": "",
"main": "src/index.js", "main": "src/index.js",
"private": false, "private": false,
@@ -13,7 +13,7 @@
}, },
"keywords": [], "keywords": [],
"author": "", "author": "",
"license": "ISC", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/fjogeleit/http-request-action/issues" "url": "https://github.com/fjogeleit/http-request-action/issues"
}, },
@@ -23,7 +23,7 @@
}, },
"dependencies": { "dependencies": {
"@zeit/ncc": "^0.22", "@zeit/ncc": "^0.22",
"axios": "^0.21.1", "axios": "^0.21.4",
"form-data": "^3.0.0" "form-data": "^4.0.0"
} }
} }

View File

@@ -5,11 +5,25 @@ const fs = require('fs')
const METHOD_GET = 'GET' const METHOD_GET = 'GET'
const METHOD_POST = 'POST' const METHOD_POST = 'POST'
const request = async({ method, instanceConfig, data, files, auth, actions, preventFailureOnNoResponse, escapeData }) => { /**
* @param {Object} param0
* @param {string} param0.method HTTP Method
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} param0.instanceConfig
* @param {string} param0.data Request Body as string, default {}
* @param {string} param0.files Map of Request Files (name: absolute path) as JSON String, default: {}
* @param {{ username: string; password: string }|undefined} param0.auth Optional HTTP Basic Auth
* @param {*} param0.actions
* @param {number[]} param0.ignoredCodes Prevent Action to fail if the API response with one of this StatusCodes
* @param {boolean} param0.preventFailureOnNoResponse Prevent Action to fail if the API respond without Response
* @param {boolean} param0.escapeData Escape unescaped JSON content in data
*
* @returns {void}
*/
const request = async({ method, instanceConfig, data, files, auth, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
try { try {
if (escapeData) { if (escapeData) {
data = data.replace(/"[^"]*"/g, (match) => { data = data.replace(/"[^"]*"/g, (match) => {
return match.replace(/[\n\r]\s*/g, "\\n"); return match.replace(/[\n\r]\s*/g, "\\n");
}); });
} }
@@ -35,7 +49,9 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
const requestData = { const requestData = {
auth, auth,
method, method,
data data,
maxContentLength: Infinity,
maxBodyLength: Infinity
} }
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig)) actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
@@ -49,11 +65,13 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
actions.setOutput('response', JSON.stringify(response.data)) actions.setOutput('response', JSON.stringify(response.data))
} catch (error) { } catch (error) {
if (error.toJSON) { if (error.toJSON) {
actions.setOutput(JSON.stringify(error.toJSON())); actions.setOutput('requestError', JSON.stringify(error.toJSON()));
} }
if (error.response) { if (error.response && ignoredCodes.includes(error.response.status)) {
actions.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data })) actions.warning(JSON.stringify({ code: error.response.status, message: error.response.data }))
} else if (error.response) {
actions.setFailed(JSON.stringify({ code: error.response.status, message: error.response.data }))
} else if (error.request && !preventFailureOnNoResponse) { } else if (error.request && !preventFailureOnNoResponse) {
actions.setFailed(JSON.stringify({ error: "no response received" })); actions.setFailed(JSON.stringify({ error: "no response received" }));
} else if (error.request && preventFailureOnNoResponse) { } else if (error.request && preventFailureOnNoResponse) {
@@ -64,6 +82,11 @@ const request = async({ method, instanceConfig, data, files, auth, actions, prev
} }
} }
/**
* @param {string} value
*
* @returns {Object}
*/
const convertToJSON = (value) => { const convertToJSON = (value) => {
try { try {
return JSON.parse(value) return JSON.parse(value)
@@ -72,6 +95,12 @@ const convertToJSON = (value) => {
} }
} }
/**
* @param {Object} data
* @param {Object} files
*
* @returns {FormData}
*/
const convertToFormData = (data, files) => { const convertToFormData = (data, files) => {
formData = new FormData() formData = new FormData()
@@ -86,6 +115,13 @@ const convertToFormData = (data, files) => {
return formData return formData
} }
/**
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} instanceConfig
* @param {FormData} formData
* @param {*} actions
*
* @returns {{ baseURL: string; timeout: number; headers: { [name: string]: string } }}
*/
const updateConfig = async (instanceConfig, formData, actions) => { const updateConfig = async (instanceConfig, formData, actions) => {
try { try {
const formHeaders = formData.getHeaders() const formHeaders = formData.getHeaders()
@@ -107,6 +143,11 @@ const updateConfig = async (instanceConfig, formData, actions) => {
} }
} }
/**
* @param {FormData} formData
*
* @returns {Promise<number>}
*/
const contentLength = (formData) => new Promise((resolve, reject) => { const contentLength = (formData) => new Promise((resolve, reject) => {
formData.getLength((err, length) => { formData.getLength((err, length) => {
if (err) { if (err) {

View File

@@ -40,4 +40,11 @@ const method = core.getInput('method') || METHOD_POST;
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true'; const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
const escapeData = core.getInput('escapeData') === 'true'; const escapeData = core.getInput('escapeData') === 'true';
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, files, actions: new GithubActions() }) const ignoreStatusCodes = core.getInput('ignoreStatusCodes')
let ignoredCodes = []
if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
}
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, files, ignoredCodes, actions: new GithubActions() })