Skip to content

Commit 7446b3d

Browse files
committed
Merge branch 'dev' into releases/v2
2 parents df6c6ee + 5e1aba9 commit 7446b3d

16 files changed

+989
-1508
lines changed

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- uses: actions/setup-node@v4
2121
with:
22-
node-version-file: '.nvmrc'
22+
node-version-file: '.node-version'
2323
registry-url: 'https://registry.npmjs.org'
2424

2525
- name: Install Yarn

.github/workflows/integration.yml

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
workflow_dispatch:
55
schedule:
66
- cron: 30 15 * * 0-6
7-
87
push:
98
tags-ignore:
109
- '*.*'

.github/workflows/production.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- uses: actions/setup-node@v4
2121
with:
22-
node-version-file: '.nvmrc'
22+
node-version-file: '.node-version'
2323
registry-url: 'https://registry.npmjs.org'
2424

2525
- name: Install Yarn

.github/workflows/version.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# Setup .npmrc file to publish to npm
3030
- uses: actions/setup-node@v4
3131
with:
32-
node-version-file: '.nvmrc'
32+
node-version-file: '.node-version'
3333
registry-url: 'https://registry.npmjs.org'
3434
scope: '@jamesives'
3535

@@ -60,7 +60,7 @@ jobs:
6060
# Setup .npmrc file to publish to GitHub Packages
6161
- uses: actions/setup-node@v4
6262
with:
63-
node-version-file: '.nvmrc'
63+
node-version-file: '.node-version'
6464
registry-url: 'https://npm.pkg.github.com'
6565
scope: '@jamesives'
6666

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v22.11.0

.nvmrc

-1
This file was deleted.

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ When contributing to this repository, please first discuss the change you wish t
1515

1616
## Deploying 🚚
1717

