Skip to content

Commit 7d27d4a

Browse files
committed
Merge branch 'dev' into releases/v2
2 parents c38518c + 4955ebc commit 7d27d4a

12 files changed

+647
-587
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727

2828
- name: Install and Test
2929
run: |
30-
yarn install
30+
yarn install --frozen-lockfile
3131
yarn lint
3232
yarn test
3333

.github/workflows/integration.yml

+17-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
persist-credentials: false
2424

25-
- name: Fetch Data 📦
25+
- name: Fetch UTF8 Data 📦
2626
uses: JamesIves/fetch-api-data-action@v2
2727
with:
2828
endpoint: https://jsonplaceholder.typicode.com/todos/1
@@ -31,7 +31,7 @@ jobs:
3131
retry: true
3232

3333
- name: Build and Deploy Repo 🚀
34-
uses: JamesIves/[email protected].2
34+
uses: JamesIves/[email protected].5
3535
with:
3636
branch: gh-pages
3737
folder: fetch-api-data-custom
@@ -40,24 +40,35 @@ jobs:
4040

4141
refresh-api-data-modified-formatting-encoding:
4242
runs-on: ubuntu-latest
43+
needs: refresh-api-data
4344
steps:
4445
- name: Checkout 🛎️
4546
uses: actions/[email protected]
4647
with:
4748
persist-credentials: false
4849

49-
- name: Fetch Data 📦
50+
- name: Fetch Hex encoded Data 📦
5051
uses: JamesIves/fetch-api-data-action@v2
5152
with:
52-
endpoint: https://jsonplaceholder.typicode.com/todos/1
53+
endpoint: https://hexendpoint-y87ci26b7sb3.runkit.sh/
5354
save-location: fetch-api-data-custom-encoding
54-
save-name: todo2
55+
save-name: hexendpointdata
5556
encoding: hex
5657
format: txt
5758
retry: true
5859

60+
- name: Fetch Base64 Data 📦
61+
uses: JamesIves/fetch-api-data-action@v2
62+
with:
63+
endpoint: https://base64endpoint-hfdurtfq9iyz.runkit.sh/
64+
save-location: fetch-api-data-custom-encoding
65+
save-name: base64endpointdata
66+
encoding: base64
67+
format: txt
68+
retry: true
69+
5970
- name: Build and Deploy Repo 🚀
60-
uses: JamesIves/[email protected].2
71+
uses: JamesIves/[email protected].5
6172
with:
6273
branch: gh-pages
6374
folder: fetch-api-data-custom-encoding

.github/workflows/production.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ jobs:
3333
3434
- name: Build
3535
run: |
36-
yarn install
36+
yarn install --frozen-lockfile
3737
yarn build
3838
3939
- name: Install Production node_modules
4040
run: |
41-
yarn install --production
41+
yarn install --production --frozen-lockfile
4242
4343
- name: Commit and Push
4444
# Keep the run green if the commit fails for the lack of changes

.github/workflows/sponsors.yml

+13-3
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,21 @@ jobs:
1616
with:
1717
token: ${{ secrets.PAT }}
1818
file: 'README.md'
19-
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="" /></a>'
20-
minimum: 500
19+
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
20+
maximum: 9999
21+
22+
- name: Generate Sponsors 💖
23+
uses: JamesIves/[email protected]
24+
with:
25+
token: ${{ secrets.PAT }}
26+
file: 'README.md'
27+
minimum: 10000
28+
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="80px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
29+
marker: 'premium'
30+
2131

2232
- name: Deploy to GitHub Pages
23-
uses: JamesIves/[email protected].2
33+
uses: JamesIves/[email protected].5
2434
with:
2535
branch: dev
2636
folder: '.'

.github/workflows/version.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
name: Update Major Version Tag
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: nowactions/[email protected].0
13+
- uses: nowactions/[email protected].2

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,24 @@
3131
</p>
3232

3333
<p align="center">
34+
This <a href="https://github.com/features/actions">GitHub Action</a> will handle authenticated API requests for you, allowing you to save the data from the request into your workspace as an environment variable and a file. Using this action will allow you to save data from these queries on a schedule so they can be used in a static page without exposing your API credentials. You can read more about the inspiration for this action <a href="https://jamesiv.es/blog/github/actions/2020/03/07/fetching-authenticated-api-data/">here</a>.
35+
</p>
36+
37+
<p align="center">
38+
<img src="https://github.com/JamesIves/fetch-api-data-action/raw/dev/assets/screenshot.png">
39+
</p>
3440

35-
This <a href="https://github.com/features/actions">GitHub Action</a> will handle authenticated API requests for you, allowing you to save the data from the request into your workspace as an environment variable and a file. Using this action will allow you to save data from these queries on a schedule so they can be used in a static page without exposing your API credentials.
3641

