Skip to content
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 .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
tenant-id: '${{ secrets.AAD_TENANT_ID }}'
project-file: ./__testdata__/TestProject/sql-action.sqlproj

# Execute testsql.sql via SQLCMD on server
# Execute testsql.sql via script action on server
- name: Test SQL Action
uses: ./
with:
Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ The definition of this GitHub Action is in [action.yml](https://github.com/Azure
# optional for SQL scripts deployment - sql-file
sql-file: # path to SQL scripts


# optional for all deployments - arguments
arguments: # sqlpackage arguments for .sqlproj or .dacpac deployment or sqlcmd arguments for SQL script deployment
arguments: # sqlpackage arguments for .sqlproj or .dacpac deployment
```

## 🎨 Samples
Expand Down Expand Up @@ -96,15 +95,12 @@ jobs:

### Authentication

The v1.x version of sql-action supports SQL authentication only in the connection string.

The `server-name` action YAML key is optional and is only available to provide backward compatibility. It is strongly recommended to put the server name in the connection string as displayed in the examples. The connection string uses this template: `Server=<servername>; User ID=<user_id>; Password=<password>; Initial Catalog=<database>`. In case the server name is put both in the `server-name` and in the `connection-string`, the server name used will be the one specified in the `server-name` YAML key.
The v1.x version of sql-action supports SQL authentication only in the connection string. Starting in v2, AAD Password, AAD Service Principal, and AAD Default authentications are also supported.

### Environments

sql-action is supported on both Windows and Linux environments. The [default images](https://github.com/actions/virtual-environments) include the prerequisites:

- sqlcmd
- sqlpackage (for sqlproj or dacpac deployment)
- dotnet (for sqlproj build)

Expand Down
2 changes: 1 addition & 1 deletion __testdata__/testsql.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- This script is used by pr-check.yml to test the SQLCMD action
-- This script is used by pr-check.yml to test the script action

-- This should successfully insert data into the table created in the DACPAC step
INSERT INTO [dbo].[Table1] VALUES(1, 'test');
Expand Down
2 changes: 1 addition & 1 deletion lib/main.js

Large diffs are not rendered by default.

70 changes: 0 additions & 70 deletions src/AzureSqlActionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,6 @@ export default class AzureSqlActionHelper {
return this._sqlPackagePath;
}

public static async getSqlCmdPath(): Promise<string> {
if (!!this._sqlCmdPath) {
core.debug(`Return the cached path of SqlCmd executable: ${this._sqlCmdPath}`);
return this._sqlCmdPath;
}

if (IS_WINDOWS) {
this._sqlCmdPath = await this._getSqlCmdExecutablePath();
}
else if (IS_LINUX) {
this._sqlCmdPath = this._getSqlCmdBinaryPathLinux();
}
else {
this._sqlCmdPath = this._getSqlCmdBinaryPathMac();
}

return this._sqlCmdPath;
}

public static getRegistrySubKeys(path: string): Promise<winreg.Registry[]> {
return new Promise((resolve) => {
core.debug(`Getting sub-keys at registry path: HKLM:${path}`);
Expand Down Expand Up @@ -314,64 +295,13 @@ export default class AzureSqlActionHelper {
);
}

private static async _getSqlCmdExecutablePath(): Promise<string>{
core.debug('Getting location of sqlcmd.exe');

let sqlServerRegistryKey64 = path.join('\\', 'SOFTWARE', 'Microsoft', 'Microsoft SQL Server');
if (!(await AzureSqlActionHelper.registryKeyExists(sqlServerRegistryKey64))) {
throw new Error('Unable to find the location for SqlCmd.exe from registry');
}

let subKeys = await AzureSqlActionHelper.getRegistrySubKeys(sqlServerRegistryKey64);
let sqlServerRegistryKeys = this._getVersionsRegistryKeys(subKeys);

for(let registryKey of sqlServerRegistryKeys) {

let clientSetupToolsRegistryKeyPath = path.join(registryKey.key, 'Tools', 'ClientSetup');

if (await AzureSqlActionHelper.registryKeyExists(clientSetupToolsRegistryKeyPath)) {
let toolsPath = await AzureSqlActionHelper.getRegistryValue(new winreg ({
hive: winreg.HKLM,
key: clientSetupToolsRegistryKeyPath
}), 'ODBCToolsPath');

if (!toolsPath) {
// for older versions
await AzureSqlActionHelper.getRegistryValue(new winreg ({
hive: winreg.HKLM,
key: clientSetupToolsRegistryKeyPath
}), 'Path');
}

if (!!toolsPath) {
let sqlCmdPath = path.join(toolsPath, 'SQLCMD.exe');
if (fs.existsSync(sqlCmdPath)) {
core.debug(`SqlCmd.exe found at location: ${sqlCmdPath}`);
return sqlCmdPath;
}
}
}
}

throw new Error('Unable to find location of sqlcmd.exe');
}

private static _getSqlPackageBinaryPathLinux(): string {
return 'sqlpackage';
}

private static _getSqlCmdBinaryPathLinux(): string {
return 'sqlcmd';
}

private static _getSqlPackageBinaryPathMac(): string {
throw new Error('This action is not supported on a Mac environment.');
}

private static _getSqlCmdBinaryPathMac(): string {
throw new Error('This action is not supported on a Mac environment.');
}

private static _sqlPackagePath = '';
private static _sqlCmdPath = '';
}