diff --git a/README.md b/README.md index 84ec19d..52444a6 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 1c3896e..d478ce8 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -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() }) @@ -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' @@ -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' @@ -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' @@ -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 () => { @@ -151,20 +151,20 @@ 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', @@ -172,7 +172,7 @@ test('passing extra env variables, using appID', async () => { 'foo', 'bar' ]) - expect(exec).toHaveBeenNthCalledWith(4, 'clever', [ + expect(exec).toHaveBeenNthCalledWith(5, 'clever', [ 'env', 'set', '--alias', @@ -180,7 +180,7 @@ test('passing extra env variables, using appID', async () => { 'egg', 'spam' ]) - expect(exec).toHaveBeenNthCalledWith(5, 'clever', [ + expect(exec).toHaveBeenNthCalledWith(6, 'clever', [ 'deploy', '--alias', 'app_facade42-cafe-babe-cafe-deadf00dbaad' @@ -198,14 +198,14 @@ 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', @@ -213,7 +213,7 @@ test('passing extra env variables, using alias only', async () => { 'foo', 'bar' ]) - expect(exec).toHaveBeenNthCalledWith(3, 'clever', [ + expect(exec).toHaveBeenNthCalledWith(4, 'clever', [ 'env', 'set', '--alias', @@ -221,7 +221,7 @@ test('passing extra env variables, using alias only', async () => { 'egg', 'spam' ]) - expect(exec).toHaveBeenNthCalledWith(4, 'clever', [ + expect(exec).toHaveBeenNthCalledWith(5, 'clever', [ 'deploy', '--alias', 'foo' diff --git a/src/action.ts b/src/action.ts index 64f1f6b..867eca6 100644 --- a/src/action.ts +++ b/src/action.ts @@ -73,6 +73,23 @@ export function processArguments(): Arguments { } } +async function checkForShallowCopy(): Promise { + 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, @@ -83,6 +100,8 @@ export default async function run({ extraEnv = {} }: Arguments): Promise { try { + await checkForShallowCopy() + core.debug(`Clever CLI path: ${cleverCLI}`) // Authenticate (this will only store the credentials at a known location)