Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 42 additions & 8 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ on:
- "action.yml"
pull_request:

env:
httpbin: ${{ !github.event.act && 'https://httpbin.org' || 'http://192.168.1.25:8080' }}

jobs:
test:
name: "Test"
Expand All @@ -32,23 +35,54 @@ jobs:
GITHUB_CTX: ${{ toJSON(github) }}
run: echo "$GITHUB_CTX"

- name: "Test Local Action"
id: test
- name: "1: Test Data"
id: test1
uses: ./
with:
url: https://httpbin.org/post
url: "${{ env.httpbin }}/post"
#insecure: true
#data: '{"key": "value"}'
data: |
key: value
params: |
param1: value1
config: |
timeout: 30000

- name: "Verify Outputs"
- name: "1: Verify Data"
if: ${{ !github.event.act }}
run: |
echo 'status: ${{ steps.test1.outputs.status }}'
echo 'headers: ${{ steps.test1.outputs.headers }}'
echo 'data: ${{ steps.test1.outputs.data }}'
if [ '${{ fromJson(steps.test1.outputs.data).data }}' != '{"key":"value"}' ];then
echo "Output Invalid"
exit 1
fi

- name: "2: Test File"
if: ${{ !github.event.act }}
id: test2
uses: ./
with:
url: "${{ env.httpbin }}/post"
#insecure: true
#data: '{"key": "value"}'
data: |
key: value
params: |
param1: value1
file: event.json
filename: not-event.json

- name: "2: Verify File"
if: ${{ !github.event.act }}
run: |
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 'status: ${{ steps.test2.outputs.status }}'
echo 'headers: ${{ steps.test2.outputs.headers }}'
echo 'data: ${{ steps.test2.outputs.data }}'
echo 'data.form: ${{ fromJson(steps.test2.outputs.data).form.key }}'
if [ '${{ fromJson(steps.test2.outputs.data).form.key }}' != 'value' ];then
echo "Output Invalid"
exit 1
fi
Expand Down
109 changes: 84 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ Pass data/headers/params as JSON or YAML formatted strings.
{
"key": "value"
}
config: |
timeout: 1000
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
insecure: false
file: path/to/file.txt
name: file
filename: custom-name.txt
```

> [!NOTE]
Expand All @@ -58,37 +61,41 @@ Pass data/headers/params as JSON or YAML formatted strings.

## Inputs

| Input | Default | Description of the Input Value |
| :------- | :--------- | :------------------------------------------------- |
| url | _Required_ | URL for Request [⤵️](#url) |
| method | `POST` | Request Method [⤵️](#method) |
| data | - | Request Data JSON/YAML [⤵️](#data) |
| headers | - | Request Headers JSON/YAML [⤵️](#headers) |
| params | - | Request Parameters JSON/YAML [⤵️](#params) |
| username | - | Basic Auth Username |
| password | - | Basic Auth Password |
| insecure | `false` | Ignore SSL Errors |
| file | - | File Path to Send [⤵️](#file) |
| name | `file` | File Form Key Name |
| Input | Default Value | Description of the Input Value |
| :------- | :----------------- | :------------------------------------------------- |
| url | _Required_ | URL for Request [⤵️](#url) |
| method | `POST` | Request Method [⤵️](#method) |
| data | - | Request Data JSON/YAML [⤵️](#data) |
| headers | - | Request Headers JSON/YAML [⤵️](#headers) |
| params | - | Request Parameters JSON/YAML [⤵️](#params) |
| config | - | Axios Config JSON/YAML [⤵️](#config) |
| username | - | Basic Auth Username |
| password | - | Basic Auth Password |
| insecure | `false` | Ignore SSL Errors |
| file | - | File Path to Send [⤵️](#file) |
| name | `file` | File Form Key Name |
| filename | _Original Name_ | Set a Different File 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.
The request method, including custom methods. Case-insensitive.

Default: `POST`

### data

Body JSON or YAML data. Only used for `PUT`, `POST`, `DELETE`, and `PATCH`.
Body JSON/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).

<details><summary>View JSON/YAML Example</summary>

This format works for `data`, `headers`, `params`, and `config`.

```yaml
data: |
key1: value1
Expand All @@ -103,15 +110,35 @@ data: |
}
```

```yaml
data: '{"key1": "value1", "key2": "value2"}'
```

Note: All these examples are identical.

</details>

### headers

Headers JSON or YAML data.
Headers JSON/YAML data.

### params

Parameters, Query String, JSON or YAML data. These may also be provided in the [url](#url).
Parameters (Query String) JSON/YAML data. These may also be provided in the [url](#url).

### config

Additional Axios Config JSON/YAML data. For example, set a 3-second timeout: `timeout: 3000`

Reference: https://axios-http.com/docs/req_config

<details><summary>Note: The config is spread last and overrides other keys.</summary>

```javascript
config = { url, method, headers, params, data, auth, httpsAgent, ...config }
```

</details>

### file

Expand All @@ -120,12 +147,7 @@ key `name`. The file path is relative to the workspace/working directory.

For more information on inputs, see: https://axios-http.com/docs/req_config

```yaml
- name: 'Web Request'
uses: cssnr/web-request-action@v1
with:
url: https://httpbin.org/post
```
See the [Examples](#examples) for more usage options...

## Outputs

Expand All @@ -135,6 +157,8 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
| headers | Response Headers |
| data | Response Data |

Note: All outputs are run through `JSON.stringify` by default.

```yaml
- name: 'Web Request'
id: test
Expand All @@ -153,10 +177,20 @@ For more information on inputs, see: https://axios-http.com/docs/req_config

