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

Call in-process hook for deploy-action with parameters #610

Merged
merged 6 commits into from
Jan 25, 2023

Conversation

purplecabbage
Copy link
Member

@purplecabbage purplecabbage commented Oct 28, 2022

Description

feat: Adds call to oclif hooks for deploy-action during run/deploy and pass… it the actions being deployed
Previous hook implementation was not fine-grained enough as when the package-script for deploy-action was called, there was no context of what action was being deployed and the hook-script developer had to parse the cli params themselves to see -a action-1 filters.

This hopefully allows aio-cli plugin developers a more focused hook where they implement only the required amount and not respond to every oclif hook event init, prerun, postrun

InProc hook is fired during the deploy-action stage of:

  • aio app deploy
  • aio app deploy -a actionname
  • aio app run
  • aio app run --local

Related Issue

Working on this revealed #608

Motivation and Context

2 paths that should fire an inproc hook ...

  • aio app deploy [--action some-action]
    • for each action to be deployed fire an event with the config, which action is being deployed, isLocal
  • aio app run [--local]
    • for each action to be deployed

How Has This Been Tested?

To verify my hook (emiter) was working as expected, I added a quick hook (responder) to the app plugin.

// package.json
"oclif": {
    "hooks": {
      "deploy-actions": "./src/hooks"
    }
}

// ./src/hooks.js
module.exports.hook = async function ({ appConfig, filterEntities, isLocalDev }) {
  console.log('inproc hook called with appConfig => ', Object.keys(appConfig))
  console.log(`filterEntities: ${JSON.stringify(filterEntities)}, isLocalDev: ${isLocalDev}`)
}

Here is the output of various commands I ran to test, using the sample test hook above.

aio app run                   
inproc hook called with appConfig =>  [
  'app',        'ow',
  's3',         'web',
  'manifest',   'actions',
  'tests',      'root',
  'name',       'web2',
  'hooks',      'imsOrgId',
  'operations', 'envFile'
]
filterEntities: [], isLocalDev: false

// after modifying the `generic` action file .... 

inproc hook called with appConfig =>  [
  'app',        'ow',
  's3',         'web',
  'manifest',   'actions',
  'tests',      'root',
  'name',       'web2',
  'hooks',      'imsOrgId',
  'operations', 'envFile'
]
filterEntities: ["generic"], isLocalDev: false


// if the above calls are run with --local
// then the hook will be called with

 isLocalDev: true

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@codecov
Copy link

codecov bot commented Oct 28, 2022

Codecov Report

Merging #610 (627f875) into master (7fd11c0) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master      #610   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           54        54           
  Lines         2822      2828    +6     
  Branches       528       531    +3     
=========================================
+ Hits          2822      2828    +6     
Impacted Files Coverage Δ
src/commands/app/deploy.js 100.00% <100.00%> (ø)
src/commands/app/run.js 100.00% <100.00%> (ø)
src/lib/actions-watcher.js 100.00% <100.00%> (ø)
src/lib/deploy-actions.js 100.00% <100.00%> (ø)
src/lib/run-dev.js 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@MichaelGoberling MichaelGoberling self-requested a review December 13, 2022 17:41
Copy link
Contributor

@MichaelGoberling MichaelGoberling left a comment

Choose a reason for hiding this comment

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

Like this a lot... Seems like the nextgen for app builder internal plugin hooks. Very extensible

src/commands/app/deploy.js Outdated Show resolved Hide resolved
src/lib/deploy-actions.js Show resolved Hide resolved
@shazron
Copy link
Member

shazron commented Dec 20, 2022

Tested using:

  1. this PR branch (local link)
  2. this test plugin below
# repo: https://github.com/shazron/oclif-hooks-test
aio plugins install shazron/oclif-hooks-test
  1. added more than 1 action to my app
aio app add action

@purplecabbage purplecabbage merged commit c00e8af into adobe:master Jan 25, 2023
@purplecabbage purplecabbage deleted the InProc-Hooks branch January 25, 2023 02:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants