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

Add support for Script, DeployReport, and DriftReport #106

Merged
merged 7 commits into from
Aug 24, 2022

Conversation

zijchen
Copy link
Contributor

@zijchen zijchen commented Jul 5, 2022

Addresses #55 and then some

Right now just adds the flow-through from yaml to sqlpackage, nothing fancy, user needs to specify the /OutputPath in the sqlpackage-arguments field.

Depends on changes from #105

TODO: a sample workflow, triggered by PRs, that runs DeployReport and publishes the report as a comment on the PR

@zijchen zijchen temporarily deployed to Automation test July 6, 2022 00:00 Inactive
@zijchen zijchen temporarily deployed to Automation test July 6, 2022 00:00 Inactive
@zijchen zijchen temporarily deployed to Automation test July 6, 2022 00:00 Inactive
@zijchen zijchen temporarily deployed to Automation test July 6, 2022 00:00 Inactive
@zijchen zijchen temporarily deployed to Automation test July 6, 2022 00:00 Inactive
@zijchen zijchen temporarily deployed to Automation test July 6, 2022 00:00 Inactive
@zijchen zijchen changed the base branch from master to v2 July 6, 2022 00:19
@github-actions
Copy link

This PR is idle because it has been open for 14 days with no activity.

@github-actions github-actions bot added the idle Inactive for 14 days label Jul 20, 2022
@zijchen zijchen mentioned this pull request Aug 16, 2022
@zijchen zijchen temporarily deployed to Automation test August 18, 2022 23:41 Inactive
@zijchen zijchen temporarily deployed to Automation test August 18, 2022 23:41 Inactive
@zijchen zijchen temporarily deployed to Automation test August 18, 2022 23:41 Inactive
@zijchen zijchen temporarily deployed to Automation test August 18, 2022 23:41 Inactive
@zijchen zijchen temporarily deployed to Automation test August 18, 2022 23:41 Inactive
@zijchen zijchen temporarily deployed to Automation test August 18, 2022 23:41 Inactive
@zijchen zijchen marked this pull request as ready for review August 18, 2022 23:42
@zijchen zijchen removed the idle Inactive for 14 days label Aug 18, 2022
@chlafreniere
Copy link
Contributor

What's the relationship between main.ts and main.js? I see that main.js is being updated here, but not main.ts. Does main.ts not transpile into lib/main.js?

