This repository was archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 160
feat: List deployments sub-command for deploy plugin #176
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5b99544
feat: List deployments subcommand for deploy plugin
tbarlow12 518144c
fix: Respond to PR feedback
tbarlow12 34fd963
fix: Resolve conflicts in baseService
tbarlow12 c26effb
fix: Fix lint error
tbarlow12 90cc958
Add test for empty deployments
tbarlow12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,46 @@ import { FunctionAppService } from "../../services/functionAppService"; | |
|
|
||
| export class AzureDeployPlugin { | ||
| public hooks: { [eventName: string]: Promise<any> }; | ||
| public commands: any; | ||
|
|
||
| public constructor(private serverless: Serverless, private options: Serverless.Options) { | ||
| this.hooks = { | ||
| "deploy:deploy": this.deploy.bind(this) | ||
| "deploy:deploy": this.deploy.bind(this), | ||
| "deploy:list:list": this.list.bind(this), | ||
| }; | ||
|
|
||
| this.commands = { | ||
| deploy: { | ||
| commands: { | ||
| list: { | ||
| usage: "List deployments", | ||
| lifecycleEvents: [ | ||
| "list" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private async list() { | ||
| this.serverless.cli.log("Listing deployments"); | ||
| const resourceService = new ResourceService(this.serverless, this.options); | ||
| const deployments = await resourceService.getDeployments(); | ||
| if (!deployments || deployments.length === 0) { | ||
| this.serverless.cli.log(`No deployments found for resource group '${resourceService.getResourceGroup()}'`); | ||
| return; | ||
| } | ||
| let stringDeployments = "\n\nDeployments"; | ||
|
|
||
| for (const dep of deployments) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If no deployments exist consider adding a line that says "No deployments found for resource group" or similar. |
||
| stringDeployments += "\n-----------\n" | ||
| stringDeployments += `Name: ${dep.name}\n` | ||
| stringDeployments += `Timestamp: ${dep.properties.timestamp.getTime()}\n`; | ||
| stringDeployments += `Datetime: ${dep.properties.timestamp.toISOString()}\n` | ||
| } | ||
| stringDeployments += "-----------\n" | ||
| this.serverless.cli.log(stringDeployments); | ||
| } | ||
|
|
||
| private async deploy() { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ jest.mock("@azure/arm-resources") | |
| import { ResourceManagementClient } from "@azure/arm-resources"; | ||
|
|
||
| describe("Resource Service", () => { | ||
| const deployments = MockFactory.createTestDeployments(); | ||
|
|
||
| beforeAll(() => { | ||
| ResourceManagementClient.prototype.resourceGroups = { | ||
|
|
@@ -14,7 +15,8 @@ describe("Resource Service", () => { | |
| } as any; | ||
|
|
||
| ResourceManagementClient.prototype.deployments = { | ||
| deleteMethod: jest.fn() | ||
| deleteMethod: jest.fn(), | ||
| listByResourceGroup: jest.fn(() => Promise.resolve(deployments)), | ||
| } as any; | ||
| }); | ||
|
|
||
|
|
@@ -70,4 +72,15 @@ describe("Resource Service", () => { | |
| expect(ResourceManagementClient.prototype.resourceGroups.deleteMethod) | ||
| .toBeCalledWith(resourceGroup); | ||
| }); | ||
|
|
||
| it("lists deployments", async () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another to test when deployments are empty |
||
| const sls = MockFactory.createTestServerless(); | ||
| const resourceGroup = "myResourceGroup"; | ||
| sls.service.provider["resourceGroup"] = resourceGroup | ||
| sls.variables["azureCredentials"] = "fake credentials" | ||
| const options = MockFactory.createTestServerlessOptions(); | ||
| const service = new ResourceService(sls, options); | ||
| const deps = await service.getDeployments(); | ||
| expect(deps).toEqual(deployments); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does defining these commands mess with the top level core plugin on the CLI ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was concerned about that, which is why I left out the
lifecycleEvents(I defined them at first, which causeddeployto be triggered twice). I set the plugin to logthis.commandsto see what the object looks like by default, and itame back undefined. In my manual testing, the deployment still works fine. Feel free to double check me on that though.