Skip to content

Add redeploy command #1301

Add redeploy command

Add redeploy command #1301

Workflow file for this run

# Name of the workflow
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request events
on:
push:
branches: [ master, release/*, feature/* ]
paths-ignore:
- '**/*.md'
pull_request:
branches: [ master ]
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# Run the build first
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
submodules: 'true' # need to check out the SqlTools submodule to build successfully.
# Install .NET SDK's for 6.0 and 8.0
- name: Setup dotnet 6.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
- name: Setup dotnet 8.0
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
# Install Nerdbank.GitVersioning
- name: install nbgv
run: dotnet tool install --tool-path . nbgv
# Set version
- name: set version
run: ./nbgv cloud -p ./src/MSBuild.Sdk.SqlProj/ --all-vars
# Build command line tool
- name: dotnet build DacpacTool
run: dotnet build ./src/DacpacTool/DacpacTool.csproj -c Release
# Run tests for command line tool
- name: dotnet test
run: dotnet test ./test/DacpacTool.Tests/DacpacTool.Tests.csproj -c Release
# Run build for SDK package
- name: dotnet build SDK
run: dotnet build ./src/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj.csproj -c Release
# Ensure that test project builds
- name: dotnet build TestProject
run: dotnet build ./test/TestProject/TestProject.csproj -c Release
# Package SDK
- name: dotnet pack SDK
run: dotnet pack -c Release src/MSBuild.Sdk.SqlProj/MSBuild.Sdk.SqlProj.csproj
# Package Aspire integration
- name: dotnet pack Aspire
run: dotnet pack -c Release src/MSBuild.Sdk.SqlProj.Aspire/MSBuild.Sdk.SqlProj.Aspire.csproj
# Upload SDK package
- name: upload SDK
uses: actions/upload-artifact@v4
with:
name: sdk-package
path: ./src/MSBuild.Sdk.SqlProj/bin/Release/
# Upload Aspire package
- name: upload Aspire
uses: actions/upload-artifact@v4
with:
name: aspire-package
path: ./src/MSBuild.Sdk.SqlProj.Aspire/bin/Release/
# Package TestProject
- name: dotnet pack TestProject
run: dotnet pack -c Release ./test/TestProject/TestProject.csproj
# Upload TestProject package
- name: upload TestProject
uses: actions/upload-artifact@v4
with:
name: test-package
path: ./test/TestProject/bin/Release/
# Replace tokens
- uses: cschleiden/replace-tokens@v1
name: replace tokens
with:
files: 'src/MSBuild.Sdk.SqlProj.Templates/templates/sqlproj/sqlproj.csproj'
# Package templates
- name: dotnet pack templates
run: dotnet pack -c Release src/MSBuild.Sdk.SqlProj.Templates/MSBuild.Sdk.SqlProj.Templates.csproj
# Upload templates package
- name: upload templates
uses: actions/upload-artifact@v4
with:
name: template-package
path: ./src/MSBuild.Sdk.SqlProj.Templates/bin/Release/
# Run tests in parallel
test:
runs-on: ${{ matrix.os }}
needs: build
strategy:
matrix:
os: [ "ubuntu-22.04", "macos-13", "windows-2022" ]
dotnet: [ '6.0.x', '8.0.x' ]
fail-fast: false
steps:
# Fetch sources
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
# Setup .NET SDK
- uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ matrix.dotnet }}
# Install Nerdbank.GitVersioning
- name: install nbgv
run: dotnet tool install --tool-path . nbgv
# Set version
- name: set version
run: ./nbgv cloud -p ./src/MSBuild.Sdk.SqlProj/ --all-vars
id: nbgv
# Replace tokens
- uses: cschleiden/replace-tokens@v1
name: replace tokens
with:
files: 'test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj'
# Download artifact
- name: download-artifact
uses: actions/download-artifact@v4
with:
name: sdk-package
path: test/TestProjectWithSDKRef/nuget-packages
# Download artifact
- name: download-artifact
uses: actions/download-artifact@v4
with:
name: test-package
path: test/TestProjectWithSDKRef/nuget-packages
# Restore packages
- name: dotnet restore
run: dotnet restore ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj --verbosity n
# Build the project using exact version number
- name: build project (exact version / MSBuild resolution)
run: dotnet build ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj /bl /p:DependencyVersion="$Env:NBGV_NuGetPackageVersion" /warnaserror:SQL71502
shell: pwsh
# Build the project using fallback method of resolving version via path
- name: build project (exact version / path resolution)
run: dotnet build ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj /bl /p:DependencyVersion="$Env:NBGV_NuGetPackageVersion" /p:PkgTestProject="" /warnaserror:SQL71502
shell: pwsh
# Upload binary log
- name: upload
uses: actions/upload-artifact@v4
with:
name: binary-log-${{ matrix.os }}-${{ matrix.dotnet }}-exact-version
path: ./msbuild.binlog
# Build the project using single wildcard (i.e. 1.x.x-*)
- name: build project (single floating version)
run: dotnet build ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj /bl /p:DependencyVersion="${Env:NBGV_SimpleVersion}-*" /warnaserror:SQL71502
shell: pwsh
# Build the project using double wildcard (i.e. 1.*-*)
- name: build project (double floating version / dotnet 3)
run: dotnet build ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj /bl /p:DependencyVersion="2.*-*" /warnaserror:SQL71502
shell: pwsh
# Upload dacpac
- name: upload
if: ${{ matrix.os == 'ubuntu-22.04' && matrix.dotnet == '6.0.x' }}
uses: actions/upload-artifact@v4
with:
name: dacpac-package
path: ./test/TestProjectWithSDKRef/bin/Debug/netstandard2.0/
# Upload binary log
- name: upload
uses: actions/upload-artifact@v4
with:
name: binary-log-${{ matrix.os }}-${{ matrix.dotnet }}-floating-version
path: ./msbuild.binlog
# Attempt to deploy the resulting dacpac's to a SQL Server instance running in a container using SqlPackage.exe
deploy-sqlpackage:
runs-on: ubuntu-22.04
needs: test
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: JdMsKZPBBA8kVFXVrj8d
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'JdMsKZPBBA8kVFXVrj8d' -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 3s
--health-retries 10
--health-start-period 10s
steps:
# Download artifacts
- name: download-artifact
uses: actions/download-artifact@v4
with:
name: dacpac-package
path: ~/dacpac-package
# Setup .NET SDK
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
# Install Microsoft.SqlPackage
- name: install microsoft.sqlpackage
run: dotnet tool install --tool-path . microsoft.sqlpackage
# Run sqlpackage
- name: sqlpackage publish
run: >
sqlpackage
/Action:Publish
/SourceFile:$HOME/dacpac-package/TestProjectWithSDKRef.dacpac
/Properties:IncludeCompositeObjects=True
/TargetServerName:localhost
/TargetUser:sa
/TargetPassword:JdMsKZPBBA8kVFXVrj8d
/TargetDatabaseName:TestProjectWithSDKRef
/TargetEncryptConnection:False
# Dump logs of the container if something failed
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
# Attempt to deploy a project to a SQL Server instance running in a container using dotnet publish
deploy-publish:
runs-on: ubuntu-22.04
needs: test
services:
sqlserver:
image: mcr.microsoft.com/mssql/server:2019-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: JdMsKZPBBA8kVFXVrj8d
ports:
- 1433:1433
options: >-
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U sa -P 'JdMsKZPBBA8kVFXVrj8d' -Q 'SELECT 1' || exit 1"
--health-interval 10s
--health-timeout 3s
--health-retries 10
--health-start-period 10s
steps:
# Fetch sources
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
# Download SDK
- name: download-artifact
uses: actions/download-artifact@v4
with:
name: sdk-package
path: test/TestProjectWithSDKRef/nuget-packages
# Download test package
- name: download-artifact
uses: actions/download-artifact@v4
with:
name: test-package
path: test/TestProjectWithSDKRef/nuget-packages
# Setup .NET SDK
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
# Install Nerdbank.GitVersioning
- name: install nbgv
run: dotnet tool install --tool-path . nbgv
# Set version
- name: set version
run: ./nbgv cloud -p ./src/MSBuild.Sdk.SqlProj/ --all-vars
id: nbgv
# Replace tokens
- uses: cschleiden/replace-tokens@v1
name: replace tokens
with:
files: 'test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj'
env:
DependencyVersion: '2.*-*'
# Publish the project
- name: publish project
run: dotnet publish ./test/TestProjectWithSDKRef/TestProjectWithSDKRef.csproj /p:TargetUser=sa /p:TargetPassword=JdMsKZPBBA8kVFXVrj8d /bl /p:DependencyVersion="2.*-*" /warnaserror:SQL71502
# Upload binary log
- name: upload
uses: actions/upload-artifact@v4
with:
name: binary-log-publish
path: ./msbuild.binlog
# Dump logs of the container if something failed
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
# Publish the NuGet package to NuGet.org when building master branch
publish:
runs-on: ubuntu-22.04
if: startsWith(github.ref, 'refs/heads/release/')
needs:
- deploy-sqlpackage
- deploy-publish
steps:
# Setup .NET SDK
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '6.0.x'
# Download SDK package
- name: download-sdk-package
uses: actions/download-artifact@v4
id: download-sdk-package
with:
name: sdk-package
path: ~/nuget-packages
# Download Templates package
- name: download-template-package
uses: actions/download-artifact@v4
id: download-template-package
with:
name: template-package
path: ~/nuget-packages
# Download Aspire package
- name: download-aspire-package
uses: actions/download-artifact@v4
id: download-aspire-package
with:
name: aspire-package
path: ~/nuget-packages
- name: Display structure of downloaded files
run: ls -R
working-directory: ${{steps.download-sdk-package.outputs.download-path}}
# Push
- name: dotnet nuget push
run: dotnet nuget push 'MSBuild.Sdk.SqlProj*.nupkg' -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
working-directory: ${{steps.download-sdk-package.outputs.download-path}}