@@ -164,13 +164,20 @@ export default class AzureSqlAction {
let args = '';

switch (inputs.sqlpackageAction) {
case SqlPackageAction.Publish: {
args += `/Action:Publish /TargetConnectionString:"${inputs.connectionConfig.ConnectionString}" /SourceFile:"${inputs.filePath}"`;
case SqlPackageAction.Publish:
Copy link
Contributor

Choose a reason for hiding this comment

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

How about leveraging getSqlpackageActionTypeFromString(), saving the result into a variable, and switching on that variable? Then we wouldn't have to have logic checking for no action being passed in in two different places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I removed the redundant logic of checking for no action passed in here. SqlPackageAction should be set already at this point coming from the earlier check.

throw new Error(`Not supported SqlPackage action: '${SqlPackageAction[inputs.sqlpackageAction]}'`);
}
}

if (!!inputs.additionalArguments) {

Choose a reason for hiding this comment

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

what happens if the user doesn't pass in the OutputPath or DeployScriptPath for these new actions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sqlpackage will error out asking for one of those to be specified

@zijchen
Copy link
Contributor Author

zijchen commented Aug 19, 2022

What's the relationship between main.ts and main.js? I see that main.js is being updated here, but not main.ts. Does main.ts not transpile into lib/main.js?

@chlafreniere The *.ts file compile into main.js as defined in ./webpack.config.js. So any changes to any of the ts files under src/ will update main.js. main.js is what is used to run the action.

@zijchen zijchen linked an issue Aug 19, 2022 that may be closed by this pull request
@chlafreniere
Copy link
Contributor

What's the relationship between main.ts and main.js? I see that main.js is being updated here, but not main.ts. Does main.ts not transpile into lib/main.js?

@chlafreniere The *.ts file compile into main.js as defined in ./webpack.config.js. So any changes to any of the ts files under src/ will update main.js. main.js is what is used to run the action.

Thanks @zijchen. Not a huge fan of having what are basically build outputs checked in, but I understand that there are some constraints for GH actions in what they require (and also realize that you didn't write this code originally 😄). Certainly not something I'd block on here, just something to think about in the future.

@zijchen
Copy link
Contributor Author

zijchen commented Aug 19, 2022

@chlafreniere I totally agree with you that it feels janky to check in a build output. I looked at other actions and it does appear to be a limitation of GH Actions, all of them have a lib/dist folder with a js file in it. Hopefully there is a better way to do this in the future.

@chlafreniere
Copy link
Contributor

@chlafreniere I totally agree with you that it feels janky to check in a build output. I looked at other actions and it does appear to be a limitation of GH Actions, all of them have a lib/dist folder with a js file in it. Hopefully there is a better way to do this in the future.

Agreed! Sounds good, thanks for looking into this @zijchen, and thanks for indulging me in my curiosity 😄

* @param additionalArguments Additional arguments for this action type.
* @returns An ActionInputs objects based on the given action type.
*/
function getInputsWithCustomSqlPackageAction(actionType: ActionType, sqlpackageAction: SqlPackageAction, additionalArguments: string = '') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we specify the return type here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@@ -132,6 +150,29 @@ describe('AzureSqlAction tests', () => {
expect(getSqlPackagePathSpy).toHaveBeenCalledTimes(1); // Verify build succeeds and calls into Publish
expect(execSpy).toHaveBeenCalledTimes(2);
});

describe('validate errors on unsupported sqlpackage action types', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like how you're testing this negative scenario. How about another test for an invalid sqlpackage action as well? (e.g. Action 'foo')?

This would just ensure that we're handling invalid actions and giving users a consistent error message in future versions of the action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I moved this test to main.test.ts as the error handling is mainly there. At this point it expects the SqlpackageAction enum type so if it's not one of the supported ones, it becomes undefined. The error handling is further upstream.

@zijchen zijchen temporarily deployed to Automation test August 19, 2022 23:40 Inactive
@zijchen zijchen temporarily deployed to Automation test August 19, 2022 23:40 Inactive
@zijchen zijchen temporarily deployed to Automation test August 19, 2022 23:40 Inactive
@zijchen zijchen temporarily deployed to Automation test August 19, 2022 23:40 Inactive
@zijchen zijchen temporarily deployed to Automation test August 19, 2022 23:40 Inactive
@zijchen zijchen temporarily deployed to Automation test August 19, 2022 23:40 Inactive
expect(getSqlPackagePathSpy).toHaveBeenCalledTimes(1);
expect(execSpy).toHaveBeenCalledTimes(1);
expect(execSpy).toHaveBeenCalledWith(`"SqlPackage.exe" /Action:Publish /TargetConnectionString:"${inputs.connectionConfig.ConnectionString}" /SourceFile:"${inputs.filePath}" /TargetTimeout:20`);
it.each(inputs)('Validate %s action with args %s', async (actionName, sqlpackageArgs) => {
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to do it.each() instead of looping with a normal execution?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is jest's syntax for testing against each row of inputs, kind of similar to NUnit's test cases.

@@ -53,15 +52,16 @@ export default class AzureSqlAction {
await this._executeSqlFile(this._inputs);
}
else if (this._inputs.actionType === ActionType.BuildAndPublish) {
const dacpacPath = await this._executeBuildProject(this._inputs as IBuildAndPublishInputs);
const buildAndPublishInputs = this._inputs as IBuildAndPublishInputs;
Copy link
Member

Choose a reason for hiding this comment

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

Does anything need to be handled in case this doesn't cast successfully?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any invalid inputs should be handled by this point

@zijchen zijchen merged commit 412e851 into v2 Aug 24, 2022
@zijchen zijchen deleted the zijchen/deploy-report branch August 24, 2022 19:47
zijchen added a commit that referenced this pull request Sep 28, 2022
* v2 - Use tedious mssql module instead of sqlcmd (#96)

* Use tedious mssql library instead of sqlcmd

* Fix mssql connection

* Fix SqlUtils tests

* Use config instead of connection string

* Replace conn string builder with mssql config

* Connect to master db

* Restore connection string validation regex

* PR comments, fix error handling

* Update main.js

* Use try catch for error handling

* Fix typo

* v2 - Change script action from sqlcmd to mssql query (#99)

* Change script action from sqlcmd to mssql query

* Update action.yml

* Fully qualify Table1 in sql script

* Add more debug logging

* Clone config before changing db to master

* Cleanup

* Set TEST_DB name before cleanup

* Use runner.temp

* Always cleanup

* PR comments

* Fix database cleanup step in pr-check (#101)

* Debug script contents

* Fix sed command

* Remove debug

* v2 - Add support for AAD password, AAD default, and AAD service principal auth (#100)

* Use tedious mssql library instead of sqlcmd

* Fix mssql connection

* Fix SqlUtils tests

* Use config instead of connection string

* Replace conn string builder with mssql config

* Connect to master db

* Restore connection string validation regex

* AAD auth

* Add support for client and tenant IDs

* Add more debug messaging

* Fix connection string find array

* Make client-id and tenant-id action inputs

* Fix error handling

* More fixes

* Use try catch instead

* Add tests to pr-check.yml

* Change script action from sqlcmd to mssql query

* Update action.yml

* Fully qualify Table1 in sql script

* Add more debug logging

* Clone config before changing db to master

* Cleanup

* Set TEST_DB name before cleanup

* Use runner.temp

* Always cleanup

* Add tests for different auth types

* Mask tenant and client IDs

* Add AAD password test to pr-check.yml

* Fix yaml

* Limit max-parallel to 2

* Add test for service principal

* PR comments

* Fix typo

* Cleanup sqlcmd references (#102)

* Retry connection with user DB if master connection fails (#104)

* Retry with DB connection if master fails

* Add tests

* Add ConnectionResult interface

* Add missing doc comment

* PR comments

* PR Comments

* Download and extract go-sqlcmd before main action (#108)

* Add setup script to download go-sqlcmd

* Add sqlcmd call to pr-check.yml

* Add bz2 specific extract tar

* Move setup code to main

* Move setup code to main

* Fix casing of Setup.ts

* Use go-sqlcmd for script action (#113)

* call go-sqlcmd for script action

* Fix auth options not flowing through

* Add test cases

* Restore sqlcmd variable in cleanup script

* Fix pr-check cleanup

* Undo changes to pr-check.yml

* Undo pr-check.yml changes

* PR comments

* Change inputs (#105)

* Update SQL API version to 2021-11-01 (#117)

* Add support for Script, DeployReport, and DriftReport (#106)

* Change inputs

* Add other publish like actions

* Add tests

* Fix test

* PR comments

* Add mockReturnValue for auth type test

* Remove MacOS from ci.yml

* links to documentation on each argument type (#123)

* v2 - Remove client-id and tenant-id as inputs (#124)

* Set tenantId and clientId only when passed in

* Default to empty string

* Default to empty string

* Replace mssql call with go-sqlcmd query

* Capture sqlcmd error message

* Add more debug

* Capture stdout too

* Fix config passing

* Completely remove client-id and tenant-id

* cleanup

* Update sqlcmd query

* adding connection string format to docs (#138)

adding connection string format to docs

Co-authored-by: Drew Skwiers-Koballa <[email protected]>
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.

DeployReport support
4 participants