Publish NuGet Preview #24
This file contains hidden or 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: Publish NuGet Preview | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "NuGet package version (for example 0.1.1-preview.1)" | |
| required: true | |
| type: string | |
| run_tests: | |
| description: "Run tests before pack/publish" | |
| required: true | |
| default: true | |
| type: boolean | |
| publish: | |
| description: "Publish to NuGet.org (disable for dry-run pack)" | |
| required: true | |
| default: true | |
| type: boolean | |
| publish_release: | |
| description: "Create/update GitHub Release assets for this version" | |
| required: true | |
| default: true | |
| type: boolean | |
| permissions: | |
| contents: write | |
| jobs: | |
| pack-and-publish: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup .NET SDK | |
| uses: actions/setup-dotnet@v4 | |
| with: | |
| dotnet-version: "10.0.x" | |
| - name: Validate version | |
| id: vars | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| version='${{ inputs.version }}' | |
| if [[ -z "$version" ]]; then | |
| echo "version input is required" >&2 | |
| exit 1 | |
| fi | |
| version="${version#v}" | |
| tag="v${version}" | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| echo "artifact_dir=artifacts/release/$version" >> "$GITHUB_OUTPUT" | |
| # Encourage preview semantics for this workflow. | |
| if [[ "$version" != *"-preview."* && "$version" != *"-rc."* ]]; then | |
| echo "warning: version '$version' is not a preview/rc version" | |
| fi | |
| - name: Build release artifacts (bundle + nupkg) | |
| shell: pwsh | |
| run: | | |
| $runTests = [System.Convert]::ToBoolean('${{ inputs.run_tests }}') | |
| if ($runTests) { | |
| ./scripts/release/Build-ReleaseArtifacts.ps1 ` | |
| -Version '${{ steps.vars.outputs.version }}' ` | |
| -OutputRoot '${{ steps.vars.outputs.artifact_dir }}' | |
| } else { | |
| ./scripts/release/Build-ReleaseArtifacts.ps1 ` | |
| -Version '${{ steps.vars.outputs.version }}' ` | |
| -OutputRoot '${{ steps.vars.outputs.artifact_dir }}' ` | |
| -SkipTests | |
| } | |
| - name: Verify expected release outputs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| artifact_dir='${{ steps.vars.outputs.artifact_dir }}' | |
| version='${{ steps.vars.outputs.version }}' | |
| expected=( | |
| "$artifact_dir/roslynskills-bundle-$version.zip" | |
| "$artifact_dir/DNAKode.RoslynSkills.Cli.$version.nupkg" | |
| "$artifact_dir/DNAKode.XmlSkills.Cli.$version.nupkg" | |
| "$artifact_dir/release-manifest.json" | |
| "$artifact_dir/checksums.sha256" | |
| ) | |
| for path in "${expected[@]}"; do | |
| if [[ ! -f "$path" ]]; then | |
| echo "missing expected release output: $path" >&2 | |
| exit 1 | |
| fi | |
| echo "verified: $path" | |
| done | |
| - name: Upload release artifact bundle | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: roslynskills-release-${{ steps.vars.outputs.version }} | |
| path: ${{ steps.vars.outputs.artifact_dir }} | |
| if-no-files-found: error | |
| - name: Upload package artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-preview-packages-${{ steps.vars.outputs.version }} | |
| path: | | |
| ${{ steps.vars.outputs.artifact_dir }}/DNAKode.RoslynSkills.Cli.${{ steps.vars.outputs.version }}.nupkg | |
| ${{ steps.vars.outputs.artifact_dir }}/DNAKode.XmlSkills.Cli.${{ steps.vars.outputs.version }}.nupkg | |
| if-no-files-found: error | |
| - name: Publish to NuGet.org | |
| if: inputs.publish | |
| env: | |
| NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} | |
| run: | | |
| if [ -z "$NUGET_API_KEY" ]; then | |
| echo "NUGET_API_KEY secret is not set" >&2 | |
| exit 1 | |
| fi | |
| packages=( | |
| "${{ steps.vars.outputs.artifact_dir }}/DNAKode.RoslynSkills.Cli.${{ steps.vars.outputs.version }}.nupkg" | |
| "${{ steps.vars.outputs.artifact_dir }}/DNAKode.XmlSkills.Cli.${{ steps.vars.outputs.version }}.nupkg" | |
| ) | |
| for package in "${packages[@]}"; do | |
| if [ ! -f "$package" ]; then | |
| echo "missing package for publish: $package" >&2 | |
| exit 1 | |
| fi | |
| dotnet nuget push "$package" \ | |
| --api-key "$NUGET_API_KEY" \ | |
| --source https://api.nuget.org/v3/index.json \ | |
| --skip-duplicate | |
| done | |
| - name: Publish GitHub Release | |
| if: inputs.publish_release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.vars.outputs.tag }} | |
| name: RoslynSkills ${{ steps.vars.outputs.tag }} | |
| prerelease: ${{ contains(steps.vars.outputs.version, '-preview') || contains(steps.vars.outputs.version, '-rc') }} | |
| generate_release_notes: true | |
| target_commitish: ${{ github.sha }} | |
| files: | | |
| ${{ steps.vars.outputs.artifact_dir }}/*.zip | |
| ${{ steps.vars.outputs.artifact_dir }}/*.nupkg | |
| ${{ steps.vars.outputs.artifact_dir }}/release-manifest.json | |
| ${{ steps.vars.outputs.artifact_dir }}/checksums.sha256 | |