From c852a4c06321fda24ff4d13d9fb006d898a83821 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 4 Jan 2022 13:16:47 -0800 Subject: [PATCH 01/11] Add DACPAC action test to PR check --- .github/workflows/pr-check.yml | 25 ++++++++++++++++++------- __testdata__/sql-action.dacpac | Bin 0 -> 2287 bytes __testdata__/testsql.sql | 7 +++++++ testsql.sql | 3 --- 4 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 __testdata__/sql-action.dacpac create mode 100644 __testdata__/testsql.sql delete mode 100644 testsql.sql diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index c347f4e5..3f55ea4e 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -5,7 +5,7 @@ on: # branches: # - master # - 'releases/*' - + jobs: deploy: environment: Automation test @@ -14,25 +14,36 @@ jobs: matrix: os: [windows-latest, ubuntu-latest] steps: - - name: Checkout from PR branch + - name: Checkout from PR branch uses: actions/checkout@v2 - with: + with: repository: ${{ github.event.pull_request.head.repo.full_name }} ref: ${{ github.event.pull_request.head.ref }} - name: Installing node_modules run: | npm install - + - name: Build GitHub Action run: npm run build - uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - - - uses: ./ + + # Deploys a DACPAC with only a table to server + - name: Tests DACPAC Action + uses: ./ + with: + server-name: sql-action.database.windows.net + connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }} + dacpac-package: ./__testdata__/sql-action.dacpac + arguments: '/p:DatabaseEdition=Basic' + + # Executes testsql.sql via SQLCMD on server + - name: Tests SQL Action + uses: ./ with: server-name: sql-action.database.windows.net connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }} - sql-file: ./testsql.sql + sql-file: ./__testdata__/testsql.sql diff --git a/__testdata__/sql-action.dacpac b/__testdata__/sql-action.dacpac new file mode 100644 index 0000000000000000000000000000000000000000..c306bc01b548db94b9748d1ed0fb75175082d32c GIT binary patch literal 2287 zcmZ{lX*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DAWK-*QkITkX`*yQY;I#G<$Mm@AXn8l0=0j7yoE*IPtwjy^(`oN* z{Oo)gbc^=vj!@1E8tmJ1%rg6V4!xQV0-D|AdH?Fn%uzygk{|@_|xunXf|rz13n}ApCxEi5-1?O#5{GT2XoHm&`!ZDzl|2 z5YUB9y{lgxI7l;Ef&9Hy%OxZ9JIrmWV-|#2j)p;j*F6KTyIMyCdt#h_ub0AY1k)tE z$#ui;k8(JRxR1X?2GQB`b>XrW;<_U6hoCz%f~tg_V%qmr@?69`IlX(7U5lWig6uj2 z*A3*hKna`bIL5@8nk(C#67?~jI&@+yhaQs>dkbQnF*cGzoI+QX zJhlMUb=EDF!l4fv+T2zpMm?8~E3%$zp!=1Qo2QngkO&})0O0@s_Dm7~b^i1BAH)tO z!yg93G}wWhI0zr~;vaa73IB2CLGIwR|8T0D|8w?81Utv?CN}0>X1-sUZ2-W(0Xp*f A;{X5v literal 0 HcmV?d00001 diff --git a/__testdata__/testsql.sql b/__testdata__/testsql.sql new file mode 100644 index 00000000..14f654c2 --- /dev/null +++ b/__testdata__/testsql.sql @@ -0,0 +1,7 @@ +-- This script is used by pr-check.yml to test the SQLCMD action + +-- This should successfully insert data into the table created in the DACPAC step +INSERT INTO Table1 VALUES(1, 'test'); + +-- Cleanup test database afterwards +DROP DATABASE sql-action; \ No newline at end of file diff --git a/testsql.sql b/testsql.sql deleted file mode 100644 index c8aee4ce..00000000 --- a/testsql.sql +++ /dev/null @@ -1,3 +0,0 @@ -EXEC sp_databases - -SELECT GETDATE(); From 998da415f0d516f4e5de8c8b436e345825d72281 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 4 Jan 2022 13:32:49 -0800 Subject: [PATCH 02/11] Escape database name --- .github/workflows/pr-check.yml | 1 - __testdata__/testsql.sql | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 3f55ea4e..265fe3b0 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -38,7 +38,6 @@ jobs: server-name: sql-action.database.windows.net connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }} dacpac-package: ./__testdata__/sql-action.dacpac - arguments: '/p:DatabaseEdition=Basic' # Executes testsql.sql via SQLCMD on server - name: Tests SQL Action diff --git a/__testdata__/testsql.sql b/__testdata__/testsql.sql index 14f654c2..e805f197 100644 --- a/__testdata__/testsql.sql +++ b/__testdata__/testsql.sql @@ -1,7 +1,7 @@ -- This script is used by pr-check.yml to test the SQLCMD action -- This should successfully insert data into the table created in the DACPAC step -INSERT INTO Table1 VALUES(1, 'test'); +INSERT INTO [Table1] VALUES(1, 'test'); -- Cleanup test database afterwards -DROP DATABASE sql-action; \ No newline at end of file +DROP DATABASE [sql-action]; \ No newline at end of file From 782eeccc5e18f83b38eed048a6a79638acb7a849 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 4 Jan 2022 13:54:30 -0800 Subject: [PATCH 03/11] Truncate table instead of dropping DB --- __testdata__/testsql.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/__testdata__/testsql.sql b/__testdata__/testsql.sql index e805f197..951ee9b2 100644 --- a/__testdata__/testsql.sql +++ b/__testdata__/testsql.sql @@ -3,5 +3,5 @@ -- This should successfully insert data into the table created in the DACPAC step INSERT INTO [Table1] VALUES(1, 'test'); --- Cleanup test database afterwards -DROP DATABASE [sql-action]; \ No newline at end of file +-- Cleanup afterwards +TRUNCATE TABLE [Table1]; \ No newline at end of file From 1acc9bf34c9501a7e4ceac73dadba3c0bdd16b1c Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 4 Jan 2022 14:16:08 -0800 Subject: [PATCH 04/11] Cleanup --- .github/workflows/pr-check.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 265fe3b0..be1f9213 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -21,26 +21,26 @@ jobs: ref: ${{ github.event.pull_request.head.ref }} - name: Installing node_modules - run: | - npm install + run: npm install - name: Build GitHub Action run: npm run build - - uses: azure/login@v1 + - name: Azure Login + uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - # Deploys a DACPAC with only a table to server - - name: Tests DACPAC Action + # Deploy a DACPAC with only a table to server + - name: Test DACPAC Action uses: ./ with: server-name: sql-action.database.windows.net connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }} dacpac-package: ./__testdata__/sql-action.dacpac - # Executes testsql.sql via SQLCMD on server - - name: Tests SQL Action + # Execute testsql.sql via SQLCMD on server + - name: Test SQL Action uses: ./ with: server-name: sql-action.database.windows.net From 172d39cfc18e602d29dd65e7df68adfa03eb5621 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 11 Jan 2022 09:42:45 -0800 Subject: [PATCH 05/11] Set dbName at runtime, drop afterwards --- .github/workflows/pr-check.yml | 11 +++++++---- __testdata__/testsql.sql | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index be1f9213..339bc505 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -13,6 +13,10 @@ jobs: strategy: matrix: os: [windows-latest, ubuntu-latest] + env: + testDb: 'SqlActionTest-${{ matrix.os }}-${{ env.GITHUB_RUN_ID }}' + connectionString: 'Server=${{ secrets.AZURE_TEST_SERVER_NAME }};Database=${{ env.testDb }};User ID=${{ secrets.AZURE_TEST_SQL_USER }};Password=${{ secrets.AZURE_TEST_SQL_PASSWORD }};Persist Security Info=False;Encrypt=True;Connection Timeout=30;' + steps: - name: Checkout from PR branch uses: actions/checkout@v2 @@ -35,14 +39,13 @@ jobs: - name: Test DACPAC Action uses: ./ with: - server-name: sql-action.database.windows.net - connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }} + connection-string: ${{ env.connectionString }} dacpac-package: ./__testdata__/sql-action.dacpac # Execute testsql.sql via SQLCMD on server - name: Test SQL Action uses: ./ with: - server-name: sql-action.database.windows.net - connection-string: ${{ secrets.AZURE_SQL_CONNECTION_STRING }} + connection-string: ${{ env.connectionString }} sql-file: ./__testdata__/testsql.sql + arguments: '-v DbName="${{ env.testDb }}"' diff --git a/__testdata__/testsql.sql b/__testdata__/testsql.sql index 951ee9b2..5f4ad590 100644 --- a/__testdata__/testsql.sql +++ b/__testdata__/testsql.sql @@ -3,5 +3,5 @@ -- This should successfully insert data into the table created in the DACPAC step INSERT INTO [Table1] VALUES(1, 'test'); --- Cleanup afterwards -TRUNCATE TABLE [Table1]; \ No newline at end of file +-- Cleanup afterwards, DbName will be set at runtime +DROP DATABASE [$(DbName)]; \ No newline at end of file From 9ba11ef7512c99f0a32371c4114d6cde5c182b65 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 11 Jan 2022 09:49:22 -0800 Subject: [PATCH 06/11] Fix pr-check.yml --- .github/workflows/pr-check.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 339bc505..58e95203 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -14,8 +14,8 @@ jobs: matrix: os: [windows-latest, ubuntu-latest] env: - testDb: 'SqlActionTest-${{ matrix.os }}-${{ env.GITHUB_RUN_ID }}' - connectionString: 'Server=${{ secrets.AZURE_TEST_SERVER_NAME }};Database=${{ env.testDb }};User ID=${{ secrets.AZURE_TEST_SQL_USER }};Password=${{ secrets.AZURE_TEST_SQL_PASSWORD }};Persist Security Info=False;Encrypt=True;Connection Timeout=30;' + TEST_DB: 'SqlActionTest-${{ matrix.os }}' + CONNECTION_STRING: 'Server=${{ secrets.AZURE_TEST_SERVER_NAME }};Database=${{ env.testDb }};User ID=${{ secrets.AZURE_TEST_SQL_USER }};Password=${{ secrets.AZURE_TEST_SQL_PASSWORD }};Persist Security Info=False;Encrypt=True;Connection Timeout=30;' steps: - name: Checkout from PR branch @@ -39,13 +39,13 @@ jobs: - name: Test DACPAC Action uses: ./ with: - connection-string: ${{ env.connectionString }} + connection-string: ${{ env.CONNECTION_STRING }} dacpac-package: ./__testdata__/sql-action.dacpac # Execute testsql.sql via SQLCMD on server - name: Test SQL Action uses: ./ with: - connection-string: ${{ env.connectionString }} + connection-string: ${{ env.CONNECTION_STRING }} sql-file: ./__testdata__/testsql.sql - arguments: '-v DbName="${{ env.testDb }}"' + arguments: '-v DbName="${{ env.TEST_DB }}"' From c73bd5c3890abc6e434efc1a13d791ccd94172c0 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 11 Jan 2022 10:14:27 -0800 Subject: [PATCH 07/11] Fix pr-check.yml --- .github/workflows/pr-check.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 58e95203..3364eb9f 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -15,7 +15,6 @@ jobs: os: [windows-latest, ubuntu-latest] env: TEST_DB: 'SqlActionTest-${{ matrix.os }}' - CONNECTION_STRING: 'Server=${{ secrets.AZURE_TEST_SERVER_NAME }};Database=${{ env.testDb }};User ID=${{ secrets.AZURE_TEST_SQL_USER }};Password=${{ secrets.AZURE_TEST_SQL_PASSWORD }};Persist Security Info=False;Encrypt=True;Connection Timeout=30;' steps: - name: Checkout from PR branch @@ -39,13 +38,13 @@ jobs: - name: Test DACPAC Action uses: ./ with: - connection-string: ${{ env.CONNECTION_STRING }} + connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }} Database=${{ env.TEST_DB }};' dacpac-package: ./__testdata__/sql-action.dacpac # Execute testsql.sql via SQLCMD on server - name: Test SQL Action uses: ./ with: - connection-string: ${{ env.CONNECTION_STRING }} + connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }} Database=${{ env.TEST_DB }};' sql-file: ./__testdata__/testsql.sql arguments: '-v DbName="${{ env.TEST_DB }}"' From c88f45e415d12af1503c197e3620baa11823b3f6 Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 11 Jan 2022 10:20:00 -0800 Subject: [PATCH 08/11] Use Initial Catalog instead of Database --- .github/workflows/pr-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 3364eb9f..ad183e83 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -38,13 +38,13 @@ jobs: - name: Test DACPAC Action uses: ./ with: - connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }} Database=${{ env.TEST_DB }};' + connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};' dacpac-package: ./__testdata__/sql-action.dacpac # Execute testsql.sql via SQLCMD on server - name: Test SQL Action uses: ./ with: - connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }} Database=${{ env.TEST_DB }};' + connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};' sql-file: ./__testdata__/testsql.sql arguments: '-v DbName="${{ env.TEST_DB }}"' From 94ecdf460da754bcf91c95906d931b483339855f Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 11 Jan 2022 10:36:09 -0800 Subject: [PATCH 09/11] Use master DB for SQLCMD action --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index ad183e83..efa89d29 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -45,6 +45,6 @@ jobs: - name: Test SQL Action uses: ./ with: - connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};' + connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=master;' sql-file: ./__testdata__/testsql.sql arguments: '-v DbName="${{ env.TEST_DB }}"' From 523c0a3a3d7b03ee08e03293a6d1312e33a5290c Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 11 Jan 2022 10:44:16 -0800 Subject: [PATCH 10/11] Separate DB cleanup to its own script --- .github/workflows/pr-check.yml | 8 +++++++- __testdata__/cleanup.sql | 2 ++ __testdata__/testsql.sql | 5 +---- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 __testdata__/cleanup.sql diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index efa89d29..389bd012 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -45,6 +45,12 @@ jobs: - name: Test SQL Action uses: ./ with: - connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=master;' + connection-string: '${{ secrets.AZURE_SQL_CONNECTION_STRING_NO_DATABASE }}Initial Catalog=${{ env.TEST_DB }};' sql-file: ./__testdata__/testsql.sql + + - name: Cleanup Test Database + 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 }}"' diff --git a/__testdata__/cleanup.sql b/__testdata__/cleanup.sql new file mode 100644 index 00000000..cf6e9590 --- /dev/null +++ b/__testdata__/cleanup.sql @@ -0,0 +1,2 @@ +-- This script is used by pr-check.yml to cleanup test database after each run, DbName will be set at runtime +DROP DATABASE [$(DbName)]; \ No newline at end of file diff --git a/__testdata__/testsql.sql b/__testdata__/testsql.sql index 5f4ad590..df96ab87 100644 --- a/__testdata__/testsql.sql +++ b/__testdata__/testsql.sql @@ -1,7 +1,4 @@ -- This script is used by pr-check.yml to test the SQLCMD action -- This should successfully insert data into the table created in the DACPAC step -INSERT INTO [Table1] VALUES(1, 'test'); - --- Cleanup afterwards, DbName will be set at runtime -DROP DATABASE [$(DbName)]; \ No newline at end of file +INSERT INTO [Table1] VALUES(1, 'test'); \ No newline at end of file From 326de244d959122e2275838dd8210609b942501a Mon Sep 17 00:00:00 2001 From: Zi Chen Date: Tue, 22 Feb 2022 09:50:02 -0800 Subject: [PATCH 11/11] Use single quotes on pr-check run condition --- .github/workflows/pr-check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 82233e37..99288c4e 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -7,7 +7,7 @@ on: jobs: deploy: - if: (github.event == "pull_request" && github.event.pull_request.head.repo == github.repository.full_name) || (github.event == "pull_request_target" && github.event.pull_request.head.repo != github.repository.full_name) + if: (github.event == 'pull_request' && github.event.pull_request.head.repo == github.repository.full_name) || (github.event == 'pull_request_target' && github.event.pull_request.head.repo != github.repository.full_name) environment: Automation test runs-on: ${{ matrix.os }} strategy: