Deploy NuGet package #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy NuGet package | |
on: | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: Deployment environment | |
type: choice | |
options: | |
- staging | |
- nuget.org | |
default: staging | |
required: true | |
preview: | |
description: Append preview suffix | |
type: boolean | |
default: true | |
required: true | |
concurrency: | |
group: package-deployer | |
cancel-in-progress: true | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.compose.outputs.version }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/setup@v0 | |
with: | |
versionSpec: "5.x" | |
preferLatestVersion: true | |
- name: Determine version | |
id: gitversion | |
uses: gittools/actions/gitversion/execute@v0 | |
with: | |
updateAssemblyInfo: true | |
useConfigFile: true | |
configFilePath: gitversion.yml | |
- name: Compose version | |
id: compose | |
run: | | |
COMPOSED_VERSION=${{ steps.gitversion.outputs.majorMinorPatch }}${{ inputs.preview && '-preview.' || '' }}${{ inputs.preview && steps.gitversion.outputs.preReleaseNumber || '' }} | |
echo "version=$COMPOSED_VERSION" >> "$GITHUB_OUTPUT" | |
echo "COMPOSED_VERSION=$COMPOSED_VERSION" >> "$GITHUB_ENV" | |
echo "Composed version is:" | |
echo $COMPOSED_VERSION | |
- name: Install .NET SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "8.x" | |
dotnet-quality: "ga" | |
- name: Build library | |
run: > | |
dotnet build src/Indicators.csproj | |
--configuration Release | |
--property:Version=$COMPOSED_VERSION | |
--property:ContinuousIntegrationBuild=true | |
-warnAsError | |
- name: Pack for NuGet | |
run: > | |
dotnet pack src/Indicators.csproj | |
--configuration Release | |
--no-build | |
--include-symbols | |
--output NuGet | |
-p:PackageVersion=$COMPOSED_VERSION | |
- name: Save NuGet package | |
uses: actions/upload-artifact@v3 | |
with: | |
name: packages | |
path: NuGet | |
- name: Summary output | |
run: | | |
{ | |
echo "| Version No. | Component |" | |
echo "| :---------- | :---------------------------------------------- |" | |
echo "| Major | ${{ steps.gitversion.outputs.major }} |" | |
echo "| Minor | ${{ steps.gitversion.outputs.minor }} |" | |
echo "| Patch | ${{ steps.gitversion.outputs.patch }} |" | |
echo "| Base | ${{ steps.gitversion.outputs.majorMinorPatch }} |" | |
echo "| Composed | $COMPOSED_VERSION |" | |
} >> $GITHUB_STEP_SUMMARY | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
environment: | |
name: ${{ inputs.environment }} | |
url: "${{ vars.NUGET_DOWNLOAD_PREFIX }}${{ needs.build.outputs.version }}" | |
steps: | |
- name: Pre-flight summary | |
run: | | |
{ | |
echo "| Parameter | Value |" | |
echo "| :-------------- | :--------------------------------- |" | |
echo "| Environment | ${{ inputs.environment }} |" | |
echo "| Publishing URL | ${{ vars.NUGET_PUBLISH_URL }} |" | |
echo "| Download URL | ${{ vars.NUGET_DOWNLOAD_PREFIX }} |" | |
echo "| Version ID | ${{ needs.build.outputs.version }} |" | |
} >> $GITHUB_STEP_SUMMARY | |
- name: Install .NET SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "8.x" | |
dotnet-quality: "ga" | |
- name: Install NuGet tool | |
uses: nuget/setup-nuget@v1 | |
with: | |
nuget-api-key: ${{ secrets.NUGET_TOKEN }} | |
nuget-version: '6.x' | |
- name: Download NuGet package | |
uses: actions/download-artifact@v3 | |
with: | |
name: packages | |
path: NuGet | |
- name: Publish to Azure Artifacts (staging) | |
if: inputs.environment == 'staging' | |
run: | | |
dotnet new nugetconfig --force | |
nuget sources Add -Name "AzureArtifacts" -Source ${{ vars.NUGET_PUBLISH_URL }} -UserName DaveSkender -Password ${{ secrets.NUGET_TOKEN }} -NonInteractive -ConfigFile nuget.config | |
nuget push NuGet/*.nupkg -src AzureArtifacts -ApiKey AZ -NonInteractive -ConfigFile nuget.config | |
- name: Publish to NuGet.org | |
if: inputs.environment == 'nuget.org' | |
run: | | |
dotnet new nugetconfig --force | |
nuget setApiKey ${{ secrets.NUGET_TOKEN }} -src nuget -ConfigFile nuget.config | |
nuget push NuGet/*.nupkg -src nuget -NonInteractive -ConfigFile nuget.config -Verbosity Detailed | |
- name: Tag and draft release note | |
uses: ncipollo/release-action@v1 | |
if: inputs.environment == 'nuget.org' | |
with: | |
body: | | |
We’ve released a new Stock Indicators for .NET NuGet package. | |
See [Skender.Stock.Indicators @ NuGet.org](${{ vars.NUGET_DOWNLOAD_PREFIX }}${{ needs.build.outputs.version }}) for more information. | |
generateReleaseNotes: true | |
draft: true | |
makeLatest: ${{ !inputs.preview }} | |
prerelease: ${{ inputs.preview }} | |
tag: ${{ needs.build.outputs.version }} | |
commit: ${{ github.ref_name }} |