Skip to content

Commit

Permalink
fix: lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
hulk510 committed Jan 17, 2024
1 parent 3f6d7b0 commit 9d9ca21
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
19 changes: 9 additions & 10 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ import * as main from '../src/main'
const runMock = jest.spyOn(main, 'run')

// Other utilities
const timeRegex = /^\d{2}:\d{2}:\d{2}/
// const timeRegex = /^\d{2}:\d{2}:\d{2}/

// Mock the GitHub Actions core library
let debugMock: jest.SpyInstance
// let debugMock: jest.SpyInstance
let errorMock: jest.SpyInstance
let getInputMock: jest.SpyInstance
let setFailedMock: jest.SpyInstance
let setOutputMock: jest.SpyInstance
// let setFailedMock: jest.SpyInstance
// let setOutputMock: jest.SpyInstance

describe('action', () => {
beforeEach(() => {
jest.clearAllMocks()

debugMock = jest.spyOn(core, 'debug').mockImplementation()
// debugMock = jest.spyOn(core, 'debug').mockImplementation()
errorMock = jest.spyOn(core, 'error').mockImplementation()
getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
// setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
// setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
})

it('sets the time output', async () => {
Expand All @@ -51,7 +51,6 @@ describe('action', () => {
expect(errorMock).not.toHaveBeenCalled()
})

it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
})
it.todo('sets a failed status')
// Set the action's inputs as return values from core.getInput()
})
52 changes: 23 additions & 29 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,44 @@ export async function run(): Promise<void> {
if (headRef) {
// Get the list of cache IDs
// https://github.com/octokit/plugin-paginate-rest.js#octokitpaginate
const cacheIdList = await octokit.paginate(
const iterator = octokit.paginate.iterator(
octokit.rest.actions.getActionsCacheList,
{
...repo,
ref
},
response => response.data.flatMap(cache => cache.id ?? [])
ref: headRef
}
)
if (cacheIdList.length === 0) {
core.info('No cache found.')
return
}

// Delete the caches
cacheIdList.forEach(async id => {
await octokit.rest.actions.deleteActionsCacheById({
...repo,
cache_id: id
})
})
for await (const { data: cacheList } of iterator) {
for (const { id: cacheId } of cacheList) {
if (!cacheId) continue
await octokit.rest.actions.deleteActionsCacheById({
...repo,
cache_id: cacheId
})
}
}
}

// Get the list of cache IDs
// https://github.com/octokit/plugin-paginate-rest.js#octokitpaginate
const cacheIdList = await octokit.paginate(
const iterator = octokit.paginate.iterator(
octokit.rest.actions.getActionsCacheList,
{
...repo,
ref
},
response => response.data.flatMap(cache => cache.id ?? [])
}
)
if (cacheIdList.length === 0) {
core.info('No cache found.')
return
}

// Delete the caches
cacheIdList.forEach(async id => {
await octokit.rest.actions.deleteActionsCacheById({
...repo,
cache_id: id
})
})
for await (const { data: cacheList } of iterator) {
for (const { id: cacheId } of cacheList) {
if (!cacheId) continue
await octokit.rest.actions.deleteActionsCacheById({
...repo,
cache_id: cacheId
})
}
}
} catch (error) {
// Fail the workflow run if an error occurs
if (error instanceof Error) core.setFailed(error.message)
Expand Down

0 comments on commit 9d9ca21

Please sign in to comment.