quick note #3
Workflow file for this run
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 packages | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-and-publish: | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| contents: read | |
| id-token: write | |
| steps: | |
| - name: Check out repository | |
| uses: actions/checkout@v6 | |
| - name: Set up .NET | |
| uses: actions/setup-dotnet@v5 | |
| with: | |
| dotnet-version: 10.0.x | |
| - name: Resolve package version | |
| id: version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| version="${GITHUB_REF_NAME#v}" | |
| if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then | |
| echo "Tag '$GITHUB_REF_NAME' does not produce a valid package version." | |
| exit 1 | |
| fi | |
| echo "version=$version" >> "$GITHUB_OUTPUT" | |
| - name: Restore | |
| working-directory: MagicSettings | |
| run: dotnet restore MagicSettings.sln | |
| - name: Build | |
| working-directory: MagicSettings | |
| run: dotnet build MagicSettings.sln --configuration Release --no-restore | |
| - name: Test | |
| working-directory: MagicSettings | |
| run: dotnet test MagicSettings.sln --configuration Release --no-build --logger "console;verbosity=normal" | |
| - name: Pack | |
| working-directory: MagicSettings | |
| run: >- | |
| dotnet pack MagicSettings.sln | |
| --configuration Release | |
| --no-restore | |
| --output ../artifacts/packages | |
| -p:PackageVersion=${{ steps.version.outputs.version }} | |
| - name: Validate package output | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| version="${{ steps.version.outputs.version }}" | |
| package_dir="artifacts/packages" | |
| test -f "$package_dir/MagicSettings.$version.nupkg" | |
| test -f "$package_dir/MagicSettings.Server.$version.nupkg" | |
| if find "$package_dir" -maxdepth 1 -name 'MagicSettings.Share.*.nupkg' | grep -q .; then | |
| echo "MagicSettings.Share must not be published as a standalone package." | |
| exit 1 | |
| fi | |
| package_count=$(find "$package_dir" -maxdepth 1 -name '*.nupkg' | wc -l) | |
| if [[ "$package_count" -ne 2 ]]; then | |
| echo "Expected exactly two .nupkg files, found $package_count." | |
| find "$package_dir" -maxdepth 1 -type f -print | |
| exit 1 | |
| fi | |
| for package in \ | |
| "$package_dir/MagicSettings.$version.nupkg" \ | |
| "$package_dir/MagicSettings.Server.$version.nupkg"; do | |
| if ! unzip -l "$package" | grep -q 'lib/net10.0/MagicSettings.Share.dll'; then | |
| echo "$package does not contain lib/net10.0/MagicSettings.Share.dll." | |
| exit 1 | |
| fi | |
| done | |
| - name: Upload package artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: nuget-packages-${{ steps.version.outputs.version }} | |
| path: artifacts/packages/*.*nupkg | |
| if-no-files-found: error | |
| - name: NuGet login | |
| id: login | |
| uses: NuGet/login@v1 | |
| with: | |
| user: ${{ secrets.NUGET_USER }} | |
| - name: Publish packages | |
| shell: bash | |
| run: >- | |
| dotnet nuget push "artifacts/packages/*.nupkg" | |
| --api-key "${{ steps.login.outputs.NUGET_API_KEY }}" | |
| --source https://api.nuget.org/v3/index.json | |
| --skip-duplicate |