diff --git a/.azure/pipelines/azure-pipelines-discordplugin-build.yml b/.azure/pipelines/azure-pipelines-discordplugin-build.yml new file mode 100644 index 00000000..2ec5be2a --- /dev/null +++ b/.azure/pipelines/azure-pipelines-discordplugin-build.yml @@ -0,0 +1,138 @@ +parameters: +- name: ApplicationName + type: string +- name: SolutionFile + type: string +- name: ProjectFile + type: string +- name: PublishFolder + type: string +- name: BuildConfiguration + type: string + default: Release +- name: BuildPlatform + type: string + default: AnyCPU + +stages: +- stage: build + displayName: Build and Publish + + jobs: + - job: build + displayName: Build and Publish + workspace: + clean: all + + steps: + - task: PowerShell@2 + displayName: Write Build Parameters + condition: contains(variables['system.debug'], 'true') + inputs: + targetType: inline + script: | + Write-Host "ApplicationName: ${{parameters.ApplicationName}}" + Write-Host "SolutionFile: ${{parameters.SolutionFile}}" + Write-Host "ProjectFile: ${{parameters.ProjectFile}}" + Write-Host "PublishFolder: ${{parameters.PublishFolder}}" + Write-Host "BuildConfiguration: ${{parameters.BuildConfiguration}}" + Write-Host "BuildPlatform: ${{parameters.BuildPlatform}}" + pwsh: true + + - template: create-agent-capabilities-variables.yml@self + + - task: PowerShell@2 + displayName: Write Environment Variables + condition: contains(variables['system.debug'], 'true') + inputs: + targetType: inline + script: '(gci env:*).GetEnumerator() | Sort-Object Name | Out-String' + pwsh: true + + - task: NuGetToolInstaller@1 + displayName: Install NuGet 4.4.1 + inputs: + versionSpec: '4.4.1' + + - task: NuGetCommand@2 + displayName: NuGet Restore + inputs: + restoreSolution: '${{parameters.SolutionFile}}' + + - template: update-semantic-versioning-in-assembyinfo-files.yml@self + parameters: + ApplicationName: ${{parameters.ApplicationName}} + PathToSearch: '$(Build.SourcesDirectory)/src' + + - task: VSBuild@1 + displayName: Build ${{parameters.ApplicationName}} Project + inputs: + solution: '${{parameters.ProjectFile}}' + msbuildArgs: '/t:publish /p:PublishDir="$(Build.BinariesDirectory)"' + platform: '${{parameters.BuildPlatform}}' + configuration: '${{parameters.BuildConfiguration}}' + clean: true + + - task: PowerShell@2 + displayName: Clean-up Published Files + env: + BUILD_BINARIESDIRECTORY: $(Build.BinariesDirectory) + inputs: + targetType: inline + script: | + # Remove unwanted files + Remove-Item -Path "$env:BUILD_BINARIESDIRECTORY/ServerManager.Plugin.Common.dll" -Force -ErrorAction Ignore + Remove-Item -Path "$env:BUILD_BINARIESDIRECTORY/*.config" -Force -ErrorAction Ignore + pwsh: true + + - task: CopyFiles@2 + displayName: Copy Artifact Files + inputs: + SourceFolder: '$(Build.SourcesDirectory)' + Contents: | + src/${{parameters.ApplicationName}}/VersionFeed.xml + src/${{parameters.ApplicationName}}/VersionFeedBeta.xml + src/${{parameters.ApplicationName}}/Globalization/en-US/en-US.xaml + TargetFolder: '$(Build.ArtifactStagingDirectory)' + OverWrite: true + flattenFolders: true + preserveTimestamp: true + + - task: PowerShell@2 + displayName: Archive Binary Files + env: + BUILD_BUILDNUMBER: $(Build.BuildNumber) + BUILD_ARTIFACTSTAGINGDIRECTORY: $(Build.ArtifactStagingDirectory) + BUILD_BINARIESDIRECTORY: $(Build.BinariesDirectory) + inputs: + targetType: inline + script: | + $appVersion = $env:BUILD_BUILDNUMBER + $appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.')) + $appVersionWithUnderscores = $appVersion.Replace('.', '_') + $applicationFolderName = "${{parameters.ApplicationName}}_$($appVersionWithUnderscores)" + + $sourcePath = "$env:BUILD_BINARIESDIRECTORY/Application Files/$applicationFolderName" + $zipFile = "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/${{parameters.ApplicationName}}_$($appVersionShort).zip" + + Add-Type -Assembly System.IO.Compression.FileSystem + $compressionLevel = [System.IO.Compression.CompressionLevel]::Optimal + [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcePath, $zipFile, $compressionLevel, $false) + + Copy-Item -Path $zipFile -Destination "$env:BUILD_ARTIFACTSTAGINGDIRECTORY/latest.zip" -Force + pwsh: true + + - task: PublishBuildArtifacts@1 + displayName: Publish Artifacts + enabled: true + inputs: + PathtoPublish: '$(Build.ArtifactStagingDirectory)' + ArtifactName: '${{parameters.PublishFolder}}' + + - template: clean-agent-folders.yml@self + parameters: + CleanArtifactsFolder: false + CleanBinariesFolder: false + CleanSourcesFolder: false + CleanPublishFolder: false + PublishFolder: ${{parameters.PublishFolder}} diff --git a/.azure/pipelines/azure-pipelines-discordplugin-deploy.yml b/.azure/pipelines/azure-pipelines-discordplugin-deploy.yml new file mode 100644 index 00000000..ac47a05a --- /dev/null +++ b/.azure/pipelines/azure-pipelines-discordplugin-deploy.yml @@ -0,0 +1,202 @@ +parameters: +- name: DeploymentType + displayName: Type of Deployment Stage + type: string + values: + - Beta + - Production +- name: DependsOn + displayName: Depends On + type: string +- name: ApplicationName + type: string +- name: PublishFolder + type: string +- name: RepositoryFolder + type: string +- name: GitEmail + type: string +- name: GitUsername + type: string + +stages: +- stage: deploy${{parameters.DeploymentType}} + displayName: ${{parameters.DeploymentType}} + lockBehavior: runLatest + condition: and(succeeded(), eq(variables['build.sourceBranch'], 'refs/heads/source')) + dependsOn: + - build + - ${{ if ne(parameters.DependsOn, 'build') }}: + - deploy${{parameters.DependsOn}} + + jobs: + - deployment: deploy${{parameters.DeploymentType}} + displayName: Deploy ${{parameters.DeploymentType}} + environment: github-servermanager-${{ lower(parameters.DeploymentType) }} + workspace: + clean: all + variables: + - name: NewVersionBuild + value: $(VersionBuild) + - name: NewVersionRevision + value: $(VersionRevision) + + strategy: + runOnce: + deploy: + steps: + - task: PowerShell@2 + displayName: Write Deployment Parameters + condition: contains(variables['system.debug'], 'true') + inputs: + targetType: inline + script: | + Write-Host "DeploymentType: ${{parameters.DeploymentType}}" + Write-Host "DependsOn: ${{parameters.DependsOn}}" + Write-Host "ApplicationName: ${{parameters.ApplicationName}}" + Write-Host "PublishFolder: ${{parameters.PublishFolder}}" + Write-Host "RepositoryFolder: ${{parameters.RepositoryFolder}}" + pwsh: true + + - task: PowerShell@2 + displayName: Write Environment Variables + condition: contains(variables['system.debug'], 'true') + inputs: + targetType: inline + script: '(gci env:*).GetEnumerator() | Sort-Object Name | Out-String' + pwsh: true + + - checkout: MasterRepo + persistCredentials: true + + - task: PowerShell@2 + displayName: Pull Master Repository Files + env: + DEPLOY_BUILDNUMBER: $(Build.BuildNumber) + DEPLOY_SOURCESDIRECTORY: $(Build.SourcesDirectory) + inputs: + targetType: inline + script: | + Write-Host "Setting up the global configuration" + git config --global user.email "${{parameters.GitEmail}}" + git config --global user.name "${{parameters.GitUsername}}" + + Write-Host "Performing Git Checkout" + git checkout -b master + + Write-Host "Performing Git Fetch" + git fetch + + Write-Host "Performing Git Branch" + git branch --set-upstream-to=origin/master master + + Write-Host "Performing Git Pull" + git pull --force + pwsh: true + workingDirectory: '$(Build.SourcesDirectory)' + + - task: PowerShell@2 + displayName: Copy ${{parameters.DeploymentType}} Files + env: + DEPLOY_BUILDNUMBER: $(Build.BuildNumber) + DEPLOY_PUBLISHDIRECTORY: "$(Agent.BuildDirectory)/${{parameters.PublishFolder}}" + DEPLOY_REPODIRECTORY: "$(Build.SourcesDirectory)/${{parameters.RepositoryFolder}}" + inputs: + targetType: inline + script: | + $appVersion = $env:DEPLOY_BUILDNUMBER + $appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.')) + + if (!(Test-Path $env:DEPLOY_PUBLISHDIRECTORY)) { + throw "Source directory does not exist or could not be found ($env:DEPLOY_PUBLISHDIRECTORY)" + } + if (!(Test-Path $env:DEPLOY_REPODIRECTORY)) { + New-Item -Path "$env:DEPLOY_REPODIRECTORY" -ItemType Directory -Force + } + + # copy common files + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\en-US.xaml" -Destination "$env:DEPLOY_REPODIRECTORY" -Force + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.zip" -Destination "$env:DEPLOY_REPODIRECTORY" -Force + + # copy beta specific files + if ('${{parameters.DeploymentType}}' -eq 'Beta') { + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latestBeta.txt" -Destination "$env:DEPLOY_REPODIRECTORY\latest.txt" -Force + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\VersionFeedBeta.xml" -Destination "$env:DEPLOY_REPODIRECTORY\VersionFeed.xml" -Force + } + + # copy production specific files + if ('${{parameters.DeploymentType}}' -eq 'Production') { + $applicationFilenamePrefix = "${{parameters.ApplicationName}}_$appVersionShort" + + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\$applicationFilenamePrefix.zip" -Destination "$env:DEPLOY_REPODIRECTORY" -Force + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\latest.txt" -Destination "$env:DEPLOY_REPODIRECTORY" -Force + Copy-Item -Path "$env:DEPLOY_PUBLISHDIRECTORY\VersionFeed.xml" -Destination "$env:DEPLOY_REPODIRECTORY" -Force + } + pwsh: true + + - task: PowerShell@2 + displayName: Commit ${{parameters.DeploymentType}} Files + env: + DEPLOY_BUILDNUMBER: $(Build.BuildNumber) + DEPLOY_SOURCESDIRECTORY: $(Build.SourcesDirectory) + inputs: + targetType: inline + script: | + $appVersion = $env:DEPLOY_BUILDNUMBER + $appVersionShort = $appVersion.Substring(0, $appVersion.LastIndexOf('.')) + + Write-Host "Setting up the global configuration" + git config --global user.email "${{parameters.GitEmail}}" + git config --global user.name "${{parameters.GitUsername}}" + + Write-Host "Performing Git Add" + git add -A + + Write-Host "Performing Git Commit" + if ('${{parameters.DeploymentType}}' -eq 'Beta') { + git commit -m "${{parameters.ApplicationName}} Beta $appVersion" + } + + if ('${{parameters.DeploymentType}}' -eq 'Production') { + git commit -m "${{parameters.ApplicationName}} $appVersionShort" + } + + Write-Host "Performing Git Push" + git push --set-upstream origin master --porcelain --force + pwsh: true + workingDirectory: '$(Build.SourcesDirectory)' + + - ${{ if eq(parameters.DeploymentType, 'Beta') }}: + - powershell: | + [int]$oldValue = $(NewVersionRevision) + [int]$newValue = $oldValue + 1 + Write-Host "##vso[task.setvariable variable=NewVersionRevision;]$newValue" + displayName: Set New Pipeline Version Variable Values + + - ${{ if eq(parameters.DeploymentType, 'Production') }}: + - powershell: | + [int]$oldValue = $(NewVersionBuild) + [int]$newValue = $oldValue + 1 + Write-Host "##vso[task.setvariable variable=NewVersionBuild;]$newValue" + + [int]$newValue = 1 + Write-Host "##vso[task.setvariable variable=NewVersionRevision;]$newValue" + displayName: Set New Pipeline Version Variable Values + + - template: update-pipeline-variable.yml@self + parameters: + VariableName: 'VersionBuild' + VariableValue: $(NewVersionBuild) + + - template: update-pipeline-variable.yml@self + parameters: + VariableName: 'VersionRevision' + VariableValue: $(NewVersionRevision) + + - template: clean-agent-folders.yml@self + parameters: + CleanArtifactsFolder: true + CleanBinariesFolder: true + CleanSourcesFolder: true + CleanPublishFolder: true + PublishFolder: $(PublishFolder) diff --git a/.azure/pipelines/azure-pipelines-discordplugin.yml b/.azure/pipelines/azure-pipelines-discordplugin.yml new file mode 100644 index 00000000..2c196b77 --- /dev/null +++ b/.azure/pipelines/azure-pipelines-discordplugin.yml @@ -0,0 +1,58 @@ +name: $(VersionMajor).$(VersionMinor).$(VersionBuild).$(VersionRevision) + +#trigger: +# branches: +# include: +# - source +# paths: +# include: +# - src + +pool: +# vmImage: windows-latest + demands: InnoSetup + +resources: + repositories: + - repository: MasterRepo + type: GitHub + endpoint: Bletch1971 + name: Bletch1971/ServerManagers + +variables: +- name: ApplicationName + value: $(Build.DefinitionName) +- name: SolutionFile + value: 'src/Server-Managers.sln' +- name: ProjectFile + value: 'src/$(ApplicationName)/$(ApplicationName).csproj' + +stages: +- template: azure-pipelines-discordplugin-build.yml@self + parameters: + ApplicationName: $(ApplicationName) + SolutionFile: $(SolutionFile) + ProjectFile: $(ProjectFile) + BuildConfiguration: $(BuildConfiguration) + BuildPlatform: $(BuildPlatform) + PublishFolder: $(PublishFolder) + +- template: azure-pipelines-discordplugin-deploy.yml@self + parameters: + DeploymentType: Beta + DependsOn: build + ApplicationName: $(ApplicationName) + PublishFolder: $(PublishFolder) + RepositoryFolder: $(RepositoryFolderBeta) + GitEmail: $(GitEmail) + GitUsername: $(GitUsername) + +- template: azure-pipelines-discordplugin-deploy.yml@self + parameters: + DeploymentType: Production + DependsOn: Beta + ApplicationName: $(ApplicationName) + PublishFolder: $(PublishFolder) + RepositoryFolder: $(RepositoryFolderProduction) + GitEmail: $(GitEmail) + GitUsername: $(GitUsername)