From cf91ff863e37644f694538f3976d89534019c723 Mon Sep 17 00:00:00 2001 From: Martin Othamar Date: Fri, 6 Dec 2024 10:29:40 +0100 Subject: [PATCH] Publish NuGet packages from PR (#952) --- .config/dotnet-tools.json | 12 +++++++-- .github/workflows/pr-actions.yml | 45 ++++++++++++++++++++++++++++++++ src/Directory.Build.props | 10 +++++-- 3 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pr-actions.yml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 1bb47fc64..7d9042e05 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -6,7 +6,15 @@ "version": "0.30.1", "commands": [ "dotnet-csharpier" - ] + ], + "rollForward": false + }, + "minver-cli": { + "version": "6.0.0", + "commands": [ + "minver" + ], + "rollForward": false } } -} +} \ No newline at end of file diff --git a/.github/workflows/pr-actions.yml b/.github/workflows/pr-actions.yml new file mode 100644 index 000000000..0c0fc0849 --- /dev/null +++ b/.github/workflows/pr-actions.yml @@ -0,0 +1,45 @@ +name: PR actions +on: + issue_comment: + types: [created, edited] +jobs: + publish: + name: Publish PR packages + runs-on: ubuntu-latest + if: github.event.issue.pull_request && contains(github.event.comment.body, '/publish') + env: + DOTNET_HOSTBUILDER__RELOADCONFIGONCHANGE: false + steps: + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 8.0.x + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Build PR release version + run: | + dotnet tool restore + sha=$(echo '${{ github.event.pull_request.head.sha }}' | cut -c1-8) + # Get the last part of the branch name if it contains a slash + branch=$(echo '${{ github.event.pull_request.head.ref }}' | sed 's/.*\///') + version=$(dotnet minver --tag-prefix v --ignore-height --default-pre-release-identifiers preview.0).$branch.$sha + echo "MINVERVERSIONOVERRIDE=$version" >> $GITHUB_ENV + echo $version + - name: Build + run: | + dotnet build AppLibDotnet.sln -v m -c Release + - name: Test + run: | + dotnet test AppLibDotnet.sln -v m --no-restore --no-build -c Release + - name: Pack PR release + run: | + dotnet pack AppLibDotnet.sln -v m --no-restore --no-build -c Release -p:Deterministic=true -p:BuildNumber=${{ github.run_number }} + - name: Versions + run: | + dotnet --version + - name: Publish PR release + run: | + dotnet nuget push src/**/bin/Release/*.nupkg --source https://nuget.pkg.github.com/Altinn/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 07a6027ae..1c1b48eb9 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -26,11 +26,11 @@ enable enable true - - $([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName) preview.0 v + $([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName) + true Altinn Platform Contributors git @@ -51,6 +51,12 @@ + + + $(PackageId).Experimental + + +