Skip to content

Commit

Permalink
Publish NuGet packages from PR (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar authored Dec 6, 2024
1 parent 3fb8e8e commit cf91ff8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
12 changes: 10 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
"version": "0.30.1",
"commands": [
"dotnet-csharpier"
]
],
"rollForward": false
},
"minver-cli": {
"version": "6.0.0",
"commands": [
"minver"
],
"rollForward": false
}
}
}
}
45 changes: 45 additions & 0 deletions .github/workflows/pr-actions.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 8 additions & 2 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName)</RepoRoot>
<MinVerDefaultPreReleaseIdentifiers>preview.0</MinVerDefaultPreReleaseIdentifiers>
<MinVerTagPrefix>v</MinVerTagPrefix>

<RepoRoot>$([System.IO.Directory]::GetParent($(MSBuildThisFileDirectory)).Parent.FullName)</RepoRoot>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Authors>Altinn Platform Contributors</Authors>
<RepositoryType>git</RepositoryType>
Expand All @@ -51,6 +51,12 @@
</PropertyGroup>
</Target>

<Target Name="ExperimentalBuild" AfterTargets="MinVer" Condition="'$(MinVerVersionOverride)'!=''">
<PropertyGroup>
<PackageId>$(PackageId).Experimental</PackageId>
</PropertyGroup>
</Target>

<ItemGroup Condition="'$(Deterministic)'=='true'">
<SourceRoot Include="$(MSBuildThisFileDirectory)/" />
</ItemGroup>
Expand Down

0 comments on commit cf91ff8

Please sign in to comment.