42+
<p align="center">
43+
Maintainence of this project is made possible by all the <a href="https://github.com/JamesIves/github-pages-deploy-action/graphs/contributors">contributors</a> and <a href="https://github.com/sponsors/JamesIves">sponsors</a>. If you'd like to sponsor this project and have your avatar or company logo appear below <a href="https://github.com/sponsors/JamesIves">click here</a>. 💖
3744
</p>
3845

3946
<p align="center">
40-
This action was originally created for the <a href="https://github.community/t5/Events/Featured-Event-GitHub-Actions-Hackathon/td-p/48206">2020 GitHub Actions Hackathon</a>. You can read about my inspiration for this action <a href="https://jamesiv.es/blog/github/actions/2020/03/07/fetching-authenticated-api-data/">here</a>.
47+
<!-- premium --><!-- premium -->
4148
</p>
4249

4350
<p align="center">
44-
<img src="https://github.com/JamesIves/fetch-api-data-action/raw/dev/assets/screenshot.png">
51+
<!-- sponsors --><a href="https://github.com/Chooksta69"><img src="https://github.com/Chooksta69.png" width="50px" alt="Chooksta69" /></a>&nbsp;&nbsp;<a href="https://github.com/milanpollock"><img src="https://github.com/milanpollock.png" width="50px" alt="milanpollock" /></a>&nbsp;&nbsp;<a href="https://github.com/robjtede"><img src="https://github.com/robjtede.png" width="50px" alt="robjtede" /></a>&nbsp;&nbsp;<!-- sponsors -->
4552
</p>
4653

4754
## Getting Started ✈️
@@ -62,7 +69,7 @@ jobs:
6269
configuration: '{ "method": "GET", "headers": {"Authorization": "Bearer ${{ secrets.API_TOKEN }}"} }'
6370
```
6471
65-
Once the action has run the requested data will be exported into the `FETCH_API_DATA` environment variable and will also be available as a `.json` file in your workspace located by default in the `fetch-api-data-action/data.json` directory. If you need something other than `.json` file please refer to the `format` parameter.
72+
Once the action has run the requested data will be exported into the `fetch-api-data` environment variable and will also be available as a `.json` file in your workspace located by default in the `fetch-api-data-action/data.json` directory. If you need something other than `.json` file please refer to the `format` parameter.
6673

6774
You can combine the use of this with the [GitHub Pages Deploy Action](https://github.com/JamesIves/github-pages-deploy-action) to trigger scheduled updates to a feed on your website.
6875

@@ -185,6 +192,7 @@ The following configuration options should be set.
185192
| `retry` | If you're working with an intermittent API you can toggle this option to `true`. Doing so will make the action try the request 3 times at random invervals before failing. | `with` | **No** |
186193
| `save-location` | By default the save location of the file is `fetch-api-data-action/data.json`, if you'd like to override the directory you can do so by specifying a new one with this variable. | `with` | **No** |
187194
| `save-name` | You can override the name of the exported `.json` file by specifying a new one here. You should _not_ include the file extension in your name. | `with` | **No** |
195+
| `set-output` | Determines if the returned data should be saved as an environment variable or not. This field defaults to `true`. | `with` | **No** |
188196
| `format` | Allows you to modify the extension of the file saved from the API response, for example you can set this field to `json` or `txt`. This field defaults to `json`. | `with` | **No** |
189197
| `encoding` | Allows you to modify the encoding of the file saved from the API response, for example you can set this field to `utf8` or `hex`. This field defaults to `utf8`. Choose from `ascii`, `utf8`, `utf-8`, `utf16le`, `ucs2`, `ucs-2`, `base64`, `latin1`, `binary` or `hex`. | `with` | **No** |
190198
| `debug` | If set to `true` the action will log the API responses it receives in the terminal. | `with` | **No** |
@@ -214,11 +222,3 @@ jobs:
214222
# The bearer token here is returned from the TOKEN_ENDPOINT call. The returned data looks like so: {data: {access_token: '123'}}, meaning it can be accessed using the triple bracket syntax.
215223
configuration: '{ "method": "GET", "headers": {"Authorization": "Bearer {{{ data.access_token }}}"} }'
216224
```
217-
218-
---
219-
220-
## Support 💖
221-
222-
This project would not be possible without all of our fantastic [contributors](https://github.com/JamesIves/fetch-api-data-action/graphs/contributors) and [sponsors](https://github.com/sponsors/JamesIves). If you'd like to support the maintenance and upkeep of this project you can [donate via GitHub Sponsors](https://github.com/sponsors/JamesIves).
223-
224-
<!-- sponsors --><a href="https://github.com/milanpollock"><img src="https://github.com/milanpollock.png" width="50px" alt="" /></a><a href="https://github.com/raoulvdberge"><img src="https://github.com/raoulvdberge.png" width="50px" alt="" /></a><!-- sponsors -->

action.yml

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ inputs:
3636
description: 'You can override the name of the exported `.json` file by specifying a new one here. You should _not_ include the file extension in your name.'
3737
required: false
3838

39+
set-output:
40+
description: 'Determines if the returned data should be saved as an environment variable or not. This field defaults to `true`.'
41+
required: false
42+
default: 'true'
43+
3944
debug:
4045
description: 'If set to true the action will log the API responses it receives in the terminal.'
4146
required: false

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@jamesives/fetch-api-data-action",
33
"description": "GitHub action for handling authenticated API requests, allowing you to save the data from the request into your workspace as an environment variable and a .json file.",
44
"author": "James Ives <[email protected]> (https://jamesiv.es)",
5-
"version": "2.1.0",
5+
"version": "2.2.0",
66
"license": "MIT",
77
"main": "lib/lib.js",
88
"types": "lib/lib.d.ts",
@@ -36,25 +36,25 @@
3636
"@actions/core": "1.6.0",
3737
"@actions/io": "1.1.1",
3838
"async-retry": "1.3.3",
39-
"cross-fetch": "3.1.4",
39+
"cross-fetch": "3.1.5",
4040
"mustache": "4.2.0"
4141
},
4242
"devDependencies": {
4343
"@types/async-retry": "1.4.3",
44-
"@types/jest": "27.4.0",
44+
"@types/jest": "27.4.1",
4545
"@types/mustache": "4.1.2",
46-
"@types/node": "17.0.8",
47-
"@typescript-eslint/eslint-plugin": "5.9.1",
48-
"@typescript-eslint/parser": "5.9.1",
49-
"eslint": "8.6.0",
46+
"@types/node": "17.0.19",
47+
"@typescript-eslint/eslint-plugin": "5.11.0",
48+
"@typescript-eslint/parser": "5.11.0",
49+
"eslint": "8.9.0",
5050
"eslint-config-prettier": "8.3.0",
51-
"eslint-plugin-jest": "25.3.4",
51+
"eslint-plugin-jest": "26.1.1",
5252
"eslint-plugin-prettier": "4.0.0",
53-
"jest": "27.4.7",
54-
"jest-circus": "27.4.6",
55-
"nock": "13.2.2",
53+
"jest": "27.5.1",
54+
"jest-circus": "27.5.1",
55+
"nock": "13.2.4",
5656
"prettier": "2.5.1",
57-
"ts-jest": "27.1.2",
58-
"typescript": "4.5.4"
57+
"ts-jest": "27.1.3",
58+
"typescript": "4.5.5"
5959
}
6060
}

