Skip to content

Build NuGet

Build NuGet #2

Workflow file for this run

name: Build NuGet
on:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
jobs:
check-version-change:
runs-on: windows-latest
outputs:
version_changed: ${{ steps.check.outputs.version_changed }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.BUILD_TOKEN }}
- name: Check for version.json changes
id: check
run: |
$versionFile = ".version/version.json"
$versionChanged = git diff --name-only ${{ github.event.before }} ${{ github.sha }} | Select-String -Pattern $versionFile -Quiet
if ($versionChanged) {
echo "VERSION_CHANGED=true" | Out-File -Append -FilePath $Env:GITHUB_ENV
} else {
echo "VERSION_CHANGED=false" | Out-File -Append -FilePath $Env:GITHUB_ENV
}
echo "version_changed=$versionChanged" >> $GITHUB_ENV
- name: Add GitHub Packages source
run: |
nuget sources Add -Name "GitHub" -Source "https://nuget.pkg.github.com/PrimeEagle/index.json" -Username ${{ github.repository_owner }} -Password ${{ secrets.BUILD_TOKEN }}
create-package:
needs: check-version-change
runs-on: windows-latest
if: github.event_name == 'workflow_dispatch' || needs.check-version-change.outputs.version_changed == 'True'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: 'recursive'
token: ${{ secrets.BUILD_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ secrets.DOTNET_VERSION }}
- name: Add GitHub Packages source
run: |
nuget sources Add -Name "GitHub" -Source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" -Username ${{ github.repository_owner }} -Password ${{ secrets.BUILD_TOKEN }}
- name: Read Version from version.json
run: |
$versionFile = ".version/version.json"
$versionJson = Get-Content $versionFile -Raw | ConvertFrom-Json
echo "VERSION_NUMBER=$($versionJson.version)" | Out-File -Append -FilePath $Env:GITHUB_ENV
- name: Print Version Number
run: echo "Version number is $env:VERSION_NUMBER"
- name: Pack
run: dotnet pack ${{ secrets.DOTNET_SOLUTION }} --configuration Release -o nupkgs /p:Version=${{ env.VERSION_NUMBER }}
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: nuget-packages
path: nupkgs/*.nupkg
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: nuget-packages
path: nupkgs
- name: Setup .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ secrets.DOTNET_VERSION }}
- name: Determine Package File
id: package_file
run: |
$PACKAGE_FILE = Get-ChildItem nupkgs/*.nupkg | Sort-Object LastWriteTime | Select-Object -Last 1 -ExpandProperty FullName
echo "PACKAGE_FILE=$PACKAGE_FILE" | Out-File -Append -FilePath $Env:GITHUB_ENV
- name: Publish
run: |
dotnet nuget push "${{ env.PACKAGE_FILE }}" --source "github" --skip-duplicate --api-key ${{ secrets.BUILD_TOKEN }}
- name: Update version-nuget.json
run: |
$NugetVersion = "${{ env.VERSION_NUMBER }}"
$VersionData = @{
version = $NugetVersion
}
$nugetVersionFile = ".version/version-nuget.json"
$VersionData | ConvertTo-Json | Set-Content -Path $nugetVersionFile
git config --global user.email "${{ secrets.USER_EMAIL }}"
git config --global user.name "${{ github.repository_owner }}"
git add $nugetVersionFile
git commit -m "Update NuGet package version to $NugetVersion"
git push