Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve "yarn install --frozen-lockfile" #47

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/test/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mocked } from 'ts-jest/utils'
import { execSync, StdioOptions } from 'child_process'
import { execSync } from 'child_process'
import {
readFileSync,
writeFileSync,
Expand Down Expand Up @@ -535,7 +535,7 @@ describe('parseBoolean', () => {
})
})

describe('createExecutor', async () => {
describe('createExecutor', () => {
test('should return command executor and work correctly', () => {
const cwd = 'source'
const stdio = 'pipe'
Expand Down
19 changes: 15 additions & 4 deletions deploy/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,21 @@ export const main = async (): Promise<void> => {

core.info(`installing application dependencies`)

execSync(`yarn install --frozen-lockfile`, {
cwd: appDir,
stdio: 'inherit',
})
for (let retryIndex = 0; retryIndex < 10; retryIndex++) {
try {
execSync(`yarn install --frozen-lockfile`, {
cwd: appDir,
stdio: 'inherit',
})
break
} catch (error) {
if (/Couldn't find any versions for "@resolve-js/.test(`${error}`)) {
core.debug(`Retry ${retryIndex + 1}/10: yarn install --frozen-lockfile`)
} else {
throw error
}
}
}

const randomizer = parseBoolean(core.getInput('randomize_name'))
? randomize
Expand Down
20 changes: 20 additions & 0 deletions deploy/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,26 @@ test('app dependencies installation', async () => {
})
})

test('tolerate to script "yarn install" execution errors', async () => {
let retryIndex = 0
mExec.mockImplementation((command: string) => {
if (retryIndex < 3 && command.includes('yarn install --frozen-lockfile')) {
retryIndex++
throw new Error(
`Couldn't find any versions for "@resolve-js/some-package-name" that matches "x.y.z"`
)
}
return Buffer.from('')
})

await main()

expect(mExec).toHaveBeenCalledWith('yarn install --frozen-lockfile', {
cwd: '/source/dir',
stdio: 'inherit',
})
})

test('cloud CLI requested', async () => {
await main()

Expand Down
5 changes: 4 additions & 1 deletion install-cloud/test/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ beforeEach(() => {
}
return Buffer.from(result)
})
mCreateExecutor.mockImplementation((command) => execSync)
mCreateExecutor.mockImplementation((command: string) => {
void command
return execSync
})
mReadFile.mockReturnValue(
Buffer.from(
JSON.stringify({
Expand Down
2 changes: 0 additions & 2 deletions publish/test/unpublish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import { execSync } from 'child_process'
import { mocked } from 'ts-jest/utils'
import { unpublish } from '../src/unpublish'

type Octokit = ReturnType<typeof github.getOctokit>

jest.mock('@actions/core')
jest.mock('@actions/github')
jest.mock('fs')
Expand Down