diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index c593f235..99288c4e 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -7,33 +7,50 @@ 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: matrix: os: [windows-latest, ubuntu-latest] + env: + TEST_DB: 'SqlActionTest-${{ matrix.os }}' + 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 - + 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 }} - - - uses: ./ + + # 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 }} - sql-file: ./testsql.sql - \ No newline at end of file + 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 }}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__/sql-action.dacpac b/__testdata__/sql-action.dacpac new file mode 100644 index 00000000..c306bc01 Binary files /dev/null and b/__testdata__/sql-action.dacpac differ diff --git a/__testdata__/testsql.sql b/__testdata__/testsql.sql new file mode 100644 index 00000000..df96ab87 --- /dev/null +++ b/__testdata__/testsql.sql @@ -0,0 +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'); \ 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();