Compare commits

...

47 Commits

Author SHA1 Message Date
Frank Jogeleit
86014825e9 Merge branch 'main' of github.com:fjogeleit/http-request-action 2022-11-07 11:45:05 +01:00
Frank Jogeleit
575a0b6560 Update README.md
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-11-07 11:44:46 +01:00
Frank Jogeleit
56da042223 Merge pull request #73 from fjogeleit/url-encoded-tests
Test cases for URLEncoded contentType
2022-11-07 11:11:18 +01:00
Frank Jogeleit
cc3aff9cbe Testcases for URLEncoded contentType 2022-11-07 11:08:34 +01:00
Frank Jogeleit
c4ec44ca3e Merge pull request #72 from Uzlopak/strict
use strict
2022-11-04 10:35:28 +01:00
uzlopak
b497d195dc use strict 2022-11-04 10:28:14 +01:00
Uzlopak
d00a8759d6 jsdoc: async functions should return Promise (#70)
* jsdoc: async functions should return Promise

* update dist/index.js

* improve ci

* run anyway

* update dist

* test if esbuild produces deterministic builds

* Update ci.yml

* Update ci.yml

* specify target to node16

* another try

* Check for empty dataJson

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>

* build dist

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>

* build latest

* modify test step

* avoid skipping

* go back to ncc

* add back github.ref

* remove  additional stuff

* build dist/index.js

Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
Co-authored-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-11-03 21:35:53 +01:00
Frank Jogeleit
05a08b70e2 build dist
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-11-03 20:46:35 +01:00
Frank Jogeleit
6c12bc1f79 Check for empty dataJson
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-11-03 20:24:38 +01:00
Frank Jogeleit
6796716641 Merge pull request #66 from Uzlopak/improve-ci
Improve ci
2022-11-03 14:41:00 +01:00
Frank Jogeleit
dac2a9ae42 Merge pull request #69 from Uzlopak/add-build-action
add build-action
2022-11-03 14:35:36 +01:00
Frank Jogeleit
79a8b8af48 Merge pull request #62 from fjogeleit/url-encoded
Use URLSearchParams for application/x-www-form-urlencoded
2022-11-03 14:33:24 +01:00
Uzlopak
5bbd839c3e Update ci.yml 2022-11-03 14:29:31 +01:00
Uzlopak
cf482a5e80 Update and rename test.yml to ci.yml 2022-11-03 14:19:36 +01:00
Frank Jogeleit
76415c3c59 Merge pull request #67 from fjogeleit/dependabot/github_actions/actions/checkout-3
Bump actions/checkout from 2 to 3
2022-11-03 14:17:11 +01:00
Frank Jogeleit
3a818e40e8 Merge pull request #68 from fjogeleit/dependabot/npm_and_yarn/axios-1.1.3
Bump axios from 0.21.4 to 1.1.3
2022-11-03 14:16:57 +01:00
dependabot[bot]
daa3a7f756 Bump axios from 0.21.4 to 1.1.3
Bumps [axios](https://github.com/axios/axios) from 0.21.4 to 1.1.3.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.21.4...v1.1.3)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-03 13:13:42 +00:00
dependabot[bot]
7f60d0a379 Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-03 13:13:39 +00:00
Frank Jogeleit
9adf34b765 Merge pull request #64 from Uzlopak/add-dependabot
add dependabot.yml
2022-11-03 14:13:18 +01:00
Frank Jogeleit
0d5a8b7b31 Merge pull request #65 from Uzlopak/reorder-deps
reorder deps
2022-11-03 14:13:05 +01:00
uzlopak
a8547fbde9 add build-action 2022-11-03 12:06:20 +01:00
uzlopak
a8bcd97403 reorder deps 2022-11-03 12:01:52 +01:00
uzlopak
ce3525d612 add dependabot.yml 2022-11-03 11:56:13 +01:00
Frank Jogeleit
50750c1420 Use URLSearchParams for application/x-www-form-urlencoded 2022-11-01 10:01:33 +01:00
Frank Jogeleit
fd5cf60c69 Merge pull request #58 from fjogeleit/formdata-fix
Fix undefined data for files
2022-10-05 17:31:01 +02:00
Frank Jogeleit
2214f2de10 Fix undefined data for files
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-10-05 17:29:30 +02:00
Frank Jogeleit
9e07856983 Merge pull request #53 from fjogeleit/dependabot/npm_and_yarn/actions/core-1.9.1
Bump @actions/core from 1.9.0 to 1.9.1
2022-08-18 22:06:09 +02:00
dependabot[bot]
df4c18fdd5 Bump @actions/core from 1.9.0 to 1.9.1
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-18 19:59:33 +00:00
Nick Hills
4cbc7a46b2 Adding ability to return headers without setting debug mode (#51)
* Update httpClient.js
* Update README.md
* Update action.yml

Co-authored-by: Nick Hills <nick.hills@valtech.com>
2022-08-17 09:56:02 +02:00
Frank Jogeleit
cce3f3d779 Add new httpsCA input to README.md
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-07-23 15:18:23 +02:00
Frank Jogeleit
52ba495021 Merge pull request #49 from fjogeleit/custom-ca-support
Add input for custom CA
2022-07-19 10:29:59 +02:00
Frank Jogeleit
df00cdf429 Add input for custom CA
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-07-19 10:27:31 +02:00
Frank Jogeleit
e3313c1a5f Update Error Output
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-06-04 10:52:53 +02:00
Frank Jogeleit
d4c0bee13c Merge pull request #45 from yesjinu/docs/enhance-readme
docs: enhance README.md
2022-05-24 13:25:37 +02:00
Jinu Noh
435fe1dbc8 docs: enhance README.md 2022-05-24 19:22:08 +09:00
Frank Jogeleit
35336be18d Update README 2022-03-04 11:26:59 +01:00
Frank Jogeleit
f986377e36 Update Version 2022-03-04 11:22:31 +01:00
Frank Jogeleit
046e838b3a Dependency Update (#41)
Dependency Update
2022-03-04 11:20:10 +01:00
Frank Jogeleit
31fad16908 Merge pull request #39 from fjogeleit/dependabot/npm_and_yarn/follow-redirects-1.14.8
Bump follow-redirects from 1.14.7 to 1.14.8
2022-02-13 10:59:39 +01:00
dependabot[bot]
5c4179dc69 Bump follow-redirects from 1.14.7 to 1.14.8
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.7 to 1.14.8.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.14.7...v1.14.8)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-13 06:50:19 +00:00
Frank Jogeleit
d45f6649f6 Merge pull request #37 from Atlas-Authority/master
Support single file upload
2022-02-11 12:31:32 +01:00
Nhan Nguyen
f683177370 Support single file upload 2022-02-10 10:14:07 +07:00
Frank Jogeleit
a6980b2ca5 Merge pull request #36 from fjogeleit/dependency-update
Dependency Update
2022-01-16 17:29:35 +01:00
Frank Jogeleit
70ee000b97 Dependency Update
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-01-16 17:27:57 +01:00
Frank Jogeleit
5e30e204fc Update README.md 2021-12-10 17:44:42 +01:00
Frank Jogeleit
82d22dd60f Merge pull request #34 from understructure/docs-update
docs: clarification that data can be entered as key value pairs under appropriate conditions
2021-10-12 23:20:13 +02:00
Matthew Cloney
1ea54adf35 docs: clarification that data can be entered as key value pairs under appropriate conditions 2021-10-12 16:57:47 -04:00
12 changed files with 8063 additions and 3813 deletions

10
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'weekly'

35
.github/workflows/build-action.yml vendored Normal file
View File

@@ -0,0 +1,35 @@
name: Build Action
on:
workflow_dispatch:
inputs:
ref:
description: The branch
type: string
default: main
required: true
jobs:
build:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: |
npm ci
- name: Build Action
run: |
npm run build
- name: Update dist
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add ./dist &&
git commit -m "Update dist"
git push origin HEAD:${{ inputs.ref }}

163
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,163 @@
name: CI
on:
pull_request:
push:
branches:
- main
- 'releases/*'
jobs:
build:
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.user.login == 'dependabot[bot]'
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- id: ref
run: |
if [[ -n '${{ github.event.ref }}' ]]; then
branch="${{ github.event.ref }}"
echo "branch=$branch" >> $GITHUB_OUTPUT
else
branch="${{ github.event.pull_request.head.ref }}"
echo "branch=$branch" >> $GITHUB_OUTPUT
fi
- name: checkout repo
uses: actions/checkout@v3
with:
ref: ${{ steps.ref.outputs.branch }}
- uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install dependencies
run: |
npm ci
- name: Build Action
run: |
npm run build
- name: Update dist
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add ./dist
if ! git diff --quiet dist; then
git commit -m "Update dist"
git push origin HEAD:${{ steps.ref.outputs.branch }}
fi
integrity:
if: >
!failure() &&
!cancelled()
needs:
- build
runs-on: ubuntu-latest
steps:
- name: checkout repo
uses: actions/checkout@v3
with:
persist-credentials: false
- uses: actions/setup-node@v3
with:
node-version: '16.17.0'
- name: Build action
run: |
npm ci
npm run build
- name: Repository Integrity Check
run: |
git diff --quiet dist
test:
if: >
!failure() &&
!cancelled()
needs:
- integrity
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Request Postman Echo GET
uses: ./
with:
url: 'https://postman-echo.com/get'
method: 'GET'
- name: Request Postman Echo POST
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
- name: Request Postman Echo POST with Unescaped Newline
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
escapeData: 'true'
data: >-
{
"key":"multi line\ntest
text"
}
- name: Request Postman Echo BasicAuth
uses: ./
with:
url: 'https://postman-echo.com/basic-auth'
method: 'GET'
username: 'postman'
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
run: |
echo "test" > testfile.txt
- name: Request Postman Echo POST Multipart
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
- name: Request Postman Echo POST Multipart without data
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
- name: Request Postman Echo POST single file
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
file: "${{ github.workspace }}/testfile.txt"
- name: Request Postman Echo POST URLEncoded string data
uses: ./
with:
url: 'https://postman-echo.com/post'
contentType : 'application/x-www-form-urlencoded'
method: 'POST'
data: 'key=value'
- name: Request Postman Echo POST URLEncoded json data
uses: ./
with:
url: 'https://postman-echo.com/post'
contentType : 'application/x-www-form-urlencoded'
method: 'POST'
data: '{"key":"value"}'

View File

@@ -1,63 +0,0 @@
name: Test
on: [push, pull_request]
jobs:
request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Request Postman Echo GET
uses: ./
with:
url: 'https://postman-echo.com/get'
method: 'GET'
- name: Request Postman Echo POST
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
- name: Request Postman Echo POST with Unescaped Newline
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
escapeData: 'true'
data: >-
{
"key":"multi line\ntest
text"
}
- name: Request Postman Echo BasicAuth
uses: ./
with:
url: 'https://postman-echo.com/basic-auth'
method: 'GET'
username: 'postman'
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
run: |
echo "test" > testfile.txt
- name: Request Postman Echo POST Multipart
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'

View File

@@ -9,14 +9,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Deploy Stage
uses: fjogeleit/http-request-action@master
uses: fjogeleit/http-request-action@v1
with:
url: 'https://ansible.io/api/v2/job_templates/84/launch/'
method: 'POST'
username: ${{ secrets.AWX_USER }}
password: ${{ secrets.AWX_PASSWORD }}
customHeaders: '{"Content-Type": "application/json"}'
data: '{"key_1": "value_1", "key_2": "value_2"}'
```
### Versioning
`master` branch is deprecated. Please use `main` or `v1` to get the latest version of this action. It is recommended to use a fixed version.
### Request Configuration
|Argument| Description | Default |
@@ -24,8 +30,9 @@ jobs:
|url | Request URL | _required_ Field |
|method | Request Method| POST |
|contentType | Request ContentType| application/json |
|data | Request Body Content as JSON String, only for POST / PUT / PATCH Requests | '{}' |
|data | Request Body Content:<br>- text content like JSON or XML<br>- key=value pairs separated by '&' or JSON data and contentType: application/x-www-form-urlencoded<br><br>only for POST / PUT / PATCH Requests | '{}' |
|files | Map of key / absolute file paths send as multipart/form-data request to the API, if set the contentType is set to multipart/form-data, values provided by data will be added as additional FormData values, nested objects are not supported. **Example provided in the _test_ Workflow of this Action** | '{}' |
|file | Single absolute file path send as `application/octet-stream` request to the API, if set the contentType is set to `application/octet-stream`. This input will be ignored if either `data` or `files` input is present. **Example provided in the _test_ Workflow of this Action** ||
|timeout| Request Timeout in ms | 5000 (5s) |
|username| Username for Basic Auth ||
|password| Password for Basic Auth ||
@@ -34,24 +41,29 @@ jobs:
|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' ||
|httpsCA| Certificate authority as string in PEM format ||
### Response
| Variable | Description |
|---|---|
`response` | Response as JSON String
`headers` | Headers
To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`
To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`. You can also access specific field from the response data using [fromJson()](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson) expression.
```yaml
steps:
- name: Make Request
id: myRequest
uses: fjogeleit/http-request-action@master
uses: fjogeleit/http-request-action@v1
with:
url: "http://yoursite.com/api"
- name: Show Response
run: echo ${{ steps.myRequest.outputs.response }}
run: |
echo ${{ steps.myRequest.outputs.response }}
echo ${{ steps.myRequest.outputs.headers }}
echo ${{ fromJson(steps.myRequest.outputs.response).field_you_want_to_access }}
```
### Additional Information
@@ -60,4 +72,4 @@ Additional information is available if debug logging is enabled:
- Instance Configuration (Url / Timeout / Headers)
- 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`
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

@@ -19,6 +19,9 @@ inputs:
description: 'Map of absolute file paths as JSON String'
required: false
default: '{}'
file:
description: 'A single absolute file path'
required: false
username:
description: 'Auth Username'
required: false
@@ -44,9 +47,14 @@ inputs:
escapeData:
description: 'Escape newlines in data string content'
required: false
httpsCA:
description: 'Certificate authority as string in PEM format'
required: false
outputs:
response:
description: 'HTTP Response Content'
headers:
description: 'HTTP Response Headers'
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'

11256
dist/index.js vendored

File diff suppressed because one or more lines are too long

195
package-lock.json generated
View File

@@ -1,32 +1,47 @@
{
"name": "http-request-action",
"version": "1.8.0",
"version": "1.11.2",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"version": "1.8.0",
"name": "http-request-action",
"version": "1.11.2",
"license": "MIT",
"dependencies": {
"@zeit/ncc": "^0.22",
"axios": "^0.21.4",
"form-data": "^4.0.0"
"@actions/core": "^1.10.0"
},
"devDependencies": {
"@actions/core": "^1.2.6"
"@vercel/ncc": "^0.34.0",
"axios": "^1.1.3",
"form-data": "^4.0.0"
},
"engines": {
"node": ">=16.0.0"
}
},
"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
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"dependencies": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
}
},
"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.",
"node_modules/@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dependencies": {
"tunnel": "^0.0.6"
}
},
"node_modules/@vercel/ncc": {
"version": "0.34.0",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz",
"integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==",
"dev": true,
"bin": {
"ncc": "dist/ncc/cli.js"
}
@@ -34,20 +49,25 @@
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"dev": true
},
"node_modules/axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz",
"integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==",
"dev": true,
"dependencies": {
"follow-redirects": "^1.14.0"
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.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==",
"dev": true,
"dependencies": {
"delayed-stream": "~1.0.0"
},
@@ -58,15 +78,17 @@
"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=",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"dev": true,
"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==",
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"dev": true,
"funding": [
{
"type": "individual",
@@ -86,6 +108,7 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dev": true,
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
@@ -96,54 +119,95 @@
}
},
"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==",
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"dev": true,
"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==",
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dev": true,
"dependencies": {
"mime-db": "1.49.0"
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"dev": true
},
"node_modules/tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"engines": {
"node": ">=0.6.11 <=0.7.0 || >=0.7.3"
}
},
"node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"bin": {
"uuid": "dist/bin/uuid"
}
}
},
"dependencies": {
"@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
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"requires": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
}
},
"@zeit/ncc": {
"version": "0.22.3",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ=="
"@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"requires": {
"tunnel": "^0.0.6"
}
},
"@vercel/ncc": {
"version": "0.34.0",
"resolved": "https://registry.npmjs.org/@vercel/ncc/-/ncc-0.34.0.tgz",
"integrity": "sha512-G9h5ZLBJ/V57Ou9vz5hI8pda/YQX5HQszCs3AmIus3XzsmRn/0Ptic5otD3xVST8QLKk7AMk7AqpsyQGN7MZ9A==",
"dev": true
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"dev": true
},
"axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.1.3.tgz",
"integrity": "sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==",
"dev": true,
"requires": {
"follow-redirects": "^1.14.0"
"follow-redirects": "^1.15.0",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"dev": true,
"requires": {
"delayed-stream": "~1.0.0"
}
@@ -151,17 +215,20 @@
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"dev": true
},
"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=="
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"dev": true
},
"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==",
"dev": true,
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
@@ -169,17 +236,35 @@
}
},
"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=="
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"dev": true
},
"mime-types": {
"version": "2.1.32",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.32.tgz",
"integrity": "sha512-hJGaVS4G4c9TSMYh2n6SQAGrC4RnfU+daP8G7cSCmaqNjiOoUY0VHCMS42pxnQmVF1GWwFhbHWn3RIxCqTmZ9A==",
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dev": true,
"requires": {
"mime-db": "1.49.0"
"mime-db": "1.52.0"
}
},
"proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"dev": true
},
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg=="
},
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "http-request-action",
"version": "1.8.0",
"version": "1.11.2",
"description": "",
"main": "src/index.js",
"private": false,
@@ -19,11 +19,14 @@
},
"homepage": "https://github.com/fjogeleit/http-request-action#readme",
"devDependencies": {
"@actions/core": "^1.2.6"
"@vercel/ncc": "^0.34.0",
"axios": "^1.1.3",
"form-data": "^4.0.0"
},
"dependencies": {
"@zeit/ncc": "^0.22",
"axios": "^0.21.4",
"form-data": "^4.0.0"
"@actions/core": "^1.10.0"
},
"engines": {
"node": ">=16.0.0"
}
}

