Skip to content

Commit a6489cd

Browse files
committed
Merge branch 'dev' into releases/v2
2 parents 869e3c5 + 064038a commit a6489cd

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

.github/workflows/integration.yml

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,22 @@ jobs:
3131
save-name: todo
3232
retry: true
3333

34-
- name: Build and Deploy Repo 🚀
35-
uses: JamesIves/github-pages-deploy-action@v4
36-
with:
37-
branch: gh-pages
38-
folder: fetch-api-data-custom
39-
target-folder: data
40-
ssh-key: ${{ secrets.DEPLOY_KEY }}
41-
4234
- name: Access environment variable output
43-
if: always()
44-
shell: bash
4535
run: |
4636
echo "${fetchApiData}"
4737
4838
- name: Access step output
4939
run: |
5040
echo "Output: ${{ steps.validate.outputs.fetchApiData }}"
5141
42+
- name: Build and Deploy Repo 🚀
43+
uses: JamesIves/github-pages-deploy-action@v4
44+
with:
45+
branch: gh-pages
46+
folder: fetch-api-data-custom
47+
target-folder: data
48+
ssh-key: ${{ secrets.DEPLOY_KEY }}
49+
5250
refresh-api-data-modified-formatting-encoding:
5351
runs-on: ubuntu-latest
5452
needs: refresh-api-data
@@ -69,15 +67,26 @@ jobs:
6967
retry: true
7068

7169
- name: Fetch Base64 Data 📦
70+
id: validate
7271
uses: JamesIves/fetch-api-data-action@v2
7372
with:
7473
endpoint: https://base64endpoint-hfdurtfq9iyz.runkit.sh/
7574
save-location: fetch-api-data-custom-encoding
7675
save-name: base64endpointdata
7776
encoding: base64
7877
format: txt
78+
variable-name: CATS
7979
retry: true
8080

81+
- name: Access environment variable output
82+
run: |
83+
echo "${CATS}"
84+
85+
- name: Access step output
86+
run: |
87+
echo "Output: ${{ steps.validate.outputs.fetchApiData }}"
88+
89+
8190
- name: Build and Deploy Repo 🚀
8291
uses: JamesIves/github-pages-deploy-action@v4
8392
with:

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ 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+
variable-name:
40+
description: 'You can override the name of the variable name the action exports. This will work so long as set-output is true.'
41+
required: false
42+
3943
set-output:
4044
description: 'Determines if the returned data should be saved as an environment variable or not. This field defaults to `true`, but depending on your API response length you may need to toggle this.'
4145
required: false
@@ -54,5 +58,5 @@ inputs:
5458
required: false
5559

5660
outputs:
57-
fetch-api-data:
61+
fetchApiData:
5862
description: 'The requested data from the API stored as a string.'

src/constants.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ 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. */
21+
/** Determines if the output should be saved or not. */
2222
setOutput: boolean
2323
/** The format of the file being saved. */
2424
format?: string
2525
/** Optional configuration that allows the fetch request to make a series of retry requests before failing. */
2626
retry?: boolean | null
27+
/** The variable name the data exports as. */
28+
variableName?: string
2729
}
2830

2931
export interface DataInterface {
@@ -54,6 +56,8 @@ export interface ExportInterface {
5456
setOutput: boolean
5557
/** The format of the file to save. */
5658
format?: string
59+
/** The variable name the data exports as. */
60+
variableName?: string
5761
}
5862

5963
// Required action data that gets initialized when running within the GitHub Actions environment.
@@ -74,7 +78,8 @@ export const action = {
7478
setOutput: !isNullOrUndefined(getInput('set-output'))
7579
? getInput('set-output').toLowerCase() === 'true'
7680
: false,
77-
format: getInput('format')
81+
format: getInput('format'),
82+
variableName: getInput('variable-name')
7883
}
7984

8085
/** Status codes for the action. */

src/fetch.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,18 @@ export async function generateExport({
7474
format,
7575
saveLocation,
7676
saveName,
77-
setOutput
77+
setOutput,
78+
variableName
7879
}: ExportInterface): Promise<Status> {
7980
info('Saving the data... 📁')
8081
const file = `${saveLocation ? saveLocation : 'fetch-api-data-action'}/${
8182
saveName ? saveName : 'data'
8283
}.${format ? format : 'json'}`
8384
const dataEncoding = encoding ? encoding : 'utf8'
85+
const defaultVariableName = 'fetchApiData'
86+
const environmentVariableName = variableName
87+
? variableName
88+
: defaultVariableName
8489

8590
try {
8691
await mkdirP(`${saveLocation ? saveLocation : 'fetch-api-data-action'}`)
@@ -89,8 +94,8 @@ export async function generateExport({
8994
info(`Saved ${file} 💾`)
9095

9196
if (setOutput) {
92-
exportVariable('fetchApiData', data)
93-
setEnvironmentOutput('fetchApiData', data)
97+
exportVariable(environmentVariableName, data)
98+
setEnvironmentOutput(defaultVariableName, data)
9499
}
95100

96101
return Status.SUCCESS

0 commit comments

Comments
 (0)