Skip to content

Performing validation with a local docker instance instead of Azure DB #472

Performing validation with a local docker instance instead of Azure DB

Performing validation with a local docker instance instead of Azure DB #472

Workflow file for this run

name: pr-check
# Tests PR code against a local SQL Server container so no Azure credentials are required.
# This workflow uses the pull_request trigger (not pull_request_target), so fork PRs run
# with no secrets and no elevated permissions.
on:
pull_request:
permissions: {}
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
checks: write
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
env:
ACCEPT_EULA: Y
# Bootstrap password - rotated to a random value in the first step
MSSQL_SA_PASSWORD: Bootstrap1!
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'Bootstrap1!' -C -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 5s
--health-retries 10
env:
TEST_DB: SqlActionTest
# Password is appended after rotation in the first step; composed into connection strings below
BASE_CS: 'Server=localhost;User ID=sa;TrustServerCertificate=True;'
steps:
- name: Find sqlcmd
run: |
echo "=== which sqlcmd ===" && which sqlcmd || echo "not on PATH"
echo "=== find mssql-tools ===" && find /opt -name sqlcmd 2>/dev/null || echo "not found in /opt"
echo "=== sqlcmd in container ===" && docker exec $(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest) find / -name sqlcmd 2>/dev/null | head -5
- name: Rotate SA password
run: |
SA_PASSWORD="$(openssl rand -base64 18 | tr -d '/+=')Aa1!"
CONTAINER=$(docker ps -q --filter ancestor=mcr.microsoft.com/mssql/server:2022-latest)
docker exec "$CONTAINER" /opt/mssql-tools18/bin/sqlcmd \
-S localhost -U sa -P 'Bootstrap1!' -C \
-Q "ALTER LOGIN sa WITH PASSWORD='${SA_PASSWORD}'"
echo "SA_PASSWORD=${SA_PASSWORD}" >> "$GITHUB_ENV"
- name: Checkout PR
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Build GitHub Action
run: npm ci --ignore-scripts && npm run build
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Install SqlPackage
run: dotnet tool install -g microsoft.sqlpackage
# Deploy a DACPAC with only a table to server (sqlpackage creates the DB if needed)
- name: Test DACPAC Action
uses: ./
with:
connection-string: '${{ env.BASE_CS }}Password=${{ env.SA_PASSWORD }};Initial Catalog=${{ env.TEST_DB }};'
path: ./__testdata__/sql-action.dacpac
action: 'publish'
skip-firewall-check: true
# Build and publish sqlproj that should create a new view
- name: Test Build and Publish
uses: ./
with:
connection-string: '${{ env.BASE_CS }}Password=${{ env.SA_PASSWORD }};Initial Catalog=${{ env.TEST_DB }};'
path: ./__testdata__/TestProject/sql-action.sqlproj
action: 'publish'
skip-firewall-check: true
# Execute testsql.sql via script action on server
- name: Test SQL Action
uses: ./
with:
connection-string: '${{ env.BASE_CS }}Password=${{ env.SA_PASSWORD }};Initial Catalog=${{ env.TEST_DB }};'
path: ./__testdata__/testsql.sql
skip-firewall-check: true
- name: Cleanup Test Database
if: always()
uses: ./
with:
connection-string: '${{ env.BASE_CS }}Password=${{ env.SA_PASSWORD }};Initial Catalog=master;'
path: ./__testdata__/cleanup.sql
arguments: '-v DbName="${{ env.TEST_DB }}"'
skip-firewall-check: true