18-
In order to deploy and test your own fork of this action, you must commit the `node_modules` dependencies. Be sure to run `nvm use` before installing any dependencies. You can learn more about nvm [here](https://github.com/nvm-sh/nvm/blob/master/README.md).
18+
In order to deploy and test your own fork of this action, you must commit the `node_modules` dependencies. Be sure to switch to the Node version listed in the [.node-version](./.node-version) file first.
1919

2020
To do this you can follow the instructions below:
2121

__tests__/fetch.test.ts

+26-25
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import {retrieveData, generateExport} from '../src/fetch'
2-
import nock from 'nock'
32

43
jest.setTimeout(1000000)
5-
nock.enableNetConnect()
64

75
describe('fetch', () => {
86
describe('retrieveData', () => {
9-
afterEach(nock.cleanAll)
10-
afterAll(nock.restore)
7+
afterEach(() => {
8+
jest.clearAllMocks()
9+
})
1110

1211
it('should return some data', async () => {
13-
nock('https://jamesiv.es').get('/').reply(200, {
14-
data: '12345'
12+
global.fetch = jest.fn().mockResolvedValue({
13+
ok: true,
14+
json: jest.fn().mockResolvedValue({data: '12345'}),
15+
text: jest.fn().mockResolvedValue('{"data":"12345"}')
1516
})
1617

1718
const data = await retrieveData({
@@ -22,11 +23,11 @@ describe('fetch', () => {
2223
})
2324

2425
it('should handle the triple bracket replacements', async () => {
25-
nock('https://jives.dev/')
26-
.post('/', '{"bestCat":"montezuma"}')
27-
.reply(200, {
28-
data: '12345'
29-
})
26+
global.fetch = jest.fn().mockResolvedValue({
27+
ok: true,
28+
json: jest.fn().mockResolvedValue({data: '12345'}),
29+
text: jest.fn().mockResolvedValue('{"data":"12345"}')
30+
})
3031

3132
const data = await retrieveData({
3233
debug: true,
@@ -45,8 +46,6 @@ describe('fetch', () => {
4546

4647
it('should error if improperly formatted json is passed in', async () => {
4748
try {
48-
nock('https://jamesiv.es').get('/').reply(200)
49-
5049
await retrieveData({
5150
debug: true,
5251
endpoint: 'https://example.com',
@@ -61,8 +60,10 @@ describe('fetch', () => {
6160
})
6261

6362
it('should error if the response is not ok', async () => {
64-
nock('https://jamesiv.es').post('/').reply(404, {
65-
a: 1
63+
global.fetch = jest.fn().mockResolvedValue({
64+
ok: false,
65+
json: jest.fn().mockResolvedValue({a: 1}),
66+
text: jest.fn().mockResolvedValue('{"a":1}')
6667
})
6768

6869
try {
@@ -83,18 +84,18 @@ describe('fetch', () => {
8384
}
8485
})
8586

86-
it('should error if the response is not ok after several retrys', async () => {
87+
it('should error if the response is not ok after several retries', async () => {
8788
jest.setTimeout(1000000)
88-
89-
try {
90-
nock('https://jives.dev').get('/').once().replyWithError({
91-
message: 'This is catastrophic'
92-
})
93-
94-
nock('https://jives.dev').get('/').reply(200, {
95-
data: '12345'
89+
global.fetch = jest
90+
.fn()
91+
.mockRejectedValueOnce(new Error('This is catastrophic'))
92+
.mockResolvedValueOnce({
93+
ok: true,
94+
json: jest.fn().mockResolvedValue({data: '12345'}),
95+
text: jest.fn().mockResolvedValue('{"data":"12345"}')
9696
})
9797

98+
try {
9899
await retrieveData({
99100
debug: true,
100101
endpoint: 'https://jives.dev',
@@ -117,7 +118,7 @@ describe('fetch', () => {
117118
expect(process.env['fetchApiData']).toBe('{"bestCat":"montezuma"}')
118119
})
119120

120-
it('should save non standard file types', async () => {
121+
it('should save non-standard file types', async () => {
121122
await generateExport({
122123
data: 'hello',
123124
format: 'txt',

__tests__/lib.test.ts

+21-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {exportVariable, setFailed} from '@actions/core'
2-
import nock from 'nock'
32
import {action} from '../src/constants'
43
import run from '../src/lib'
54
import '../src/main'
@@ -15,38 +14,49 @@ jest.mock('@actions/core', () => ({
1514

1615
describe('lib', () => {
1716
beforeEach(() => {
18-
nock('https://jamesiv.es').get('/').reply(200, {
19-
data: '12345'
17+
jest.clearAllMocks()
18+
19+
global.fetch = jest.fn().mockResolvedValue({
20+
json: jest.fn().mockResolvedValue({data: '12345'}),
21+
text: jest.fn().mockResolvedValue('{"data":"12345"}'),
22+
ok: true
2023
})
2124
})
2225

2326
afterEach(() => {
24-
nock.restore()
2527
Object.assign(action, JSON.parse(originalAction))
2628
})
2729

28-
afterEach(nock.cleanAll)
29-
3030
it('should run through the commands', async () => {
3131
Object.assign(action, {
3232
debug: true,
33-
endpoint: 'https://jamesiv.es',
33+
endpoint: 'https://jives.dev',
3434
setOutput: true
3535
})
36+
3637
await run(action)
3738

38-
expect(exportVariable).toHaveBeenCalled()
39+
expect(exportVariable).toHaveBeenCalledTimes(1)
40+
expect(global.fetch).toHaveBeenCalledWith(
41+
'https://jives.dev',
42+
expect.any(Object)
43+
)
3944
})
4045

4146
it('should run through the commands but not save output', async () => {
4247
Object.assign(action, {
4348
debug: true,
44-
endpoint: 'https://jamesiv.es',
49+
endpoint: 'https://jives.dev',
4550
setOutput: false
4651
})
52+
4753
await run(action)
4854

4955
expect(exportVariable).toHaveBeenCalledTimes(0)
56+
expect(global.fetch).toHaveBeenCalledWith(
57+
'https://jives.dev',
58+
expect.any(Object)
59+
)
5060
})
5161

5262
it('should throw an error if no endpoint is provided', async () => {
@@ -58,6 +68,7 @@ describe('lib', () => {
5868
try {
5969
await run(action)
6070
} catch (error) {
71+
console.error(error)
6172
expect(setFailed).toHaveBeenCalled()
6273
}
6374
})
@@ -73,6 +84,7 @@ describe('lib', () => {
7384
try {
7485
await run(action)
7586
} catch (error) {
87+
console.error(error)
7688
expect(setFailed).toHaveBeenCalled()
7789
}
7890
})

eslint.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default tseslint.config(
1717
},
1818
rules: {
1919
'jest/no-conditional-expect': 'off',
20-
'@typescript-eslint/ban-types': [
20+
'@typescript-eslint/no-restricted-types': [
2121
'error',
2222
{
2323
types: {

package.json

+15-17
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,28 @@
3535
"github-action"
3636
],
3737
"dependencies": {
38-
"@actions/core": "1.10.1",
38+
"@actions/core": "1.11.1",
3939
"@actions/io": "1.1.3",
4040
"async-retry": "1.3.3",
41-
"cross-fetch": "4.0.0",
4241
"mustache": "4.2.0"
4342
},
4443
"devDependencies": {
45-
"@types/async-retry": "1.3.0",
46-
"@types/jest": "29.5.12",
44+
"@types/async-retry": "1.4.9",
45+
"@types/jest": "29.5.14",
4746
"@types/mustache": "4.2.5",
48-
"@types/node": "20.12.7",
47+
"@types/node": "22.9.0",
4948
"@types/retry": "0.12.5",
50-
"@typescript-eslint/eslint-plugin": "7.9.0",
51-
"@typescript-eslint/parser": "7.9.0",
52-
"eslint": "9.0.0",
49+
"@typescript-eslint/eslint-plugin": "8.13.0",
50+
"@typescript-eslint/parser": "8.13.0",
51+
"eslint": "9.14.0",
5352
"eslint-config-prettier": "9.1.0",
54-
"eslint-plugin-jest": "28.5.0",
55-
"eslint-plugin-prettier": "5.1.3",
56-
"jest": "27.5.1",
57-
"jest-circus": "27.5.1",
58-
"nock": "13.5.4",
59-
"prettier": "3.2.5",
60-
"ts-jest": "29.1.2",
61-
"typescript": "5.4.5",
62-
"typescript-eslint": "7.7.0"
53+
"eslint-plugin-jest": "28.9.0",
54+
"eslint-plugin-prettier": "5.2.1",
55+
"jest": "29.7.0",
56+
"jest-circus": "29.7.0",
57+
"prettier": "3.3.3",
58+
"ts-jest": "29.2.5",
59+
"typescript": "5.6.3",
60+
"typescript-eslint": "8.13.0"
6361
}
6462
}

src/constants.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import {getInput} from '@actions/core'
22
import {isNullOrUndefined} from './util'
33

4+
/**
5+
* Required action data that gets initialized when running within the GitHub Actions environment.
6+
*/
47
export interface ActionInterface {
58
/** Allows you to log the retrieved data to the terminal. */
69
debug?: boolean
@@ -28,6 +31,9 @@ export interface ActionInterface {
2831
variableName?: string
2932
}
3033

34+
/**
35+
* Required data to fetch the data.
36+
*/
3137
export interface DataInterface {
3238
/** Allows you to log the retrieved data to the terminal. */
3339
debug?: boolean
@@ -43,6 +49,9 @@ export interface DataInterface {
4349
retry?: boolean | null
4450
}
4551

52+
/**
53+
* Required data to export the data.
54+
*/
4655
export interface ExportInterface {
4756
/** The data to save. */
4857
data: string
@@ -60,7 +69,9 @@ export interface ExportInterface {
6069
variableName?: string
6170
}
6271

63-
// Required action data that gets initialized when running within the GitHub Actions environment.
72+
/**
73+
* Required action data that gets initialized when running within the GitHub Actions environment.
74+
*/
6475
export const action = {
6576
debug: !isNullOrUndefined(getInput('debug'))
6677
? getInput('debug').toLowerCase() === 'true'

src/fetch.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {
55
debug
66
} from '@actions/core'
77
import {mkdirP} from '@actions/io'
8-
import 'cross-fetch/polyfill'
98
import {promises as fs} from 'fs'
109
import {render} from 'mustache'
1110
import retryRequest from 'async-retry'
1211
import {DataInterface, ExportInterface, Status} from './constants'
1312
import {parseData} from './util'
1413

15-
/* Fetches or Posts data to an API. If auth is provided it will replace the mustache variables with the data from it. */
14+
/**
15+
* Retrieves data from an API endpoint.
16+
*/
1617
export async function retrieveData({
1718
debug: requestDebug,
1819
endpoint,
@@ -67,7 +68,9 @@ export async function retrieveData({
6768
}
6869
}
6970

70-
/* Saves the data to the local file system and exports an environment variable containing the retrieved data. */
71+
/**
72+
* Generates an export file from the data provided.
73+
*/
7174
export async function generateExport({
7275
data,
7376
encoding,

src/lib.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default async function run(
3131
hasRequiredParameters(settings)
3232

3333
let auth = ''
34+
3435
if (settings.tokenEndpoint) {
3536
auth = await retrieveData({
3637
debug: settings.debug,

0 commit comments

Comments
 (0)