mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-05 17:45:55 +08:00
Compare commits
1 Commits
main
...
support-fi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f415ec7c5 |
8
.github/workflows/build-action.yml
vendored
8
.github/workflows/build-action.yml
vendored
@@ -14,12 +14,12 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout repo
|
||||
uses: actions/checkout@v6.0.2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.inputs.ref }}
|
||||
- uses: actions/setup-node@v6
|
||||
ref: ${{ inputs.ref }}
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: '.tool-versions'
|
||||
node-version: '16'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm ci
|
||||
|
||||
150
.github/workflows/ci.yml
vendored
150
.github/workflows/ci.yml
vendored
@@ -18,15 +18,20 @@ jobs:
|
||||
steps:
|
||||
- id: ref
|
||||
run: |
|
||||
branch="${{ github.event.ref || github.event.pull_request.head.ref }}"
|
||||
echo "branch=$branch" >> $GITHUB_OUTPUT
|
||||
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@v6.0.2
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ steps.ref.outputs.branch }}
|
||||
- uses: actions/setup-node@v6
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version-file: '.tool-versions'
|
||||
node-version: '16'
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
npm ci
|
||||
@@ -42,3 +47,138 @@ jobs:
|
||||
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@v4
|
||||
with:
|
||||
persist-credentials: false
|
||||
- uses: actions/setup-node@v4
|
||||
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@v4
|
||||
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" > testfile1.txt
|
||||
echo "test" > testfile2.txt
|
||||
|
||||
- name: Request Postman Echo POST Multipart
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
data: '{ "key": "value" }'
|
||||
files: '{ "file": "${{ github.workspace }}/testfile1.txt" }'
|
||||
|
||||
- name: Request Postman Echo POST Multipart File Array
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
data: '{ "key": "value" }'
|
||||
files: '{ "file": ["${{ github.workspace }}/testfile1.txt", "${{ github.workspace }}/testfile2.txt"] }'
|
||||
|
||||
- name: Request Postman Echo POST and persist response
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
file: "${{ github.workspace }}/testfile1.txt"
|
||||
responseFile: "${{ github.workspace }}/response.json"
|
||||
- name: Output responseFile
|
||||
run: |
|
||||
cat "${{ github.workspace }}/response.json"
|
||||
|
||||
- name: Request Postman Echo POST Multipart without data
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
files: '{ "file": "${{ github.workspace }}/testfile1.txt" }'
|
||||
|
||||
- name: Request Postman Echo POST single file
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
file: "${{ github.workspace }}/testfile1.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"}'
|
||||
|
||||
337
.github/workflows/it-tests.yml
vendored
337
.github/workflows/it-tests.yml
vendored
@@ -1,337 +0,0 @@
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
jobs:
|
||||
|
||||
test-method-get-on-existing-url:
|
||||
name: "IT Test - Request Postman Echo GET"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with GET and a valid URL
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/get'
|
||||
method: 'GET'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-method-post-on-existing-url:
|
||||
name: "IT Test - Request Postman Echo POST"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with POST using valid data
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: "https://postman-echo.com/post"
|
||||
method: 'POST'
|
||||
data: '{ "key": "value" }'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-method-post-on-existing-url-with-unescaped-newline:
|
||||
name: "IT Test - Request Postman Echo POST with Unescaped Newline"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with POST using unescaped new line within data
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: "https://postman-echo.com/post"
|
||||
method: 'POST'
|
||||
escapeData: 'true'
|
||||
data: >-
|
||||
{
|
||||
"key":"multi line\ntest
|
||||
text"
|
||||
}
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-basic-auth:
|
||||
name: "IT Test - Request Postman Echo BasicAuth"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with valid BasicAuth parameters
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/basic-auth'
|
||||
method: 'GET'
|
||||
username: 'postman'
|
||||
password: 'password'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200 as this URL exists
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-input-ignore-failure-code-404:
|
||||
name: "IT Test - Request Postman Echo with 404 Response and ignore failure code"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with unknown URL and ignoreStatusCode 404 for it
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/status/404'
|
||||
method: 'GET'
|
||||
ignoreStatusCodes: '404'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must 404
|
||||
with:
|
||||
expected: '404'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then the outcome value must be success as the error 404 is ignored
|
||||
with:
|
||||
expected: 'success'
|
||||
actual: ${{ steps.execution.outcome }}
|
||||
comparison: exact
|
||||
|
||||
test-input-ignore-failure-multiple-codes-401-404:
|
||||
name: "IT Test - Request Postman Echo with 404 Response and ignore failure code"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with unknown URL and ignore status codes 401,404
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/status/404'
|
||||
method: 'GET'
|
||||
ignoreStatusCodes: '401,404'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 404
|
||||
with:
|
||||
expected: '404'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then the outcome value must be success as the error 404 is ignored
|
||||
with:
|
||||
expected: 'success'
|
||||
actual: ${{ steps.execution.outcome }}
|
||||
comparison: exact
|
||||
|
||||
test-input-files:
|
||||
name: "IT Test - Request Postman Echo POST Multipart"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Create Test File
|
||||
run: |
|
||||
echo "test" > testfile.txt
|
||||
- name: Given the gh-action is used with file and data
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
data: '{ "key": "value" }'
|
||||
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-input-responseFile:
|
||||
name: "IT Test - Request Postman Echo POST and persist response"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Create Test File
|
||||
run: |
|
||||
echo "test" > testfile2.txt
|
||||
- name: Given the gh-action is used with file and responseFile
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
file: "${{ github.workspace }}/testfile2.txt"
|
||||
responseFile: "${{ github.workspace }}/response.json"
|
||||
|
||||
- name: Output responseFile
|
||||
id: execution-response-file
|
||||
run: |
|
||||
echo "response_content=$(cat ${{ github.workspace }}/response.json)" >> $GITHUB_OUTPUT
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.response_content value must include
|
||||
with:
|
||||
expected: '{"args":{},"data":"test\n","files":{},"form":{},"headers":{"host":"postman-echo.com",'
|
||||
actual: ${{ steps.execution-response-file.outputs.response_content }}
|
||||
comparison: contains
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.response_content value must include
|
||||
with:
|
||||
expected: '"accept":"application/json, text/plain, */*"'
|
||||
actual: ${{ steps.execution-response-file.outputs.response_content }}
|
||||
comparison: contains
|
||||
|
||||
test-input-files-without-data:
|
||||
name: "IT Test - Request Postman Echo POST Multipart without data"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Create Test File
|
||||
run: |
|
||||
echo "test" > testfile3.txt
|
||||
- name: Given the gh-action is used with file
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
files: '{ "file": "${{ github.workspace }}/testfile3.txt" }'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-input-file-with-single-file:
|
||||
name: "IT Test - Request Postman Echo POST single file"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Create Test File
|
||||
run: |
|
||||
echo "test" > testfile4.txt
|
||||
- name: Given the gh-action is used with file
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
file: "${{ github.workspace }}/testfile4.txt"
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-input-data-with-url-encoded-string:
|
||||
name: "IT Test - Request Postman Echo POST URLEncoded string data"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with data form url encoded
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
contentType : 'application/x-www-form-urlencoded'
|
||||
method: 'POST'
|
||||
data: 'key=value'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-input-data-with-url-encoded-json-data:
|
||||
name: "IT Test - Request Postman Echo POST URLEncoded json data"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with json data
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
contentType : 'application/x-www-form-urlencoded'
|
||||
method: 'POST'
|
||||
data: '{"key":"value"}'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
test-delete-http-method:
|
||||
name: "IT Test - Request Postman Echo DELETE"
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
||||
- name: Given the gh-action is used with method DELETE
|
||||
id: execution
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/delete'
|
||||
contentType : 'application/json'
|
||||
method: 'DELETE'
|
||||
data: '{"key":"value"}'
|
||||
|
||||
- uses: nick-fields/assert-action@aa0067e01f0f6545c31755d6ca128c5a3a14f6bf # v2
|
||||
name: Then outputs.status value must be 200
|
||||
with:
|
||||
expected: '200'
|
||||
actual: ${{ steps.execution.outputs.status }}
|
||||
comparison: exact
|
||||
|
||||
it-tests:
|
||||
name: "All IT Tests have to pass"
|
||||
runs-on: ubuntu-latest
|
||||
if: always()
|
||||
needs:
|
||||
# Add your tests here so that they prevent the merge of broken changes
|
||||
- test-method-get-on-existing-url
|
||||
- test-method-post-on-existing-url
|
||||
- test-method-post-on-existing-url-with-unescaped-newline
|
||||
- test-basic-auth
|
||||
- test-input-ignore-failure-code-404
|
||||
- test-input-ignore-failure-multiple-codes-401-404
|
||||
- test-input-files
|
||||
- test-input-responseFile
|
||||
- test-input-files-without-data
|
||||
- test-input-file-with-single-file
|
||||
- test-input-data-with-url-encoded-string
|
||||
- test-input-data-with-url-encoded-json-data
|
||||
- test-delete-http-method
|
||||
steps:
|
||||
- uses: re-actors/alls-green@05ac9388f0aebcb5727afa17fcccfecd6f8ec5fe # v1.2.2
|
||||
with:
|
||||
jobs: ${{ toJSON(needs) }}
|
||||
31
.github/workflows/release.yml
vendored
31
.github/workflows/release.yml
vendored
@@ -1,31 +0,0 @@
|
||||
---
|
||||
name: Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*.*.*"
|
||||
|
||||
jobs:
|
||||
create:
|
||||
name: Create
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write
|
||||
steps:
|
||||
- name: Checkout ${{ github.repository }}
|
||||
uses: actions/checkout@v6.0.2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
ref: "${{ github.ref }}"
|
||||
- name: Create release
|
||||
uses: elgohr/Github-Release-Action@c5ea99036abb741a89f8bf1f2cd7fba845e3313a # v5
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
title: ${{ github.ref_name }}
|
||||
tag: ${{ github.ref_name }}
|
||||
- name: Bump tags
|
||||
uses: fischerscode/tagger@5ca3fa63ce3003fb7183cae547644b29f3b632be # v0.2.0
|
||||
with:
|
||||
prefix: v
|
||||
@@ -1 +0,0 @@
|
||||
nodejs 24.13.0
|
||||
@@ -45,10 +45,8 @@ jobs:
|
||||
|httpsCert| Client Certificate as string ||
|
||||
|httpsKey| Client Certificate Key as string ||
|
||||
|responseFile| Persist the response data to the specified file path ||
|
||||
|maskResponse| If set to true, the response will be masked in the logs of the action |'false'|
|
||||
|retry| optional amount of retries if the request is failing, does not retry if the status code is ignored ||
|
||||
|retryWait| time between each retry in millseconds | 3000 |
|
||||
|ignoreSsl| ignore ssl verify (rejectUnauthorized: false) | false |
|
||||
|
||||
### Response
|
||||
|
||||
@@ -56,7 +54,6 @@ jobs:
|
||||
|---|---|
|
||||
`response` | Response as JSON String
|
||||
`headers` | Headers
|
||||
`status` | HTTP status message
|
||||
|
||||
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.
|
||||
|
||||
@@ -71,7 +68,6 @@ steps:
|
||||
run: |
|
||||
echo ${{ steps.myRequest.outputs.response }}
|
||||
echo ${{ steps.myRequest.outputs.headers }}
|
||||
echo ${{ steps.myRequest.outputs.status }}
|
||||
echo ${{ fromJson(steps.myRequest.outputs.response).field_you_want_to_access }}
|
||||
```
|
||||
|
||||
@@ -103,4 +99,4 @@ Optionen:
|
||||
--bearerToken bearer token without Bearer prefix, added as
|
||||
Authorization header [string]
|
||||
--timeout request timeout [number] [default: 5000]
|
||||
```
|
||||
```
|
||||
21
RELEASE.md
21
RELEASE.md
@@ -1,21 +0,0 @@
|
||||
# Release
|
||||
|
||||
## Create release
|
||||
|
||||
Do not manually draft a release.
|
||||
|
||||
To start a release, create a release tag at the commit you want using the commands
|
||||
below.
|
||||
|
||||
```shell
|
||||
git tag -a "v1.2.3" -m "v1.2.3"
|
||||
git push origin "v1.2.3"
|
||||
```
|
||||
|
||||
## Publish GitHub Action to the marketplace
|
||||
|
||||
1. Go to the [Releases page](https://github.com/fjogeleit/http-request-action/releases)
|
||||
and select the latest release that was just created.
|
||||
2. Select "Edit" button.
|
||||
3. Select "Publish this Action to the GitHub Marketplace" checkbox.
|
||||
4. Select "Update release" button.
|
||||
13
action.yml
13
action.yml
@@ -29,7 +29,7 @@ inputs:
|
||||
description: 'Auth Password'
|
||||
required: false
|
||||
timeout:
|
||||
description: 'Request Timeout in milliseconds'
|
||||
description: 'Request Timeout in Sec'
|
||||
required: false
|
||||
default: '5000'
|
||||
bearerToken:
|
||||
@@ -59,26 +59,17 @@ inputs:
|
||||
responseFile:
|
||||
description: 'Persist the response data to the specified file path'
|
||||
required: false
|
||||
maskResponse:
|
||||
description: 'Allows to mark your response as secret and hide the output in the action logs'
|
||||
required: false
|
||||
default: 'false'
|
||||
retry:
|
||||
description: 'optional amount of retries if the request fails'
|
||||
required: false
|
||||
retryWait:
|
||||
description: 'wait time between retries in milliseconds'
|
||||
required: false
|
||||
ignoreSsl:
|
||||
description: 'ignore ssl verify (rejectUnauthorized: false)'
|
||||
default: 'false'
|
||||
outputs:
|
||||
response:
|
||||
description: 'HTTP Response Content'
|
||||
headers:
|
||||
description: 'HTTP Response Headers'
|
||||
status:
|
||||
description: 'HTTP status message'
|
||||
runs:
|
||||
using: 'node24'
|
||||
using: 'node16'
|
||||
main: 'dist/index.js'
|
||||
|
||||
33232
dist/index.js
vendored
33232
dist/index.js
vendored
File diff suppressed because one or more lines are too long
3223
package-lock.json
generated
3223
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
16
package.json
16
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "http-request-action",
|
||||
"version": "1.16.4",
|
||||
"version": "1.14.2",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"private": false,
|
||||
@@ -19,15 +19,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/fjogeleit/http-request-action#readme",
|
||||
"devDependencies": {
|
||||
"@vercel/ncc": "^0.38.4",
|
||||
"axios": "^1.13.4",
|
||||
"form-data": "^4.0.3",
|
||||
"yargs": "^18.0.0"
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"axios": "^1.6",
|
||||
"form-data": "^4.0.0",
|
||||
"yargs": "^17.7.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^2.0.3"
|
||||
"@actions/core": "^1.10.1",
|
||||
"install": "^0.13.0",
|
||||
"npm": "^10.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=24.0.0"
|
||||
"node": ">=16.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,6 @@ class GithubActions {
|
||||
core.setOutput(name, output)
|
||||
}
|
||||
|
||||
setSecret(value) {
|
||||
core.setSecret(value)
|
||||
}
|
||||
|
||||
setFailed(message) {
|
||||
core.setFailed(message)
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const axios = require('axios');
|
||||
const { GithubActions } = require('../githubActions');
|
||||
|
||||
/**
|
||||
* @param {GithubActions} actions
|
||||
*
|
||||
* @returns {(response: axios.AxiosResponse) => void}
|
||||
*/
|
||||
const createMaskHandler = (actions) => (response) => {
|
||||
actions.setSecret(JSON.stringify(response.data))
|
||||
}
|
||||
|
||||
module.exports = { createMaskHandler }
|
||||
@@ -1,17 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
const axios = require('axios');
|
||||
const { GithubActions } = require('../githubActions');
|
||||
|
||||
/**
|
||||
* @param {GithubActions} actions
|
||||
*
|
||||
* @returns {(response: axios.AxiosResponse) => void}
|
||||
*/
|
||||
const createOutputHandler = (actions) => (response) => {
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
actions.setOutput('headers', response.headers)
|
||||
actions.setOutput('status', response.status)
|
||||
}
|
||||
|
||||
module.exports = { createOutputHandler }
|
||||
@@ -17,8 +17,8 @@ const createPersistHandler = (filePath, actions) => (response) => {
|
||||
data = JSON.stringify(data)
|
||||
}
|
||||
|
||||
fs.writeFile(filePath, data, error => {
|
||||
if (!error) {
|
||||
fs.writeFile(filePath, data, err => {
|
||||
if (!err) {
|
||||
actions.info(`response persisted successfully at ${filePath}`)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ const convertToJSON = (value) => {
|
||||
*
|
||||
* @returns {FormData}
|
||||
*/
|
||||
const convertToFormData = (data, files) => {
|
||||
const convertToFormData = async (data, files, convertPaths) => {
|
||||
const formData = new FormData();
|
||||
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
@@ -32,7 +32,11 @@ const convertToFormData = (data, files) => {
|
||||
}
|
||||
|
||||
for (const [key, value] of Object.entries(files)) {
|
||||
formData.append(key, fs.createReadStream(value));
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach(v => formData.append(key, fs.createReadStream(v)))
|
||||
} else {
|
||||
formData.append(key, fs.createReadStream(value));
|
||||
}
|
||||
}
|
||||
|
||||
return formData;
|
||||
@@ -55,8 +59,8 @@ const retry = async (callback, options) => {
|
||||
lastErr = err;
|
||||
}
|
||||
|
||||
if (i < options.retry) {
|
||||
options.actions.warning(`#${i + 1} request failed: ${lastErr}`);
|
||||
if (i < options.retries) {
|
||||
options.actions.warning(`#${i + 1} request failed: ${err}`);
|
||||
await sleep(options.sleep);
|
||||
}
|
||||
|
||||
|
||||
@@ -53,17 +53,11 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
if (Object.keys(filesJson).length > 0) {
|
||||
try {
|
||||
data = convertToFormData(dataJson, filesJson)
|
||||
instanceConfig = await updateConfig(instanceConfig, data, actions)
|
||||
} catch(error) {
|
||||
actions.setFailed(JSON.stringify({ message: `Unable to convert Data and Files into FormData: ${error.message}`, data: dataJson, files: filesJson }))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
instanceConfig = await updateConfig(instanceConfig, data)
|
||||
} catch(error) {
|
||||
actions.setFailed(JSON.stringify({ message: `Unable to read Content-Length: ${error.message}` }))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +94,10 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
} catch(error) {
|
||||
if (error.response && options.ignoredCodes.includes(error.response.status)) {
|
||||
actions.warning(`ignored status code: ${JSON.stringify({ code: error.response.status, message: error.response.data })}`)
|
||||
|
||||
return error.response
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
if (!error.response && error.request && options.preventFailureOnNoResponse) {
|
||||
actions.warning(`no response received: ${JSON.stringify(error)}`);
|
||||
|
||||
@@ -125,6 +119,9 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
return null
|
||||
}
|
||||
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
actions.setOutput('headers', response.headers)
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
if ((typeof error === 'object') && (error.isAxiosError === true)) {
|
||||
@@ -135,7 +132,7 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
if (error.response) {
|
||||
actions.setFailed(JSON.stringify({ code: error.response.status, message: error.response.data }))
|
||||
} else if (error.request) {
|
||||
actions.setFailed(JSON.stringify({ error: "no response received", message: error.message }));
|
||||
actions.setFailed(JSON.stringify({ error: "no response received" }));
|
||||
} else {
|
||||
actions.setFailed(JSON.stringify({ message: error.message, data }));
|
||||
}
|
||||
@@ -145,10 +142,12 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
/**
|
||||
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} instanceConfig
|
||||
* @param {FormData} formData
|
||||
* @param {*} actions
|
||||
*
|
||||
* @returns {Promise<{ baseURL: string; timeout: number; headers: { [name: string]: string } }>}
|
||||
*/
|
||||
const updateConfig = async (instanceConfig, formData) => {
|
||||
const updateConfig = async (instanceConfig, formData, actions) => {
|
||||
try {
|
||||
const formHeaders = formData.getHeaders()
|
||||
const contentType = formHeaders['content-type']
|
||||
|
||||
@@ -163,6 +162,9 @@ const updateConfig = async (instanceConfig, formData) => {
|
||||
'Content-Type': contentType
|
||||
}
|
||||
}
|
||||
} catch(error) {
|
||||
actions.setFailed({ message: `Unable to read Content-Length: ${error.message}`, data, files })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,9 +197,9 @@ const updateConfigForFile = (instanceConfig, filePath, actions) => {
|
||||
* @returns {Promise<number>}
|
||||
*/
|
||||
const contentLength = (formData) => new Promise((resolve, reject) => {
|
||||
formData.getLength((error, length) => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
formData.getLength((err, length) => {
|
||||
if (err) {
|
||||
reject (err)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
21
src/index.js
21
src/index.js
@@ -5,10 +5,7 @@ const axios = require('axios');
|
||||
const https = require('https');
|
||||
const { request, METHOD_POST } = require('./httpClient');
|
||||
const { GithubActions } = require('./githubActions');
|
||||
|
||||
const { createPersistHandler } = require('./handler/persist');
|
||||
const { createOutputHandler } = require('./handler/output');
|
||||
const { createMaskHandler } = require('./handler/mask');
|
||||
|
||||
let customHeaders = {}
|
||||
|
||||
@@ -29,9 +26,6 @@ if (!!core.getInput('bearerToken')) {
|
||||
|
||||
/** @type {axios.AxiosRequestConfig} */
|
||||
const instanceConfig = {
|
||||
httpsAgent: new https.Agent({
|
||||
rejectUnauthorized: core.getInput('ignoreSsl') !== 'true',
|
||||
}),
|
||||
baseURL: core.getInput('url', { required: true }),
|
||||
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
||||
headers: { ...headers, ...customHeaders }
|
||||
@@ -61,7 +55,7 @@ if (!!core.getInput('retry')) {
|
||||
|
||||
let retryWait = 3000
|
||||
if (!!core.getInput('retryWait')) {
|
||||
retryWait = parseInt(core.getInput('retryWait'))
|
||||
retry = parseInt(core.getInput('retryWait'))
|
||||
}
|
||||
|
||||
const data = core.getInput('data') || '{}';
|
||||
@@ -79,15 +73,8 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
|
||||
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
|
||||
}
|
||||
|
||||
const actions = new GithubActions();
|
||||
|
||||
const handler = [];
|
||||
|
||||
if (core.getBooleanInput('maskResponse')) {
|
||||
handler.push(createMaskHandler(actions))
|
||||
}
|
||||
|
||||
handler.push(createOutputHandler(actions))
|
||||
const actions = new GithubActions();
|
||||
|
||||
if (!!responseFile) {
|
||||
handler.push(createPersistHandler(responseFile, actions))
|
||||
@@ -102,7 +89,7 @@ const options = {
|
||||
}
|
||||
|
||||
request({ data, method, instanceConfig, files, file, actions, options }).then(response => {
|
||||
if (response && typeof response == 'object') {
|
||||
if (typeof response == 'object') {
|
||||
handler.forEach(h => h(response))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user