diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index fe15f89..0996fe6 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -45,8 +45,9 @@ jobs: - name: "Verify Outputs" run: | - echo '${{ steps.test.outputs.status }}' - echo '${{ steps.test.outputs.data }}' + echo 'status: ${{ steps.test.outputs.status }}' + echo 'headers: ${{ steps.test.outputs.headers }}' + echo 'data: ${{ steps.test.outputs.data }}' if [ '${{ fromJson(steps.test.outputs.data).data }}' != '{"key":"value"}' ];then echo "Output Invalid" exit 1 diff --git a/README.md b/README.md index 700aa9d..a53393f 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,27 @@ Easily make a web request from a workflow using Axios. Supports all methods, uploading files, basic authentication and more. +Pass data/headers/params as JSON or YAML formatted strings. + +```yaml +- name: 'Web Request' + uses: cssnr/web-request-action@v1 + with: + url: https://httpbin.org/post + method: 'POST' + data: '{"key": "value"}' + headers: | + key: value + params: | + { + "key": "value" + } + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + insecure: false + file: path/to/file.txt + name: file +``` > [!NOTE] > Please submit a [Feature Request](https://github.com/cssnr/web-request-action/discussions/categories/feature-requests) @@ -38,10 +59,10 @@ Supports all methods, uploading files, basic authentication and more. | Input | Default | Description of the Input Value | | :------- | :--------- | :------------------------------------------------- | -| url | _Required_ | URL for Request | -| method | `POST` | Request Method | +| url | _Required_ | URL for Request [⤵️](#url) | +| method | `POST` | Request Method [⤵️](#method) | | data | - | Request Data JSON/YAML [⤵️](#data) | -| headers | - | Request Headers JSON/YAML | +| headers | - | Request Headers JSON/YAML [⤵️](#headers) | | params | - | Request Parameters JSON/YAML [⤵️](#params) | | username | - | Basic Auth Username | | password | - | Basic Auth Password | @@ -49,31 +70,47 @@ Supports all methods, uploading files, basic authentication and more. | file | - | File Path to Send [⤵️](#file) | | name | `file` | File Form Key Name | +### url + +The URL to send the request too. You may include params here or in the [params](#params) key. + +### method + +The request method, including custom methods. + +Default: `POST` + ### data -Only used for `PUT`, `POST`, `DELETE`, and `PATCH`. Data is parsed with `JSON.parse` then `yaml.load`. +Body JSON or YAML data. Only used for `PUT`, `POST`, `DELETE`, and `PATCH`. + +Data is parsed with `JSON.parse` or `yaml.load`, [js-yaml](https://github.com/nodeca/js-yaml). -
View Multi-Line JSON/YAML Example +
View JSON/YAML Example ```yaml data: | - { - "key1": "value1", - "key2": "value2" - } + key1: value1 + key2: value2 ``` ```yaml data: | - key1: value1 - key2: value2 + { + "key1": "value1", + "key2": "value2" + } ```
+### headers + +Headers JSON or YAML data. + ### params -These can be specified in the URL or added here as JSON key/value pairs. +Parameters, Query String, JSON or YAML data. These may also be provided in the [url](#url). ### file @@ -91,10 +128,11 @@ For more information on inputs, see: https://axios-http.com/docs/req_config ## Outputs -| Output | Description | -| :----- | :-------------- | -| status | Response Status | -| data | Response Data | +| Output | Description | +| :------ | :--------------- | +| status | Response Status | +| headers | Response Headers | +| data | Response Data | ```yaml - name: 'Web Request' @@ -106,6 +144,7 @@ For more information on inputs, see: https://axios-http.com/docs/req_config - name: 'Echo Output' run: | echo '${{ steps.test.outputs.status }}' + echo '${{ steps.test.outputs.headers }}' echo '${{ steps.test.outputs.data }}' ``` @@ -132,7 +171,8 @@ For more information on inputs, see: https://axios-http.com/docs/req_config uses: cssnr/web-request-action@v1 with: url: ${{ secrets.RENDER_HOOK }} - params: '{"imgURL": "ghcr.io/${{ github.repository }}:${{ github.ref_name }}"}' + params: | + imgURL: ghcr.io/${{ github.repository }}:${{ github.ref_name }} ```
@@ -166,6 +206,7 @@ For more information on inputs, see: https://axios-http.com/docs/req_config with: url: https://httpbin.org/post file: path/to/file.txt + name: file # Default - name of file key ``` @@ -178,8 +219,12 @@ For more information on inputs, see: https://axios-http.com/docs/req_config url: https://httpbin.org/post method: 'POST' data: '{"key": "value"}' - headers: '{"header": "value"}' - params: '{"parameter": "value"}' + headers: | + key: value + params: | + { + "key": "value" + } username: ${{ secrets.USERNAME }} password: ${{ secrets.PASSWORD }} insecure: false diff --git a/action.yml b/action.yml index b3afea1..1b4f434 100644 --- a/action.yml +++ b/action.yml @@ -34,6 +34,8 @@ inputs: outputs: status: description: "Response Status" + headers: + description: "Response Headers" data: description: "Response Data" diff --git a/dist/index.js b/dist/index.js index 9aae5cf..7a85a21 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36240,7 +36240,7 @@ module.exports = parseParams /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { "use strict"; -/*! Axios v1.13.0 Copyright (c) 2025 Matt Zabriskie and contributors */ +/*! Axios v1.13.1 Copyright (c) 2025 Matt Zabriskie and contributors */ const FormData$1 = __nccwpck_require__(6454); @@ -38400,7 +38400,7 @@ function buildFullPath(baseURL, requestedURL, allowAbsoluteUrls) { return requestedURL; } -const VERSION = "1.13.0"; +const VERSION = "1.13.1"; function parseProtocol(url) { const match = /^([-+\w]{1,25})(:?\/\/|:)/.exec(url); @@ -39676,7 +39676,7 @@ const httpAdapter = isHttpAdapterSupported && function httpAdapter(config) { if (responseType === 'stream') { response.data = responseStream; - settle(resolve, abort, response); + settle(resolve, reject, response); } else { const responseBuffer = []; let totalResponseBytes = 0; @@ -41538,6 +41538,7 @@ const yaml = __nccwpck_require__(4281) ;(async () => { try { // Inputs + core.startGroup('Inputs') const url = core.getInput('url', { required: true }) console.log('url:', url) const method = core.getInput('method', { required: true }) @@ -41558,6 +41559,7 @@ const yaml = __nccwpck_require__(4281) console.log('file:', file) const name = core.getInput('name') console.log('name:', name) + core.endGroup() // Inputs // Options const auth = username && password ? { username, password } : {} @@ -41592,14 +41594,20 @@ const yaml = __nccwpck_require__(4281) } console.log('config:', config) const response = await axios.request(config) + console.log('response.status:', response.status) // console.log('response:', response) // console.log('response.request._headers:', response.request._headers) - // console.log('response.headers:', response.headers) - console.log('response.status:', response.status) + core.startGroup('Headers') + console.log('response.headers:', response.headers) + core.endGroup() // Headers + + core.startGroup('Data') console.log('response.data:', response.data) + core.endGroup() // Data // Outputs core.setOutput('status', response.status) + core.setOutput('headers', response.headers) core.setOutput('data', response.data) core.info(`\u001b[32;1mFinished Success`) diff --git a/package-lock.json b/package-lock.json index 3cec242..5810fb1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,7 +7,7 @@ "name": "web-request-action", "dependencies": { "@actions/core": "^1.11.1", - "axios": "^1.13.0", + "axios": "^1.13.1", "form-data": "^4.0.4", "js-yaml": "^4.1.0" }, @@ -351,9 +351,9 @@ "license": "MIT" }, "node_modules/axios": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.0.tgz", - "integrity": "sha512-zt40Pz4zcRXra9CVV31KeyofwiNvAbJ5B6YPz9pMJ+yOSLikvPT4Yi5LjfgjRa9CawVYBaD1JQzIVcIvBejKeA==", + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.13.1.tgz", + "integrity": "sha512-hU4EGxxt+j7TQijx1oYdAjw4xuIp1wRQSsbMFwSthCWeBQur1eF+qJ5iQ5sN3Tw8YRzQNKb8jszgBdMDVqwJcw==", "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", diff --git a/package.json b/package.json index 96d6361..5614c4b 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "dependencies": { "@actions/core": "^1.11.1", - "axios": "^1.13.0", + "axios": "^1.13.1", "form-data": "^4.0.4", "js-yaml": "^4.1.0" }, diff --git a/src/index.js b/src/index.js index 9522eda..e6b7e0a 100644 --- a/src/index.js +++ b/src/index.js @@ -8,6 +8,7 @@ const yaml = require('js-yaml') ;(async () => { try { // Inputs + core.startGroup('Inputs') const url = core.getInput('url', { required: true }) console.log('url:', url) const method = core.getInput('method', { required: true }) @@ -28,6 +29,7 @@ const yaml = require('js-yaml') console.log('file:', file) const name = core.getInput('name') console.log('name:', name) + core.endGroup() // Inputs // Options const auth = username && password ? { username, password } : {} @@ -62,14 +64,20 @@ const yaml = require('js-yaml') } console.log('config:', config) const response = await axios.request(config) + console.log('response.status:', response.status) // console.log('response:', response) // console.log('response.request._headers:', response.request._headers) - // console.log('response.headers:', response.headers) - console.log('response.status:', response.status) + core.startGroup('Headers') + console.log('response.headers:', response.headers) + core.endGroup() // Headers + + core.startGroup('Data') console.log('response.data:', response.data) + core.endGroup() // Data // Outputs core.setOutput('status', response.status) + core.setOutput('headers', response.headers) core.setOutput('data', response.data) core.info(`\u001b[32;1mFinished Success`)