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 MacOS support #116

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
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
48 changes: 36 additions & 12 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest]
os: [windows-latest, ubuntu-latest, macos-latest]
auth_type: [sql_login, aad_password, service_principal] # Unique for each parallel job run, part of TEST_DB name to ensure no collisions from parallel jobs
include:
# Includes the connection string Github secret name, effectively a switch statement on auth_type
- auth_type: sql_login
connection_string_secret: AZURE_SQL_CONNECTION_STRING_NO_DATABASE
- auth_type: aad_password
connection_string_secret: AAD_PASSWORD_CONNECTION_STRING_NO_DATABASE
- auth_type: service_principal
connection_string_secret: SERVICE_PRINCIPAL_CONNECTION_STRING_NO_DATABASE

env:
TEST_DB: 'SqlActionTest-${{ matrix.os }}'
TEST_DB: 'SqlActionTest-${{ matrix.os }}-${{ matrix.auth_type }}'

steps:
- name: Checkout from PR branch
Expand All @@ -42,26 +52,40 @@ jobs:
- name: Test DACPAC Action
uses: ./
with:
connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};'
dacpac-package: ./__testdata__/sql-action.dacpac
connection-string: '${{ secrets[matrix.connection_string_secret] }}Initial Catalog=${{ env.TEST_DB }};'
tenant-id: '${{ secrets.AAD_TENANT_ID }}'
path: ./__testdata__/sql-action.dacpac
action: 'publish'

# Build and publish sqlproj that should create a new view
- name: Test Build and Publish
uses: ./
with:
connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};'
project-file: ./__testdata__/TestProject/sql-action.sqlproj
connection-string: '${{ secrets[matrix.connection_string_secret] }}Initial Catalog=${{ env.TEST_DB }};'
tenant-id: '${{ secrets.AAD_TENANT_ID }}'
path: ./__testdata__/TestProject/sql-action.sqlproj
action: 'publish'

# Execute testsql.sql via SQLCMD on server
# Execute testsql.sql via script action on server
- name: Test SQL Action
uses: ./
with:
connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};'
sql-file: ./__testdata__/testsql.sql
connection-string: '${{ secrets[matrix.connection_string_secret] }}Initial Catalog=${{ env.TEST_DB }};'
tenant-id: '${{ secrets.AAD_TENANT_ID }}'
path: ./__testdata__/testsql.sql

# Test that go-sqlcmd has been added to runner, this step will be removed in future PR when go-sqlcmd is hooked up
- name: Test go-sqlcmd is setup
run: sqlcmd -?

- name: Set database name for cleanup
if: always()
run: sed 's/$(DbName)/${{ env.TEST_DB }}/' ./__testdata__/cleanup.sql > ${{ runner.temp }}/cleanup.sql

- name: Cleanup Test Database
if: always()
uses: ./
with:
connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=master;'
sql-file: ./__testdata__/cleanup.sql
arguments: '-v DbName="${{ env.TEST_DB }}"'
connection-string: '${{ secrets[matrix.connection_string_secret] }}Initial Catalog=master;'
tenant-id: '${{ secrets.AAD_TENANT_ID }}'
path: ${{ runner.temp }}/cleanup.sql
57 changes: 32 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ Get started today with a [free Azure account](https://azure.com/free/open-source
The definition of this GitHub Action is in [action.yml](https://github.com/Azure/sql-action/blob/master/action.yml). Learn more in the [user guide](#📓-user-guide).

```yaml
- uses: azure/sql-action@v1.3
- uses: azure/sql-action@v2
with:
connection-string: # required, connection string incl the database and user authentication information
# required, connection string incl the database and user authentication information
connection-string:

# optional for SQL project deployment - project-file, build-arguments
project-file: # path to a .sqlproj file
build-arguments: # additional arguments applied to dotnet build when building the .sqlproj to .dacpac
# required, path to either a .sql, .dacpac, or .sqlproj file
path:

# optional for dacpac deployment - dacpac-package
dacpac-package: # path to a .dacpac file
# optional when using a .sql script, required otherwise
# sqlpackage action on the .dacpac or .sqlproj file, only Publish is supported now
action:

# optional for SQL scripts deployment - sql-file
sql-file: # path to SQL scripts
# optional app (client) ID when using Azure Active Directory authentication
client-id:

# optional tenant ID of the Active Directory when using AAD auth and the 'common' tenant isn't available
tenant-id:

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

# optional additional dotnet build arguments when building a database project file
build-arguments:
```

## 🎨 Samples
Expand All @@ -45,10 +51,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: azure/sql-action@v1.3
- uses: azure/sql-action@v2
with:
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
project-file: './Database.sqlproj'
path: './Database.sqlproj'
action: 'publish'
build-arguments: '-c Release' # Optional arguments passed to dotnet build
arguments: '/p:DropObjectsNotInSource=true' # Optional parameters for SqlPackage Publish
```
Expand All @@ -67,10 +74,10 @@ jobs:
- uses: azure/login@v1 # Azure login required to add a temporary firewall rule
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- uses: azure/sql-action@v1.3
- uses: azure/sql-action@v2
with:
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
sql-file: './sqlscripts/*.sql'
path: './sqlscripts/*.sql'
```

### Deploy a DACPAC to an Azure SQL database with Allow Azure Services access enabled
Expand All @@ -84,10 +91,11 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: azure/sql-action@v1.3
- uses: azure/sql-action@v2
with:
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
dacpac-package: './Database.dacpac'
path: './Database.dacpac'
action: 'publish'
arguments: '/p:DropObjectsNotInSource=true' # Optional parameters for SqlPackage Publish
```

Expand All @@ -96,15 +104,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 Expand Up @@ -166,10 +171,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: azure/sql-action@v1.3
- uses: azure/sql-action@v2
with:
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
project-file: './Database.sqlproj'
path: './Database.sqlproj'
action: 'publish'
```
3. Place the connection string from the Azure Portal in GitHub secrets as `AZURE_SQL_CONNECTION_STRING`. Connection string format is: `Server=<server.database.windows.net>;User ID=<user>;Password=<password>;Initial Catalog=<database>`.
4. Copy the below SQL project template and paste the content in your project repository as `Database.sqlproj`.
Expand Down Expand Up @@ -218,10 +224,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: azure/sql-action@v1.3
- uses: azure/sql-action@v2
with:
connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }}
dacpac-package: './PreviousDatabase.dacpac'
path: './PreviousDatabase.dacpac'
action: 'publish'
```
4. Place the connection string from the Azure Portal in GitHub secrets as `AZURE_SQL_CONNECTION_STRING`. Connection string format is: `Server=<server.database.windows.net>;User ID=<user>;Password=<password>;Initial Catalog=<database>`.
5. Commit and push your project to GitHub repository, you should see a new GitHub Action initiated in **Actions** tab.
Expand Down
6 changes: 3 additions & 3 deletions __testdata__/testsql.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
-- 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 [Table1] VALUES(1, 'test');
INSERT INTO [dbo].[Table1] VALUES(1, 'test');

-- This should successfully SELECT from the view created by the sqlproj
SELECT * FROM [View1];
SELECT * FROM [dbo].[View1];
Loading