Skip to content

Commit

Permalink
fix: force build on every aio app run (for switching from remote and …
Browse files Browse the repository at this point in the history
…local contexts) (#551)
  • Loading branch information
shazron authored Jun 10, 2022
1 parent 6c7ca51 commit 073bb5b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/lib/build-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ const { buildActions } = require('@adobe/aio-lib-runtime')
*
* @param {object} config see src/lib/config-loader.js
* @param {Array<string>} filterActions add filters to deploy only specified OpenWhisk actions
* @param {boolean} [forceBuild=false] force a build (skip file changed hash check)
*/
module.exports = async (config, filterActions) => {
module.exports = async (config, filterActions, forceBuild = false) => {
utils.runScript(config.hooks['pre-app-build'])
const script = await utils.runScript(config.hooks['build-actions'])
if (!script) {
await buildActions(config, filterActions)
await buildActions(config, filterActions, forceBuild)
}
utils.runScript(config.hooks['post-app-build'])
}
2 changes: 1 addition & 1 deletion src/lib/run-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async function runDev (config, dataDir, options = {}, log = () => {}) {

// build and deploy actions
log('building actions..')
await buildActions(devConfig)
await buildActions(devConfig, null, true /* force build */)

const { cleanup: watcherCleanup } = await actionsWatcher({ config: devConfig, isLocal, log })
cleanup.add(() => watcherCleanup(), 'stopping action watcher...')
Expand Down
2 changes: 1 addition & 1 deletion test/commands/app/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ describe('run', () => {
}), expect.any(Function))
})

test('app:run with -verbose', async () => {
test('app:run with --verbose', async () => {
mockFSExists([PRIVATE_KEY_PATH, PUB_CERT_PATH])
command.argv = ['--verbose']
const appConfig = createAppConfig(command.appConfig)
Expand Down
14 changes: 14 additions & 0 deletions test/commands/lib/build-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,17 @@ test('no build-actions app hook available (use inbuilt)', async () => {
expect(utils.runScript).toHaveBeenNthCalledWith(2, 'build-actions')
expect(utils.runScript).toHaveBeenNthCalledWith(3, 'post-app-build')
})

test('forceBuild false (default)', async () => {
await buildActions(extensionConfig)

expect(rtBuildActions).toHaveBeenCalled()
expect(rtBuildActions).toHaveBeenCalledWith(extensionConfig, undefined, false)
})

test('forceBuild true', async () => {
await buildActions(extensionConfig, null, true)

expect(rtBuildActions).toHaveBeenCalled()
expect(rtBuildActions).toHaveBeenCalledWith(extensionConfig, null, true)
})
9 changes: 9 additions & 0 deletions test/commands/lib/run-dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,12 @@ test('devRemote true, build-static hook set, serve-static hook not set)', async
expect(logPoller.run).not.toHaveBeenCalled()
expect(actionsWatcher).toHaveBeenCalled()
})

test('runDev always force builds', async () => {
const config = cloneDeep(createAppConfig().application)

await runDev(config, DATA_DIR, { devRemote: true })

expect(buildActions).toHaveBeenCalled()
expect(buildActions).toHaveBeenCalledWith(expect.any(Object) /* config */, null /* filterActions */, true /* forceBuild */)
})

0 comments on commit 073bb5b

Please sign in to comment.