From 4e15d1e5961995d6ef35e17e38d97940492ca1ac Mon Sep 17 00:00:00 2001 From: AeonLucid Date: Wed, 14 Oct 2020 16:02:25 +0200 Subject: [PATCH] AppVeyor and cake --- .config/dotnet-tools.json | 12 +++ .github/workflows/deploy.yml | 156 ----------------------------------- .gitignore | 3 +- appveyor.yml | 33 +++----- build.cake | 101 +++++++++++++++++++++++ 5 files changed, 125 insertions(+), 180 deletions(-) create mode 100644 .config/dotnet-tools.json delete mode 100644 .github/workflows/deploy.yml create mode 100644 build.cake diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..727dfd7 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "0.38.5", + "commands": [ + "dotnet-cake" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index d252d4e..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,156 +0,0 @@ -name: Deploy - -on: - push: - tags: - - 'v*' - -jobs: - build: - name: Build - runs-on: windows-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: true - - name: Setup MSBuild.exe - uses: microsoft/setup-msbuild@v1.0.1 - - name: Setup .NET Core - uses: actions/setup-dotnet@v1 - with: - dotnet-version: 5.0.100-rc.1.20452.10 - - name: Install dependencies - run: dotnet restore ./src - # - name: Build Impostor.Client - # run: msbuild ./src/Impostor.Client/Impostor.Client.csproj /p:Configuration=Release /p:DebugSymbols=false /p:DebugType=None - - name: Build Impostor.Server - run: dotnet build --no-restore -c Release -f net5.0 ./src/Impostor.Server/Impostor.Server.csproj - - name: Test - run: dotnet test --no-restore -v normal -f net5.0 ./src - # - name: Zip Impostor.Client - # shell: bash - # run: | - # cd ./src/Impostor.Client/bin/Release/net452/win-x64 - # 7z a -r $GITHUB_WORKSPACE/build/win-x64-client.zip * - # cd $GITHUB_WORKSPACE - - - name: Publish Impostor.Server (win-x64) - run: dotnet publish -c release -o ./build/win-x64 -f net5.0 -r win-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - name: Zip Impostor.Server (win-x64) - shell: bash - run: | - cd ./build/win-x64 - 7z a -r ../win-x64.zip * - cd $GITHUB_WORKSPACE - - - name: Publish Impostor.Server (linux-x64) - run: dotnet publish -c release -o ./build/linux-x64 -f net5.0 -r linux-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - name: Zip Impostor.Server (linux-x64) - shell: bash - run: | - cd ./build/linux-x64 - 7z a -r ../linux-x64.zip * - cd $GITHUB_WORKSPACE - - - name: Publish Impostor.Server (linux-arm) - run: dotnet publish -c release -o ./build/linux-arm -f net5.0 -r linux-arm --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - name: Zip Impostor.Server (linux-arm) - shell: bash - run: | - cd ./build/linux-arm - 7z a -r ../linux-arm.zip * - cd $GITHUB_WORKSPACE - - - name: Publish Impostor.Server (linux-arm64) - run: dotnet publish -c release -o ./build/linux-arm64 -f net5.0 -r linux-arm64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - name: Zip Impostor.Server (linux-arm64) - shell: bash - run: | - cd ./build/linux-arm64 - 7z a -r ../linux-arm64.zip * - cd $GITHUB_WORKSPACE - - - name: Publish Impostor.Server (osx-x64) - run: dotnet publish -c release -o ./build/osx-x64 -f net5.0 -r osx-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - name: Zip Impostor.Server (osx-x64) - shell: bash - run: | - cd ./build/osx-x64 - 7z a -r ../osx-x64.zip * - cd $GITHUB_WORKSPACE - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Release ${{ github.ref }} - body: | - Changes in this Release - - First Change - - Second Change - draft: true - prerelease: false - # - - # name: Upload Release Asset (win-x64) Client - # uses: actions/upload-release-asset@v1 - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # with: - # upload_url: ${{ steps.create_release.outputs.upload_url }} - # asset_path: ./build/win-x64-client.zip - # asset_name: Impostor-Client-win-x64.zip - # asset_content_type: application/zip - - - name: Upload Release Asset (win-x64) Server - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/win-x64.zip - asset_name: Impostor-Server-win-x64.zip - asset_content_type: application/zip - - - name: Upload Release Asset (linux-x64) Server - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/linux-x64.zip - asset_name: Impostor-Server-linux-x64.zip - asset_content_type: application/zip - - - name: Upload Release Asset (linux-arm) Server - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/linux-arm.zip - asset_name: Impostor-Server-linux-arm.zip - asset_content_type: application/zip - - - name: Upload Release Asset (linux-arm64) Server - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/linux-arm64.zip - asset_name: Impostor-Server-linux-arm64.zip - asset_content_type: application/zip - - - name: Upload Release Asset (osx-x64) Server - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build/osx-x64.zip - asset_name: Impostor-Server-osx-x64.zip - asset_content_type: application/zip \ No newline at end of file diff --git a/.gitignore b/.gitignore index fbb2346..e5150c9 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/.vscode \ No newline at end of file +/.vscode +/build \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index a85d5de..f536b6e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,34 +28,21 @@ environment: install: - git submodule update --init --recursive - -before_build: - - dotnet restore "src/Impostor.sln" -v Minimal + - ps: .\build\dotnet-install.ps1 -InstallDir 'C:\Program Files\dotnet\' + - ps: dotnet tool restore build_script: - # Tests - - dotnet build "src/Impostor.Tests/Impostor.Tests.csproj" -c Release - # Client - - dotnet build "src/Impostor.Client/Impostor.Client.Cli/Impostor.Client.Cli.csproj" --no-restore -c Release -f net5.0 - - dotnet build "src/Impostor.Client/Impostor.Client.WinForms/Impostor.Client.WinForms.csproj" /p:Configuration=Release /p:DebugSymbols=false /p:DebugType=None - # Server win-x64 - - dotnet publish -c release -o build/win-x64 -f net5.0 -r win-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - ps: 7z a -r build/Impostor-Server-win-x64-$(APPVEYOR_BUILD_VERSION).zip %APPVEYOR_BUILD_FOLDER%/build/win-x64/* - # Server linux-x64 - - dotnet publish -c release -o ./build/linux-x64 -f net5.0 -r linux-x64 --self-contained --no-restore ./src/Impostor.Server/Impostor.Server.csproj /p:PublishSingleFile=true - - ps: z a -r build/Impostor-Server-linux-x64-$(APPVEYOR_BUILD_VERSION).zip %APPVEYOR_BUILD_FOLDER%/build/linux-x64/* - -test_script: - - dotnet test --no-build --no-restore -v normal -f net5.0 -c Release "src/Impostor.Tests" + - ps: dotnet cake build.cake --bootstrap + - ps: dotnet cake build.cake --pack + +test: off artifacts: - - path: build/Impostor-Server-win-x64-$(APPVEYOR_BUILD_VERSION).zip - name: Impostor-Server-win-x64-$(APPVEYOR_BUILD_VERSION).zip - - path: build/Impostor-Server-linux-x64-$(APPVEYOR_BUILD_VERSION).zip - name: Impostor-Server-linux-x64-$(APPVEYOR_BUILD_VERSION).zip + - path: ./build/*.zip only_commits: files: - - appveyor.yml - - src/**/* + - ./appveyor.yml + - ./build.cake + - ./src/**/* - .gitmodules diff --git a/build.cake b/build.cake new file mode 100644 index 0000000..8c79c0c --- /dev/null +++ b/build.cake @@ -0,0 +1,101 @@ +var buildVersion = EnvironmentVariable("APPVEYOR_BUILD_VERSION") ?? "1.0.0"; +var buildDir = MakeAbsolute(Directory("./build")); + +var target = Argument("target", "Deploy"); +var configuration = Argument("configuration", "Release"); + +////////////////////////////////////////////////////////////////////// +// UTILS +////////////////////////////////////////////////////////////////////// + +public void ImpostorPublish(string name, string project, string runtime) { + var projBuildDir = buildDir.Combine(name + "-" + runtime); + var projBuildZip = buildDir.CombineWithFilePath(name + "-" + buildVersion + "-" + runtime + ".zip"); + + DotNetCorePublish(project, new DotNetCorePublishSettings { + Configuration = configuration, + NoRestore = true, + Framework = "net5.0", + Runtime = runtime, + SelfContained = true, + PublishSingleFile = true, + PublishTrimmed = true, + OutputDirectory = projBuildDir + }); + + Zip(projBuildDir, projBuildZip); +} + +public void ImpostorPublishNF(string name, string project) { + var runtime = "win-x64"; + var projBuildDir = buildDir.Combine(name + "-" + runtime); + var projBuildZip = buildDir.CombineWithFilePath(name + "-" + buildVersion + "-" + runtime + ".zip"); + + DotNetCorePublish(project, new DotNetCorePublishSettings { + Configuration = configuration, + NoRestore = true, + Framework = "net462", + OutputDirectory = projBuildDir + }); + + Zip(projBuildDir, projBuildZip); +} + +////////////////////////////////////////////////////////////////////// +// TASKS +////////////////////////////////////////////////////////////////////// + +Task("Clean") + .Does(() => { + if (DirectoryExists(buildDir)) { + DeleteDirectory(buildDir, new DeleteDirectorySettings { + Recursive = true + }); + } + }); + +Task("Restore") + .Does(() => { + DotNetCoreRestore("./src/Impostor.sln"); + }); + +Task("Build") + .IsDependentOn("Clean") + .IsDependentOn("Restore") + .Does(() => { + // Tests. + DotNetCoreBuild("./src/Impostor.Tests/Impostor.Tests.csproj", new DotNetCoreBuildSettings { + Configuration = configuration, + }); + + // Client. + ImpostorPublishNF("Impostor-Client", "./src/Impostor.Client/Impostor.Client.WinForms/Impostor.Client.WinForms.csproj"); + + // Server. + ImpostorPublish("Impostor-Server", "./src/Impostor.Server/Impostor.Server.csproj", "win-x64"); + ImpostorPublish("Impostor-Server", "./src/Impostor.Server/Impostor.Server.csproj", "osx-x64"); + ImpostorPublish("Impostor-Server", "./src/Impostor.Server/Impostor.Server.csproj", "linux-x64"); + ImpostorPublish("Impostor-Server", "./src/Impostor.Server/Impostor.Server.csproj", "linux-arm"); + ImpostorPublish("Impostor-Server", "./src/Impostor.Server/Impostor.Server.csproj", "linux-arm64"); + }); + +Task("Test") + .IsDependentOn("Build") + .Does(() => { + DotNetCoreTest("./src/Impostor.Tests/Impostor.Tests.csproj", new DotNetCoreTestSettings { + Configuration = configuration, + NoBuild = true + }); + }); + +Task("Deploy") + .IsDependentOn("Test") + .Does(() => { + Information("Finished."); + }); + +////////////////////////////////////////////////////////////////////// +// EXECUTION +////////////////////////////////////////////////////////////////////// + +RunTarget(target); \ No newline at end of file -- 2.39.5