Skip to content

Commit

Permalink
Merge branch 'dev' into releases/v2
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesIves committed Mar 6, 2022
2 parents c38518c + 4955ebc commit 7d27d4a
Show file tree
Hide file tree
Showing 12 changed files with 647 additions and 587 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:

- name: Install and Test
run: |
yarn install
yarn install --frozen-lockfile
yarn lint
yarn test
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
with:
persist-credentials: false

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

- name: Build and Deploy Repo 🚀
uses: JamesIves/github-pages-deploy-action@v4.2.2
uses: JamesIves/github-pages-deploy-action@v4.2.5
with:
branch: gh-pages
folder: fetch-api-data-custom
Expand All @@ -40,24 +40,35 @@ jobs:

refresh-api-data-modified-formatting-encoding:
runs-on: ubuntu-latest
needs: refresh-api-data
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2.4.0
with:
persist-credentials: false

- name: Fetch Data 📦
- name: Fetch Hex encoded Data 📦
uses: JamesIves/fetch-api-data-action@v2
with:
endpoint: https://jsonplaceholder.typicode.com/todos/1
endpoint: https://hexendpoint-y87ci26b7sb3.runkit.sh/
save-location: fetch-api-data-custom-encoding
save-name: todo2
save-name: hexendpointdata
encoding: hex
format: txt
retry: true

- name: Fetch Base64 Data 📦
uses: JamesIves/fetch-api-data-action@v2
with:
endpoint: https://base64endpoint-hfdurtfq9iyz.runkit.sh/
save-location: fetch-api-data-custom-encoding
save-name: base64endpointdata
encoding: base64
format: txt
retry: true

- name: Build and Deploy Repo 🚀
uses: JamesIves/github-pages-deploy-action@v4.2.2
uses: JamesIves/github-pages-deploy-action@v4.2.5
with:
branch: gh-pages
folder: fetch-api-data-custom-encoding
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ jobs:
- name: Build
run: |
yarn install
yarn install --frozen-lockfile
yarn build
- name: Install Production node_modules
run: |
yarn install --production
yarn install --production --frozen-lockfile
- name: Commit and Push
# Keep the run green if the commit fails for the lack of changes
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ jobs:
with:
token: ${{ secrets.PAT }}
file: 'README.md'
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="" /></a>'
minimum: 500
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="50px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
maximum: 9999

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1.0.8
with:
token: ${{ secrets.PAT }}
file: 'README.md'
minimum: 10000
template: '<a href="https://github.com/{{{ login }}}"><img src="https://github.com/{{{ login }}}.png" width="80px" alt="{{{ login }}}" /></a>&nbsp;&nbsp;'
marker: 'premium'


- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4.2.2
uses: JamesIves/github-pages-deploy-action@v4.2.5
with:
branch: dev
folder: '.'
2 changes: 1 addition & 1 deletion .github/workflows/version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
name: Update Major Version Tag
runs-on: ubuntu-latest
steps:
- uses: nowactions/update-majorver@v1.1.0
- uses: nowactions/update-majorver@v1.1.2
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,24 @@
</p>

<p align="center">
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>.
</p>

<p align="center">
<img src="https://github.com/JamesIves/fetch-api-data-action/raw/dev/assets/screenshot.png">
</p>

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.

<p align="center">
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>. 💖
</p>

<p align="center">
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>.
<!-- premium --><!-- premium -->
</p>

<p align="center">
<img src="https://github.com/JamesIves/fetch-api-data-action/raw/dev/assets/screenshot.png">
<!-- 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 -->
</p>