src/constants.ts

+8
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ export interface ActionInterface {
1818
saveLocation?: string
1919
/** The save name of the exported file. */
2020
saveName?: string
21+
/** Determines if the output shoudl be saved or not. */
22+
setOutput: string
2123
/** The format of the file being saved. */
2224
format?: string
2325
/** Optional configuration that allows the fetch request to make a series of retry requests before failing. */
2426
retry?: boolean | null
27+
2528
}
2629

2730
export interface DataInterface {
@@ -48,6 +51,8 @@ export interface ExportInterface {
4851
saveLocation?: string
4952
/** The name of the file to save. */
5053
saveName?: string
54+
/** Determines if the output shoudl be saved or not. */
55+
setOutput: string
5156
/** The format of the file to save. */
5257
format?: string
5358
}
@@ -67,6 +72,9 @@ export const action = {
6772
tokenConfiguration: getInput('token-configuration'),
6873
saveLocation: getInput('save-location'),
6974
saveName: getInput('save-name'),
75+
setOutput: !isNullOrUndefined(getInput('set-output'))
76+
? getInput('set-output').toLowerCase() === 'true'
77+
: false,
7078
format: getInput('format')
7179
}
7280

src/fetch.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export async function generateExport({
6868
encoding,
6969
format,
7070
saveLocation,
71-
saveName
71+
saveName,
72+
setOutput
7273
}: ExportInterface): Promise<Status> {
7374
info('Saving the data... 📁')
7475
const file = `${saveLocation ? saveLocation : 'fetch-api-data-action'}/${
@@ -82,7 +83,9 @@ export async function generateExport({
8283

8384
info(`Saved ${file} 💾`)
8485

85-
exportVariable('fetch-api-data', data)
86+
if (setOutput) {
87+
exportVariable('fetch-api-data', data)
88+
}
8689

8790
return Status.SUCCESS
8891
} catch (error) {

src/lib.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ export default async function run(
5555
encoding: settings.encoding,
5656
saveLocation: settings.saveLocation,
5757
saveName: settings.saveName,
58-
format: settings.format
58+
format: settings.format,
59+
setOutput: settings.setOutput
5960
})
6061
} catch (error) {
6162
status = Status.FAILED

0 commit comments

Comments
 (0)