Skip to content

Commit

Permalink
feat: Detect shallow copies
Browse files Browse the repository at this point in the history
Closes Detect shallow working copies & show useful error message #109.
  • Loading branch information
franky47 committed Mar 3, 2022
1 parent c7bea87 commit 3e54024
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 25 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ In your workflow file:
steps:
# This action requires an unshallow working copy,
# so the following prerequisites are necessary:
- uses: actions/checkout@v1.1
- run: git fetch --prune --unshallow
- uses: actions/checkout@v3
with:
fetch-depth: 0

# Deploy your application
- uses: 47ng/actions-clever-cloud@v1.1
Expand Down
46 changes: 23 additions & 23 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ test('deploy default application (no arguments)', async () => {
cleverCLI: 'clever'
})

expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', ['deploy'])
expect(exec).toHaveBeenNthCalledWith(3, 'clever', ['deploy'])
expect(core.setFailed).not.toHaveBeenCalled()
})

Expand All @@ -38,14 +38,14 @@ test('deploy application with alias', async () => {
cleverCLI: 'clever'
})

expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
'deploy',
'--alias',
'app-alias'
Expand All @@ -60,20 +60,20 @@ test('deploy application with app ID', async () => {
appID: 'app_facade42-cafe-babe-cafe-deadf00dbaad',
cleverCLI: 'clever'
})
expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
'link',
'app_facade42-cafe-babe-cafe-deadf00dbaad',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad'
])
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
'deploy',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad'
Expand All @@ -88,20 +88,20 @@ test('when both app ID and alias are provided, appID takes precedence', async ()
appID: 'app_facade42-cafe-babe-cafe-deadf00dbaad',
cleverCLI: 'clever'
})
expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
'link',
'app_facade42-cafe-babe-cafe-deadf00dbaad',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad'
])
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
'deploy',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad'
Expand All @@ -118,26 +118,26 @@ test('passing extra env variables, using no input args', async () => {
egg: 'spam'
}
})
expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
'env',
'set',
'foo',
'bar'
])
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
'env',
'set',
'egg',
'spam'
])
expect(exec).toHaveBeenNthCalledWith(4, 'clever', ['deploy'])
expect(exec).toHaveBeenNthCalledWith(5, 'clever', ['deploy'])
})

test('passing extra env variables, using appID', async () => {
Expand All @@ -151,36 +151,36 @@ test('passing extra env variables, using appID', async () => {
egg: 'spam'
}
})
expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
'link',
'app_facade42-cafe-babe-cafe-deadf00dbaad',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad'
])
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
'env',
'set',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad',
'foo',
'bar'
])
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
expect(exec).toHaveBeenNthCalledWith(5, 'clever', [
'env',
'set',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad',
'egg',
'spam'
])
expect(exec).toHaveBeenNthCalledWith(5, 'clever', [
expect(exec).toHaveBeenNthCalledWith(6, 'clever', [
'deploy',
'--alias',
'app_facade42-cafe-babe-cafe-deadf00dbaad'
Expand All @@ -198,30 +198,30 @@ test('passing extra env variables, using alias only', async () => {
egg: 'spam'
}
})
expect(exec).toHaveBeenNthCalledWith(1, 'clever', [
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
'login',
'--token',
'token',
'--secret',
'secret'
])
expect(exec).toHaveBeenNthCalledWith(2, 'clever', [
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
'env',
'set',
'--alias',
'foo',
'foo',
'bar'
])
expect(exec).toHaveBeenNthCalledWith(3, 'clever', [
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
'env',
'set',
'--alias',
'foo',
'egg',
'spam'
])
expect(exec).toHaveBeenNthCalledWith(4, 'clever', [
expect(exec).toHaveBeenNthCalledWith(5, 'clever', [
'deploy',
'--alias',
'foo'
Expand Down
19 changes: 19 additions & 0 deletions src/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ export function processArguments(): Arguments {
}
}

async function checkForShallowCopy(): Promise<void> {
let output = ''
await exec('git', ['rev-parse', '--is-shallow-repository'], {
listeners: {
stdout: (data: Buffer) => (output += data.toString())
}
})
if (output.trim() === 'true') {
throw new Error(`This action requires an unshallow working copy.
-> Use the following step before running this action:
- uses: actions/checkout@v3
with:
fetch-depth: 0
`)
}
}

export default async function run({
token,
secret,
Expand All @@ -83,6 +100,8 @@ export default async function run({
extraEnv = {}
}: Arguments): Promise<void> {
try {
await checkForShallowCopy()

core.debug(`Clever CLI path: ${cleverCLI}`)

// Authenticate (this will only store the credentials at a known location)
Expand Down

0 comments on commit 3e54024

Please sign in to comment.