SQL-MI-CICD #23
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SQL-MI-CICD | |
on: | |
push: | |
branches: | |
- "NA" | |
workflow_dispatch: | |
env: | |
SQL_PROJECT_NAME: DemoSqlProj | |
SQL_ARTIFACT_NAME: SqlDb | |
jobs: | |
build: | |
name: "Build" | |
runs-on: self-hosted | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Dotnet needs to be preinstalled on the runner | |
- name: Build DACPAC | |
run: dotnet build "data/${{ env.SQL_PROJECT_NAME }}/${{ env.SQL_PROJECT_NAME }}.sqlproj" --configuration Release | |
- name: Upload artifact | |
uses: actions/upload-artifact@v3.1.2 | |
with: | |
name: ${{ env.SQL_ARTIFACT_NAME }} | |
path: data/${{ env.SQL_PROJECT_NAME }}/bin/Release | |
deployDev: | |
needs: build | |
name: Deploy | |
runs-on: self-hosted | |
steps: | |
# Azure CLI needs to be preinstalled on the runner | |
- name: "Login via Azure CLI" | |
uses: azure/login@v1 | |
with: | |
creds: ${{ secrets.AZURE_SP_CREDENTIALS }} | |
- name: Download Dacpac Artifact | |
uses: actions/download-artifact@v3.0.2 | |
with: | |
name: ${{ env.SQL_ARTIFACT_NAME }} | |
- name: "Get SQL MI FQDN" | |
# shell: pwsh | |
run: | | |
$resourceGroup = "mi-${{ vars.RESOURCE_NAME_ROOT }}-rg" | |
$sqlMiName = "mi-${{ vars.RESOURCE_NAME_ROOT }}-mssql" | |
$fqdn = $(az sql mi show --name $sqlMiName --resource-group $resourceGroup --query fullyQualifiedDomainName).Replace("`"","") | |
echo "SQL_MI_HOST=$fqdn" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
# SqlPackage needs to be preinstalled on the runner | |
# vars.SQL_MI_FQDN needs to be set as a repository variable after the MI is created with Terraform | |
- name: Deploy DACPAC to SQL Managed Instance | |
run: | | |
sqlpackage /Action:Publish /SourceFile:"./${{ env.SQL_PROJECT_NAME }}.dacpac" /TargetUser:${{ secrets.SQL_ADMIN_USER }} /TargetPassword:${{ secrets.SQL_ADMIN_PASSWORD }} /TargetServerName:${{ env.SQL_MI_HOST }} /TargetDatabaseName:${{ vars.SQL_INITIAL_CATALOG }} | |
- name: Clean up runner | |
run: rm -Recurse ${{github.workspace}}\* |