diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ab13f9efad..d5ee4fcdcf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -70,3 +70,7 @@ jobs: with: name: DisCatSharp path: ./artifacts/ + - name: Restore Tools Packages + run: dotnet restore --no-cache -f -v minimal DisCatSharp.Tools/DisCatSharp.Tools.sln + - name: Build tools + run: dotnet build -c Release -v minimal --no-restore DisCatSharp.Tools/DisCatSharp.Tools.sln \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 03b3d08eae..0bba1101a6 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -48,7 +48,10 @@ jobs: - name: Restore dependencies run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln - name: Build - run: | - dotnet build -c Release -v minimal --no-restore --no-self-contained DisCatSharp.sln + run: dotnet build -c Release -v minimal --no-restore --no-self-contained DisCatSharp.sln + - name: Restore Tools Packages + run: dotnet restore --no-cache -f -v minimal DisCatSharp.Tools/DisCatSharp.Tools.sln + - name: Build tools + run: dotnet build -c Release -v minimal --no-restore DisCatSharp.Tools/DisCatSharp.Tools.sln - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/internal-release.yml b/.github/workflows/internal-release.yml index 806a48f230..8f621edaa7 100644 --- a/.github/workflows/internal-release.yml +++ b/.github/workflows/internal-release.yml @@ -28,7 +28,9 @@ jobs: 8.0.100 7.0.404 - name: Restore dependencies - run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln + run: | + dotnet restore --no-cache -f -v minimal DisCatSharp.sln + dotnet restore --no-cache -f -v minimal DisCatSharp.Tools/DisCatSharp.Tools.sln - name: Set outputs id: vars run: echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT @@ -37,15 +39,32 @@ jobs: run: ./DisCatSharp.Tools/rebuild-lib.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release -VersionSuffix ${{ steps.vars.outputs.sha }} env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + - name: Build tools as pre-release + shell: pwsh + run: ./DisCatSharp.Tools/rebuild-tools.ps1 -ArtifactLocation ./dcs-tools-artifacts -Configuration Release -VersionSuffix ${{ steps.vars.outputs.sha }} + - name: Build attributes as pre-release + shell: pwsh + run: ./DisCatSharp.Tools/rebuild-attributes.ps1 -ArtifactLocation ./dcs-attributes-artifacts -Configuration Release -VersionSuffix ${{ steps.vars.outputs.sha }} - name: Remove invalid packages run: rm *.symbols.* working-directory: ./dcs-artifacts - name: Remove symbol packages run: rm *.snupkg working-directory: ./dcs-artifacts + - name: Remove symbol packages for tools + run: rm *.snupkg + working-directory: ./dcs-tools-artifacts + - name: Remove symbol packages for attributes + run: rm *.snupkg + working-directory: ./dcs-attributes-artifacts - name: Add AITSYS Internal NuGet source run: dotnet nuget add source --name aitsys https://registry.aitsys-infra.tools/nuget/aitsys/index.json --username bytesafe --password ${{ secrets.BYTESAFE }} --store-password-in-clear-text - working-directory: ./dcs-artifacts - - name: Publish to AITSYS Internal Registry + - name: Publish to library to AITSYS Internal Registry run: dotnet nuget push --source aitsys -k ${{ secrets.BYTESAFE }} * working-directory: ./dcs-artifacts + - name: Publish to tools to AITSYS Internal Registry + run: dotnet nuget push --source aitsys -k ${{ secrets.BYTESAFE }} * + working-directory: ./dcs-tools-artifacts + - name: Publish to attributes to AITSYS Internal Registry + run: dotnet nuget push --source aitsys -k ${{ secrets.BYTESAFE }} * + working-directory: ./dcs-attributes-artifacts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 05c1758471..95bf036c2b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -17,6 +17,15 @@ on: required: false type: boolean default: false + packages_to_release: + description: "Packages to release" + required: false + type: choice + options: + - "DisCatSharp" + - "DisCatSharp.Attributes" + - "DisCatSharp.Tools" + env: DOTNET_NOLOGO: true @@ -48,20 +57,43 @@ jobs: dotnet-version: | 8.0.100 7.0.404 - - name: Restore dependencies + - name: Restore dependencies (DisCatSharp) + if: ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp' run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln - - name: Build library as full release + - name: Restore dependencies (DisCatSharp.Attributes) + if: ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp.Attributes' + run: dotnet restore --no-cache -f -v minimal DisCatSharp.Attributes/DisCatSharp.Attributes.csproj + - name: Restore dependencies (DisCatSharp.Tools) + if: ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp.Tools' + run: dotnet restore --no-cache -f -v minimal DisCatSharp.Tools/DisCatSharp.Tools.sln + - name: Build DisCatSharp as full release if: ${{!inputs.release_as_prerelease}} shell: pwsh run: ./DisCatSharp.Tools/rebuild-lib.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} - - name: Build library as pre-release + - name: Build DisCatSharp as pre-release if: ${{inputs.release_as_prerelease}} shell: pwsh run: ./DisCatSharp.Tools/rebuild-lib.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release -VersionSuffix ${{github.event.inputs.version_suffix}} env: SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} + - name: Build DisCatSharp.Attributes as full release + if: ${{!inputs.release_as_prerelease}} && ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp.Attributes' + shell: pwsh + run: ./DisCatSharp.Tools/rebuild-attributes.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release + - name: Build DisCatSharp.Attributes as pre-release + if: ${{inputs.release_as_prerelease}} && ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp.Attributes' + shell: pwsh + run: ./DisCatSharp.Tools/rebuild-attributes.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release -VersionSuffix ${{github.event.inputs.version_suffix}} + - name: Build DisCatSharp.Tools as full release + if: ${{!inputs.release_as_prerelease}} && ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp.Tools' + shell: pwsh + run: ./DisCatSharp.Tools/rebuild-tools.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release + - name: Build DisCatSharp.Tools as pre-release + if: ${{inputs.release_as_prerelease}} && ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp.Tools' + shell: pwsh + run: ./DisCatSharp.Tools/rebuild-tools.ps1 -ArtifactLocation ./dcs-artifacts -Configuration Release -VersionSuffix ${{github.event.inputs.version_suffix}} - name: Remove invalid packages shell: pwsh run: rm *.symbols.* @@ -75,19 +107,20 @@ jobs: run: dotnet nuget push --source https://nuget.pkg.github.com/Aiko-IT-Systems/index.json -k ${{secrets.NYUW_TOKEN_GH}} * working-directory: ./dcs-artifacts - name: Set outputs + if: ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp' id: vars run: | echo "version=10.6.0" >> $GITHUB_OUTPUT echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT - name: "Create Sentry prod release" - if: ${{!inputs.release_as_prerelease}} + if: ${{!inputs.release_as_prerelease}} && ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp' uses: getsentry/action-release@v1.6.0 with: environment: prod ignore_missing: true version: DisCatSharp@${{ steps.vars.outputs.version }}+${{ steps.vars.outputs.sha }} - name: "Create Sentry dev release" - if: ${{inputs.release_as_prerelease}} + if: ${{inputs.release_as_prerelease}} && ${{ github.event.inputs.packages_to_release }} == 'DisCatSharp' uses: getsentry/action-release@v1.6.0 with: environment: dev diff --git a/DisCatSharp.Tools/rebuild-attributes.ps1 b/DisCatSharp.Tools/rebuild-attributes.ps1 new file mode 100644 index 0000000000..b720983041 --- /dev/null +++ b/DisCatSharp.Tools/rebuild-attributes.ps1 @@ -0,0 +1,175 @@ +#!/usr/bin/env pwsh +# Rebuild-lib +# +# Rebuilds the entire DisCatSharp project, and places artifacts in specified directory. +# +# Author: Emzi0767 +# Version: 2018-08-30 14:41 +# +# Arguments: +# .\rebuild-lib.ps1 [version suffix] [build number] +# +# Run as: +# .\rebuild-lib.ps1 .\path\to\artifact\location Debug/Release version-suffix build-number +# +# or +# .\rebuild-lib.ps1 .\path\to\artifact\location Debug/Release + +param +( + [parameter(Mandatory = $true)] + [string] $ArtifactLocation, + + [parameter(Mandatory = $true)] + [string] $Configuration, + + [parameter(Mandatory = $false)] + [string] $VersionSuffix, + + [parameter(Mandatory = $false)] + [int] $BuildNumber = -1 +) + +# Check if configuration is valid +if ($Configuration -ne "Debug" -and $Configuration -ne "Release") +{ + Write-Host "Invalid configuration specified. Must be Release or Debug." + Exit 1 +} + +# Restores the environment +function Restore-Environment() +{ + Write-Host "Restoring environment" + Remove-Item ./NuGet.config +} + +# Prepares the environment +function Prepare-Environment([string] $target_dir_path) +{ + # Prepare the environment + Copy-Item ./.nuget/NuGet.config ./ + + # Check if the target directory exists + # If it does, remove it + if (Test-Path "$target_dir_path") + { + Write-Host "Target directory exists, deleting" + Remove-Item -recurse -force "$target_dir_path" + } + + # Create target directory + $dir = New-Item -type directory "$target_dir_path" +} + +# Builds everything +function Build-All([string] $target_dir_path, [string] $version_suffix, [string] $build_number, [string] $bcfg) +{ + # Form target path + $dir = Get-Item "$target_dir_path" + $target_dir = $dir.FullName + Write-Host "Will place packages in $target_dir" + + # Clean previous build results + Write-Host "Cleaning previous build" + & dotnet clean -v minimal -c "$bcfg" DisCatSharp.Tools/DisCatSharp.Tools.sln | Out-Host + if ($LastExitCode -ne 0) + { + Write-Host "Cleanup failed" + Return $LastExitCode + } + + # Restore nuget packages + Write-Host "Restoring NuGet packages" + & dotnet restore --no-cache -f -v minimal DisCatSharp.Tools/DisCatSharp.Tools.sln | Out-Host + if ($LastExitCode -ne 0) + { + Write-Host "Restoring packages failed" + Return $LastExitCode + } + + # Create build number string + if (-not $build_number) + { + $build_number_string = "" + } + else + { + $build_number_string = [int]::Parse($build_number).ToString("00000") + } + + # Build in specified configuration + Write-Host "Building everything" + if (-not $version_suffix) + { + & dotnet build --no-restore -v minimal -c "$bcfg" DisCatSharp.Attributes/DisCatSharp.Attributes.csproj | Out-Host + } + elseif (-not $build_number_string) + { + & dotnet build --no-restore -v minimal -c "$bcfg" --version-suffix "$version_suffix" DisCatSharp.Attributes/DisCatSharp.Attributes.csproj | Out-Host + } + else + { + & dotnet build --no-restore -v minimal -c "$bcfg" --version-suffix "$version_suffix" -p:BuildNumber="$build_number_string" DisCatSharp.Attributes/DisCatSharp.Attributes.csproj | Out-Host + } + if ($LastExitCode -ne 0) + { + Write-Host "Build failed" + Return $LastExitCode + } + + # Package for NuGet + Write-Host "Creating NuGet packages" + if (-not $version_suffix) + { + & dotnet pack -v minimal -c "$bcfg" --no-restore --no-build -o "$target_dir" --include-symbols DisCatSharp.Attributes/DisCatSharp.Attributes.csproj | Out-Host + } + elseif (-not $build_number_string) + { + & dotnet pack -v minimal -c "$bcfg" --no-restore --version-suffix "$version_suffix" --no-build -o "$target_dir" --include-symbols DisCatSharp.Attributes/DisCatSharp.Attributes.csproj | Out-Host + } + else + { + & dotnet pack -v minimal -c "$bcfg" --no-restore --version-suffix "$version_suffix" -p:BuildNumber="$build_number_string" --no-build -o "$target_dir" --include-symbols DisCatSharp.Attributes/DisCatSharp.Attributes.csproj | Out-Host + } + if ($LastExitCode -ne 0) + { + Write-Host "Packaging failed" + Return $LastExitCode + } + + Return 0 +} + +# Check if building a pre-production package +if ($VersionSuffix -and $BuildNumber -ge 0) +{ + Write-Host "Building pre-production package with version suffix of `"$VersionSuffix-$($BuildNumber.ToString("00000"))`"" +} +elseif ($VersionSuffix -and (-not $BuildNumber -or $BuildNumber -lt 0)) +{ + Write-Host "Building pre-production package with version suffix of `"$VersionSuffix`"" + Remove-Variable BuildNumber + $BuildNumber = $null +} + +# Prepare environment +Prepare-Environment "$ArtifactLocation" + +# Build everything +$BuildResult = Build-All "$ArtifactLocation" "$VersionSuffix" "$BuildNumber" "$Configuration" + +# Restore environment +Restore-Environment + +# Check if there were any errors +if ($BuildResult -ne 0) +{ + Write-Host "Build failed with code $BuildResult" + $host.SetShouldExit($BuildResult) + Exit $BuildResult +} +else +{ + Exit 0 +} diff --git a/DisCatSharp.Tools/rebuild-tools.ps1 b/DisCatSharp.Tools/rebuild-tools.ps1 new file mode 100644 index 0000000000..8629bebd08 --- /dev/null +++ b/DisCatSharp.Tools/rebuild-tools.ps1 @@ -0,0 +1,175 @@ +#!/usr/bin/env pwsh +# Rebuild-lib +# +# Rebuilds the entire DisCatSharp project, and places artifacts in specified directory. +# +# Author: Emzi0767 +# Version: 2018-08-30 14:41 +# +# Arguments: +# .\rebuild-lib.ps1 [version suffix] [build number] +# +# Run as: +# .\rebuild-lib.ps1 .\path\to\artifact\location Debug/Release version-suffix build-number +# +# or +# .\rebuild-lib.ps1 .\path\to\artifact\location Debug/Release + +param +( + [parameter(Mandatory = $true)] + [string] $ArtifactLocation, + + [parameter(Mandatory = $true)] + [string] $Configuration, + + [parameter(Mandatory = $false)] + [string] $VersionSuffix, + + [parameter(Mandatory = $false)] + [int] $BuildNumber = -1 +) + +# Check if configuration is valid +if ($Configuration -ne "Debug" -and $Configuration -ne "Release") +{ + Write-Host "Invalid configuration specified. Must be Release or Debug." + Exit 1 +} + +# Restores the environment +function Restore-Environment() +{ + Write-Host "Restoring environment" + Remove-Item ./NuGet.config +} + +# Prepares the environment +function Prepare-Environment([string] $target_dir_path) +{ + # Prepare the environment + Copy-Item ./.nuget/NuGet.config ./ + + # Check if the target directory exists + # If it does, remove it + if (Test-Path "$target_dir_path") + { + Write-Host "Target directory exists, deleting" + Remove-Item -recurse -force "$target_dir_path" + } + + # Create target directory + $dir = New-Item -type directory "$target_dir_path" +} + +# Builds everything +function Build-All([string] $target_dir_path, [string] $version_suffix, [string] $build_number, [string] $bcfg) +{ + # Form target path + $dir = Get-Item "$target_dir_path" + $target_dir = $dir.FullName + Write-Host "Will place packages in $target_dir" + + # Clean previous build results + Write-Host "Cleaning previous build" + & dotnet clean -v minimal -c "$bcfg" DisCatSharp.Tools/DisCatSharp.Tools.sln | Out-Host + if ($LastExitCode -ne 0) + { + Write-Host "Cleanup failed" + Return $LastExitCode + } + + # Restore nuget packages + Write-Host "Restoring NuGet packages" + & dotnet restore --no-cache -f -v minimal DisCatSharp.Tools/DisCatSharp.Tools.sln | Out-Host + if ($LastExitCode -ne 0) + { + Write-Host "Restoring packages failed" + Return $LastExitCode + } + + # Create build number string + if (-not $build_number) + { + $build_number_string = "" + } + else + { + $build_number_string = [int]::Parse($build_number).ToString("00000") + } + + # Build in specified configuration + Write-Host "Building everything" + if (-not $version_suffix) + { + & dotnet build --no-restore -v minimal -c "$bcfg" DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer.Package/DisCatSharp.Analyzer.Package.csproj | Out-Host + } + elseif (-not $build_number_string) + { + & dotnet build --no-restore -v minimal -c "$bcfg" --version-suffix "$version_suffix" DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer.Package/DisCatSharp.Analyzer.Package.csproj | Out-Host + } + else + { + & dotnet build --no-restore -v minimal -c "$bcfg" --version-suffix "$version_suffix" -p:BuildNumber="$build_number_string" DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer.Package/DisCatSharp.Analyzer.Package.csproj | Out-Host + } + if ($LastExitCode -ne 0) + { + Write-Host "Build failed" + Return $LastExitCode + } + + # Package for NuGet + Write-Host "Creating NuGet packages" + if (-not $version_suffix) + { + & dotnet pack -v minimal -c "$bcfg" --no-restore --no-build -o "$target_dir" --include-symbols DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer.Package/DisCatSharp.Analyzer.Package.csproj | Out-Host + } + elseif (-not $build_number_string) + { + & dotnet pack -v minimal -c "$bcfg" --no-restore --version-suffix "$version_suffix" --no-build -o "$target_dir" --include-symbols DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer.Package/DisCatSharp.Analyzer.Package.csproj | Out-Host + } + else + { + & dotnet pack -v minimal -c "$bcfg" --no-restore --version-suffix "$version_suffix" -p:BuildNumber="$build_number_string" --no-build -o "$target_dir" --include-symbols DisCatSharp.Tools/DisCatSharp.Analyzer/DisCatSharp.Analyzer.Package/DisCatSharp.Analyzer.Package.csproj | Out-Host + } + if ($LastExitCode -ne 0) + { + Write-Host "Packaging failed" + Return $LastExitCode + } + + Return 0 +} + +# Check if building a pre-production package +if ($VersionSuffix -and $BuildNumber -ge 0) +{ + Write-Host "Building pre-production package with version suffix of `"$VersionSuffix-$($BuildNumber.ToString("00000"))`"" +} +elseif ($VersionSuffix -and (-not $BuildNumber -or $BuildNumber -lt 0)) +{ + Write-Host "Building pre-production package with version suffix of `"$VersionSuffix`"" + Remove-Variable BuildNumber + $BuildNumber = $null +} + +# Prepare environment +Prepare-Environment "$ArtifactLocation" + +# Build everything +$BuildResult = Build-All "$ArtifactLocation" "$VersionSuffix" "$BuildNumber" "$Configuration" + +# Restore environment +Restore-Environment + +# Check if there were any errors +if ($BuildResult -ne 0) +{ + Write-Host "Build failed with code $BuildResult" + $host.SetShouldExit($BuildResult) + Exit $BuildResult +} +else +{ + Exit 0 +}