update dotnet syntax #122
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 | |
# Version format: major.minor.patch[-preview.suffix] | |
# - Versioning managed by GitVersion | |
# - Preview suffix toggled by "preview" input | |
# - Non-preview versions on nuget.org restricted to main branch; | |
# runs targeting nuget.org from non-"main" branches will fail early. | |
# - Default: patch increment unless "+semver:" message found | |
# or will use "next-version" if set in config | |
# - Preview numbers auto-increment (e.g., preview.1 -> preview.2) | |
# - Branches are only tagged with the version after deployments to nuget.org | |
on: | |
push: | |
branches: | |
- main | |
- 'v*' | |
- fix-deployer | |
workflow_dispatch: | |
inputs: | |
environment: | |
description: Deployment environment | |
type: choice | |
options: | |
- pkg.github.com | |
- nuget.org | |
default: pkg.github.com | |
required: true | |
preview: | |
description: Append preview suffix | |
type: boolean | |
default: true | |
required: true | |
dry_run: | |
description: 'Dry-run only (no deploy)' | |
type: boolean | |
default: true | |
required: true | |
concurrency: | |
group: ${{ github.ref_name }} | |
cancel-in-progress: true | |
jobs: | |
validate: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Debug GitVersion config presence | |
run: cat src/gitversion.yml | |
- name: Setup GitVersion Tool | |
run: dotnet tool install --global GitVersion.Tool --version 6.0.5 | |
- name: Show GitVersion config | |
run: dotnet gitversion -showconfig -config src/gitversion.yml | |
- name: Show GitVersion config (with Json output) | |
run: dotnet gitversion -output json -l console -config src/gitversion.yml | |
- name: Validate preview settings | |
run: | | |
if [[ "${{ github.event.inputs.environment }}" == "nuget.org" ]] && \ | |
[[ "${{ github.ref }}" != "refs/heads/main" ]] && \ | |
[[ "${{ github.event.inputs.preview }}" != "true" ]]; then | |
echo "::error::Non-preview versions on nuget.org are only allowed from main branch" | |
exit 1 | |
fi | |
package: | |
needs: validate | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.version_info.outputs.version }} | |
url: ${{ steps.package_info.outputs.url }} | |
name: ${{ steps.package_info.outputs.name }} | |
environ: ${{ steps.settings.outputs.environ }} | |
preview: ${{ steps.settings.outputs.preview }} | |
dry_run: ${{ steps.settings.outputs.dry_run }} | |
steps: | |
- name: Set default inputs for dispatch | |
id: settings | |
run: | | |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then | |
echo "environ=${{ inputs.environment }}" >> $GITHUB_OUTPUT | |
echo "preview=${{ inputs.preview }}" >> $GITHUB_OUTPUT | |
echo "dry_run=${{ inputs.dry_run }}" >> $GITHUB_OUTPUT | |
else | |
echo "environ=NO_ENVIRONMENT" >> $GITHUB_OUTPUT | |
echo "preview=true" >> $GITHUB_OUTPUT | |
echo "dry_run=true" >> $GITHUB_OUTPUT | |
fi | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install dependencies | |
run: sudo apt-get update && sudo apt-get install -y libxml2-utils | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "9.x" | |
dotnet-quality: "ga" | |
- name: Debug Git state | |
run: | | |
git branch | |
git status | |
git log --oneline -n 5 | |
- name: Setup GitVersion Tool | |
run: | | |
# Install GitVersion as a global tool | |
dotnet tool install --global GitVersion.Tool --version 6.0.5 | |
# Add the tool to PATH | |
echo "$HOME/.dotnet/tools" >> $GITHUB_PATH | |
- name: Determine version | |
id: gitversion | |
run: | | |
# Execute GitVersion and capture JSON output | |
dotnet gitversion -output json -config src/gitversion.yml > gitversion.json | |
# Extract desired outputs | |
version=$(jq -r '.SemVer' gitversion.json) | |
prerelease_tag=$(jq -r '.PreReleaseTag' gitversion.json) | |
prerelease_number=$(jq -r '.PreReleaseNumber' gitversion.json) | |
echo "SemVer=$version" >> $GITHUB_OUTPUT | |
echo "PreReleaseTag=$prerelease_tag" >> $GITHUB_OUTPUT | |
echo "PreReleaseNumber=$prerelease_number" >> $GITHUB_OUTPUT | |
- name: Compose version | |
id: version_info | |
run: | | |
# get base version from GitVersion (respects tags on main, next-version on others) | |
base="${{ steps.gitversion.outputs.SemVer }}" | |
# preview suffix controlled by workflow input + gitversion config | |
if [[ "${{ steps.settings.outputs.preview }}" == "true" ]]; then | |
# respect GitVersion preview tag config from gitversion.yml | |
preview_tag="-${{ steps.gitversion.outputs.PreReleaseTag }}." | |
preview_num="${{ steps.gitversion.outputs.PreReleaseNumber }}" | |
else | |
preview_tag="" | |
preview_num="" | |
fi | |
ver="${base}${preview_tag}${preview_num}" | |
echo "version=$ver" >> "$GITHUB_OUTPUT" | |
- name: Compose package info | |
id: package_info | |
run: | | |
PACKAGE_NAME=$(xmllint --xpath "//PropertyGroup/PackageId/text()" src/Indicators.csproj) | |
echo "name=${PACKAGE_NAME}" >> $GITHUB_OUTPUT | |
if [[ "${{ steps.settings.outputs.environ }}" == "nuget.org" ]]; then | |
echo "url=https://www.nuget.org/packages/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT | |
else | |
echo "url=https://github.com/${{ github.repository }}/packages/nuget/${PACKAGE_NAME}/${{ steps.version_info.outputs.version }}" >> $GITHUB_OUTPUT | |
fi | |
- name: Build library | |
run: > | |
dotnet build src/Indicators.csproj | |
--configuration Release | |
--property:Version=${{ steps.version_info.outputs.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=${{ steps.version_info.outputs.version }} | |
- name: Save package | |
uses: actions/upload-artifact@v4 | |
with: | |
name: packages | |
path: NuGet | |
include-hidden-files: true | |
- name: Summary output | |
run: | | |
{ | |
echo "| Version No. | Component |" | |
echo "| :---------------- | :----------------------------------------------- |" | |
echo "| SemVer | ${{ steps.gitversion.outputs.SemVer }} |" | |
echo "| PreReleaseTag | ${{ steps.gitversion.outputs.PreReleaseTag }} |" | |
echo "| PreReleaseNumber | ${{ steps.gitversion.outputs.PreReleaseNumber }} |" | |
echo "| Composed | ${{ steps.version_info.outputs.version }} |" | |
echo "| Package | ${{ steps.package_info.outputs.name }} |" | |
echo "| Package URL | ${{ steps.package_info.outputs.url }} |" | |
} >> $GITHUB_STEP_SUMMARY | |
deploy: | |
needs: package | |
runs-on: ubuntu-latest | |
if: success() | |
permissions: | |
contents: write | |
packages: write | |
environment: | |
name: ${{ needs.package.outputs.environ }} | |
url: ${{ needs.package.outputs.url }} | |
env: | |
version: ${{ needs.package.outputs.version }} | |
preview: ${{ needs.package.outputs.preview }} | |
dry_run: ${{ needs.package.outputs.dry_run }} | |
environ: ${{ needs.package.outputs.environ }} | |
url: ${{ needs.package.outputs.url }} | |
name: ${{ needs.package.outputs.name }} | |
NUGET_PUBLISH_URL: ${{ needs.package.outputs.environ == 'nuget.org' && 'https://api.nuget.org/v3/index.json' || 'https://nuget.pkg.github.com/${{ github.repository }}/index.json' }} | |
NUGET_API_KEY: ${{ needs.package.outputs.environ == 'nuget.org' && secrets.NUGET_TOKEN || secrets.GITHUB_TOKEN }} | |
steps: | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: "9.x" | |
dotnet-quality: "ga" | |
- name: Download package | |
uses: actions/download-artifact@v4 | |
with: | |
name: packages | |
path: NuGet | |
- name: Publish package | |
if: ${{ !env.dry_run }} | |
run: > | |
dotnet nuget push NuGet/*.nupkg | |
--source "${{ env.NUGET_PUBLISH_URL }}" | |
--api-key "${{ env.NUGET_API_KEY }}" | |
--skip-duplicate | |
- name: Tag and draft release note | |
uses: ncipollo/release-action@v1 | |
if: ${{ !env.dry_run && env.environ == 'nuget.org' }} | |
with: | |
body: | | |
## Release ${{ env.version }} | |
📦 Package deployed to [${{ env.environ }}](${{ env.url }}) | |
### Package Details | |
- **Name**: ${{ env.name }} | |
- **Version**: ${{ env.version }} | |
- **Preview**: ${{ env.preview && 'Yes' || 'No' }} | |
generateReleaseNotes: true | |
draft: true | |
makeLatest: ${{ !env.preview }} | |
prerelease: ${{ env.preview }} | |
tag: v${{ env.version }} | |
commit: ${{ github.sha }} | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Deployment summary | |
if: always() | |
run: | | |
{ | |
echo "## Package Deployment" | |
echo "| Parameter | Value |" | |
echo "|:------------|:------|" | |
echo "| Mode | ${{ env.dry_run && '🔍 DRY RUN' || '🚀 DEPLOY' }} |" | |
echo "| Status | ${{ job.status == 'success' && '✅ Success' || '❌ Failed' }} |" | |
echo "| Environment | ${{ env.environ }} |" | |
echo "| Version | ${{ env.version }} |" | |
echo "| Package | [${{ env.name }}](${{ env.url }}) |" | |
echo "| Preview | ${{ env.preview && '✓' || '✗' }} |" | |
} >> $GITHUB_STEP_SUMMARY |