View File

@@ -1,3 +1,5 @@
'use strict'
const core = require("@actions/core");
class GithubActions {

View File

@@ -1,25 +1,32 @@
const axios = require("axios");
'use strict'
const axios = require('axios');
const FormData = require('form-data')
const fs = require('fs')
const url = require('url');
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
const HEADER_CONTENT_TYPE = 'Content-Type'
const CONTENT_TYPE_URLENCODED = 'application/x-www-form-urlencoded'
/**
* @param {Object} param0
* @param {string} param0.method HTTP Method
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} param0.instanceConfig
* @param {axios.AxiosRequestConfig} 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 {string} param0.file Single request file (absolute path)
* @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}
* @returns {Promise<void>}
*/
const request = async({ method, instanceConfig, data, files, auth, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
const request = async({ method, instanceConfig, data, files, file, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
try {
if (escapeData) {
data = data.replace(/"[^"]*"/g, (match) => {
@@ -32,8 +39,8 @@ const request = async({ method, instanceConfig, data, files, auth, actions, igno
}
if (files && files !== '{}') {
filesJson = convertToJSON(files)
dataJson = convertToJSON(data)
let filesJson = convertToJSON(files)
let dataJson = convertToJSON(data)
if (Object.keys(filesJson).length > 0) {
try {
@@ -46,8 +53,20 @@ const request = async({ method, instanceConfig, data, files, auth, actions, igno
}
}
// Only consider file if neither data nor files provided
if ((!data || data === '{}') && (!files || files === '{}') && file) {
data = fs.createReadStream(file)
updateConfigForFile(instanceConfig, file, actions)
}
if (instanceConfig.headers[HEADER_CONTENT_TYPE] === CONTENT_TYPE_URLENCODED) {
let dataJson = convertToJSON(data)
if (typeof dataJson === 'object' && Object.keys(dataJson).length) {
data = (new url.URLSearchParams(dataJson)).toString();
}
}
const requestData = {
auth,
method,
data,
maxContentLength: Infinity,
@@ -63,9 +82,12 @@ const request = async({ method, instanceConfig, data, files, auth, actions, igno
const response = await instance.request(requestData)
actions.setOutput('response', JSON.stringify(response.data))
actions.setOutput('headers', response.headers)
} catch (error) {
if (error.toJSON) {
actions.setOutput('requestError', JSON.stringify(error.toJSON()));
if ((typeof error === 'object') && (error.isAxiosError === true)) {
const { name, message, code, response } = error
actions.setOutput('requestError', JSON.stringify({ name, message, code, status: response && response.status ? response.status : null }));
}
if (error.response && ignoredCodes.includes(error.response.status)) {
@@ -89,7 +111,7 @@ const request = async({ method, instanceConfig, data, files, auth, actions, igno
*/
const convertToJSON = (value) => {
try {
return JSON.parse(value)
return JSON.parse(value) || {}
} catch(e) {
return {}
}
@@ -102,7 +124,7 @@ const convertToJSON = (value) => {
* @returns {FormData}
*/
const convertToFormData = (data, files) => {
formData = new FormData()
const formData = new FormData()
for (const [key, value] of Object.entries(data)) {
formData.append(key, value)
@@ -120,7 +142,7 @@ const convertToFormData = (data, files) => {
* @param {FormData} formData
* @param {*} actions
*
* @returns {{ baseURL: string; timeout: number; headers: { [name: string]: string } }}
* @returns {Promise<{ baseURL: string; timeout: number; headers: { [name: string]: string } }>}
*/
const updateConfig = async (instanceConfig, formData, actions) => {
try {
@@ -143,6 +165,30 @@ const updateConfig = async (instanceConfig, formData, actions) => {
}
}
/**
* @param instanceConfig
* @param filePath
* @param {*} actions
*
* @returns {{ baseURL: string; timeout: number; headers: { [name: string]: string } }}
*/
const updateConfigForFile = (instanceConfig, filePath, actions) => {
try {
const { size } = fs.statSync(filePath)
return {
...instanceConfig,
headers: {
...instanceConfig.headers,
'Content-Length': size,
'Content-Type': 'application/octet-stream'
}
}
} catch(error) {
actions.setFailed({ message: `Unable to read Content-Length: ${error.message}`, data, files })
}
}
/**
* @param {FormData} formData
*

View File

@@ -1,8 +1,11 @@
const core = require("@actions/core");
'use strict'
const core = require('@actions/core');
const axios = require('axios');
const https = require('https');
const { request, METHOD_POST } = require('./httpClient');
const { GithubActions } = require('./githubActions');
let auth = undefined
let customHeaders = {}
if (!!core.getInput('customHeaders')) {
@@ -15,27 +18,33 @@ if (!!core.getInput('customHeaders')) {
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
if (!!core.getInput('username') || !!core.getInput('password')) {
core.debug('Add BasicHTTP Auth config')
auth = {
username: core.getInput('username'),
password: core.getInput('password')
}
}
if (!!core.getInput('bearerToken')) {
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
}
/** @type {axios.AxiosRequestConfig} */
const instanceConfig = {
baseURL: core.getInput('url', { required: true }),
timeout: parseInt(core.getInput('timeout') || 5000, 10),
headers: { ...headers, ...customHeaders }
}
if (!!core.getInput('httpsCA')) {
instanceConfig.httpsAgent = new https.Agent({ ca: core.getInput('httpsCA') })
}
if (!!core.getInput('username') || !!core.getInput('password')) {
core.debug('Add BasicHTTP Auth config')
instanceConfig.auth = {
username: core.getInput('username'),
password: core.getInput('password')
}
}
const data = core.getInput('data') || '{}';
const files = core.getInput('files') || '{}';
const file = core.getInput('file')
const method = core.getInput('method') || METHOD_POST;
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
const escapeData = core.getInput('escapeData') === 'true';
@@ -47,4 +56,4 @@ 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() })
request({ data, method, instanceConfig, preventFailureOnNoResponse, escapeData, files, file, ignoredCodes, actions: new GithubActions() })