## Getting Started ✈️
Expand All @@ -62,7 +69,7 @@ jobs:
configuration: '{ "method": "GET", "headers": {"Authorization": "Bearer ${{ secrets.API_TOKEN }}"} }'
```

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.
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.

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.

Expand Down Expand Up @@ -185,6 +192,7 @@ The following configuration options should be set.
| `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** |
| `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** |
| `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** |
| `set-output` | Determines if the returned data should be saved as an environment variable or not. This field defaults to `true`. | `with` | **No** |
| `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** |
| `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** |
| `debug` | If set to `true` the action will log the API responses it receives in the terminal. | `with` | **No** |
Expand Down Expand Up @@ -214,11 +222,3 @@ jobs:
# 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.
configuration: '{ "method": "GET", "headers": {"Authorization": "Bearer {{{ data.access_token }}}"} }'
```

---

## Support 💖

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).

<!-- 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 -->
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ inputs:
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.'
required: false

set-output:
description: 'Determines if the returned data should be saved as an environment variable or not. This field defaults to `true`.'
required: false
default: 'true'

debug:
description: 'If set to true the action will log the API responses it receives in the terminal.'
required: false
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@jamesives/fetch-api-data-action",
"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.",
"author": "James Ives <iam@jamesiv.es> (https://jamesiv.es)",
"version": "2.1.0",
"version": "2.2.0",
"license": "MIT",
"main": "lib/lib.js",
"types": "lib/lib.d.ts",
Expand Down Expand Up @@ -36,25 +36,25 @@
"@actions/core": "1.6.0",
"@actions/io": "1.1.1",
"async-retry": "1.3.3",
"cross-fetch": "3.1.4",
"cross-fetch": "3.1.5",
"mustache": "4.2.0"
},
"devDependencies": {
"@types/async-retry": "1.4.3",
"@types/jest": "27.4.0",
"@types/jest": "27.4.1",
"@types/mustache": "4.1.2",
"@types/node": "17.0.8",
"@typescript-eslint/eslint-plugin": "5.9.1",
"@typescript-eslint/parser": "5.9.1",
"eslint": "8.6.0",
"@types/node": "17.0.19",
"@typescript-eslint/eslint-plugin": "5.11.0",
"@typescript-eslint/parser": "5.11.0",
"eslint": "8.9.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-jest": "25.3.4",
"eslint-plugin-jest": "26.1.1",
"eslint-plugin-prettier": "4.0.0",
"jest": "27.4.7",
"jest-circus": "27.4.6",
"nock": "13.2.2",
"jest": "27.5.1",
"jest-circus": "27.5.1",
"nock": "13.2.4",
"prettier": "2.5.1",
"ts-jest": "27.1.2",
"typescript": "4.5.4"
"ts-jest": "27.1.3",
"typescript": "4.5.5"
}
}
8 changes: 8 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export interface ActionInterface {
saveLocation?: string
/** The save name of the exported file. */
saveName?: string
/** Determines if the output shoudl be saved or not. */
setOutput: string
/** The format of the file being saved. */
format?: string
/** Optional configuration that allows the fetch request to make a series of retry requests before failing. */
retry?: boolean | null

}

export interface DataInterface {
Expand All @@ -48,6 +51,8 @@ export interface ExportInterface {
saveLocation?: string
/** The name of the file to save. */
saveName?: string
/** Determines if the output shoudl be saved or not. */
setOutput: string
/** The format of the file to save. */
format?: string
}
Expand All @@ -67,6 +72,9 @@ export const action = {
tokenConfiguration: getInput('token-configuration'),
saveLocation: getInput('save-location'),
saveName: getInput('save-name'),
setOutput: !isNullOrUndefined(getInput('set-output'))
? getInput('set-output').toLowerCase() === 'true'
: false,
format: getInput('format')
}

Expand Down
7 changes: 5 additions & 2 deletions src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export async function generateExport({
encoding,
format,
saveLocation,
saveName
saveName,
setOutput
}: ExportInterface): Promise<Status> {
info('Saving the data... 📁')
const file = `${saveLocation ? saveLocation : 'fetch-api-data-action'}/${
Expand All @@ -82,7 +83,9 @@ export async function generateExport({

info(`Saved ${file} 💾`)

exportVariable('fetch-api-data', data)
if (setOutput) {
exportVariable('fetch-api-data', data)
}

return Status.SUCCESS
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default async function run(
encoding: settings.encoding,
saveLocation: settings.saveLocation,
saveName: settings.saveName,
format: settings.format
format: settings.format,
setOutput: settings.setOutput
})
} catch (error) {
status = Status.FAILED
Expand Down

0 comments on commit 7d27d4a

Please sign in to comment.