💡 _Click on an example heading to expand or collapse the example._

<details open><summary>Algolia Start Crawl</summary>
<details open><summary>Trigger a Webhook</summary>

```yaml
- name: 'Algolia Start Crawl'
- name: 'Portainer Webhook'
uses: cssnr/web-request-action@v1
with:
url: ${{ secrets.PORTAINER_WEBHOOK }}
```

</details>
<details open><summary>Start Algolia Crawl</summary>

```yaml
- name: 'Start Algolia Crawl'
uses: cssnr/web-request-action@v1
with:
url: https://crawler.algolia.com/api/1/crawlers/${{ secrets.CRAWLER_ID }}/reindex
Expand All @@ -168,7 +202,7 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
<details open><summary>Deploy to Render</summary>

```yaml
- name: 'Render Deploy'
- name: 'Render Deploy Image'
uses: cssnr/web-request-action@v1
with:
url: ${{ secrets.RENDER_HOOK }}
Expand Down Expand Up @@ -196,8 +230,14 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
with:
url: https://httpbin.org/post
data: '{"key": "value"}'
data: |
'{"key": "value"}'
data: |
key: value
```

Note: All data keys are identical as exemplar formats.

</details>
<details><summary>Send File</summary>

Expand All @@ -208,8 +248,24 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
url: https://httpbin.org/post
file: path/to/file.txt
name: file # Default - name of file key
filename: name.txt # Optional - file name
```

</details>
<details><summary>Set Axios Config</summary>

```yaml
- name: 'Web Request'
uses: cssnr/web-request-action@v1
with:
url: https://httpbin.org/post
config: |
timeout: 1000
maxContentLength: 2000
```

Reference: https://axios-http.com/docs/req_config

</details>
<details><summary>All Inputs</summary>

Expand All @@ -226,11 +282,14 @@ For more information on inputs, see: https://axios-http.com/docs/req_config
{
"key": "value"
}
config: |
timeout: 5000
username: ${{ secrets.USERNAME }}
password: ${{ secrets.PASSWORD }}
insecure: false
file: path/to/file.txt
name: file
filename: name.txt
```

</details>
Expand Down
14 changes: 10 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "Web Request"
description: "Send Web Requests like POST and GET with Axios using GitHub Actions."
description: "Easily Make Web Requests like GET/POST, Trigger Webhooks, and Send Files using Axios. Data inputs supports YAML/JSON format."
author: "Shane"
branding:
icon: "globe"
Expand All @@ -13,11 +13,13 @@ inputs:
description: "Request Method"
default: "POST"
data:
description: "Request Data JSON"
description: "Request Data JSON/YAML"
headers:
description: "Request Headers JSON"
description: "Request Headers JSON/YAML"
params:
description: "Request Parameters JSON"
description: "Request Parameters JSON/YAML"
config:
description: "Axios Config JSON/YAML"
username:
description: "Basic Auth Username"
password:
Expand All @@ -30,6 +32,8 @@ inputs:
name:
description: "File Key Name"
default: "file"
filename:
description: "Custom File Name"

outputs:
status:
Expand All @@ -38,6 +42,8 @@ outputs:
description: "Response Headers"
data:
description: "Response Data"
#url:
# description: "Response URL"

runs:
using: "node24"
Expand Down
Loading
Loading