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

[ACNA-1357] Optimize deploy to skip build & deploy. #497

Merged
merged 3 commits into from
Nov 2, 2021
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@parcel/reporter-cli": "2.0.0-beta.3.1",
"ajv": "^6.12.2",
"chalk": "^4.0.0",
"chokidar": "^3.4.2",
"chokidar": "^3.5.2",
"cli-ux": "^5.4.5",
"debug": "^4.1.1",
"dedent-js": "^1.0.1",
Expand Down
9 changes: 7 additions & 2 deletions src/lib/actions-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function createChangeHandler (watcherOptions) {
let undeployedFile = ''

return async (filePath) => {
aioLogger.debug('Code change triggered...')
if (deploymentInProgress) {
aioLogger.debug(`${filePath} has changed. Deploy in progress. This change will be deployed after completion of current deployment.`)
undeployedFile = filePath
Expand All @@ -91,8 +92,12 @@ function createChangeHandler (watcherOptions) {
try {
aioLogger.debug(`${filePath} has changed. Redeploying actions.`)
const filterActions = getActionNameFromPath(filePath, watcherOptions)
await buildAndDeploy(watcherOptions, filterActions)
aioLogger.debug('Deployment successful')
if (!filterActions.length) {
log(' -> A non-action file was changed, restart is required to deploy...')
} else {
await buildAndDeploy(watcherOptions, filterActions)
aioLogger.debug('Deployment successful')
}
} catch (err) {
log(' -> Error encountered while deploying actions. Stopping auto refresh.')
aioLogger.debug(err)
Expand Down
10 changes: 6 additions & 4 deletions test/commands/lib/actions-watcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const chokidar = require('chokidar')
const mockLogger = require('@adobe/aio-lib-core-logging')
const buildActions = require('../../../src/lib/build-actions')
const deployActions = require('../../../src/lib/deploy-actions')
const buildAndDeploy = require('../../../src/lib/deploy-actions')
const util = require('util')
const dataMocks = require('../../data-mocks/config-loader')
const sleep = util.promisify(setTimeout)
Expand All @@ -38,6 +39,7 @@ beforeEach(() => {

buildActions.mockReset()
deployActions.mockReset()
buildAndDeploy.mockReset()
})

test('exports', () => {
Expand Down Expand Up @@ -153,7 +155,7 @@ test('onChange handler calls buildActions with filterActions', async () => {
)
})

test('onChange handler calls buildActions without filterActions when actions are undefined', async () => {
test('on non-action file changed, skip build&deploy', async () => {
const { application } = createAppConfig()
const cloneApplication = cloneDeep(application)
Object.entries(cloneApplication.manifest.full.packages).forEach(([, pkg]) => {
Expand All @@ -176,10 +178,10 @@ test('onChange handler calls buildActions without filterActions when actions are
await actionsWatcher({ config: cloneApplication, log })
expect(typeof onChangeHandler).toEqual('function')

deployActions.mockImplementation(async () => await sleep(2000))
onChangeHandler('/myactions/action.js')
buildAndDeploy.mockImplementation(async () => await sleep(2000))
onChangeHandler('/myactions/utils.js')
Copy link
Contributor

@sandeep-paliwal sandeep-paliwal Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we only watch action source file or action folder?
From issue description I felt if files outside action source folder are modified then we ask for restart. is this correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sandeep-paliwal
We watch the action folder and deploy only when an action file source gets changed.
When a file in the action folder, other than the action input, gets changed, we notify the user that a restart is required in order to redeploy the actions affected by that file.


await jest.runAllTimers()

expect(buildActions).toHaveBeenCalledWith(cloneApplication, [])
expect(buildAndDeploy).not.toHaveBeenCalled()
})