From cee90a2202b350c170f179e206009e4069c2b4d7 Mon Sep 17 00:00:00 2001 From: Alex McAuliffe Date: Thu, 17 Nov 2022 17:16:34 +0000 Subject: [PATCH] Add publish github action --- .github/workflows/build.yml | 2 +- .github/workflows/publish.yml | 34 ++++++++++++++++++++++++++++++++++ appveyor.yml | 19 ------------------- build.cake | 24 +++++++++++++++++++++--- 4 files changed, 56 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/publish.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fbd3397..fef76f2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: - name: Run the build script uses: cake-build/cake-action@v1 with: - target: Github + target: Pack - name: Upload a Build Artifact uses: actions/upload-artifact@v3.1.0 if: runner.os == 'Windows' diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..47d214c --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,34 @@ +name: Publish + +on: + push: + branches: + - main + +jobs: + release: + name: Release + if: "!contains(github.event.head_commit.message, 'skip-ci')" + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup dotnet + uses: actions/setup-dotnet@v3 + with: + dotnet-version: 6.0.x + + - name: Nerdbank.GitVersioning + uses: dotnet/nbgv@v0.4.0 + with: + setAllVars: true + + - name: Build + uses: cake-build/cake-action@v1 + env: + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} + with: + target: Github \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 926834d..0000000 --- a/appveyor.yml +++ /dev/null @@ -1,19 +0,0 @@ -version: 1.0.1000000.{build} -image: Visual Studio 2022 -configuration: Release -install: -- cmd: git submodule update --init --recursive -- ps: >- - dotnet --info -build_script: -- ps: dotnet tool restore -- ps: dotnet cake --target=Appveyor -artifacts: -- path: .\artifacts\*.nupkg -test: false -deploy: -- provider: NuGet - api_key: - secure: F2XoBC5Dq633+XJVmP8Lzd2Ii8PZfT5zsa55ISograD4vEm7IxppfjUUVa6D3ukf - on: - APPVEYOR_REPO_TAG: true diff --git a/build.cake b/build.cake index d08b1e6..0eb48be 100644 --- a/build.cake +++ b/build.cake @@ -49,11 +49,29 @@ Task("Pack") DotNetPack("./src/Cake.Coverlet/Cake.Coverlet.csproj", data.PackSettings); }); -Task("Appveyor") - .IsDependentOn("Pack"); +Task("Publish") + .IsDependentOn("Pack") + .Does((ICakeContext context, MyBuildData data) => +{ + // Make sure that there is an API key. + var apiKey = context.EnvironmentVariable("NUGET_API_KEY"); + if (string.IsNullOrWhiteSpace(apiKey)) { + throw new CakeException("No NuGet API key specified."); + } + + // Publish all projects + foreach(var file in GetFiles($"./{data.ArtifactsDirectory}/*.nupkg")) + { + context.Information("Publishing {0}...", file.GetFilename().FullPath); + context.NuGetPush(file, new NuGetPushSettings { + ApiKey = apiKey, + Source = "https://api.nuget.org/v3/index.json" + }); + } +}); Task("Github") - .IsDependentOn("Pack"); + .IsDependentOn("Publish"); Task("Default") .IsDependentOn("Pack");