|
| 1 | +name: Publish .NET Tool |
| 2 | + |
| 3 | +# This workflow publishes the .NET tool to NuGet using Trusted Publishing (OIDC). |
| 4 | +# |
| 5 | +# Setup required on NuGet.org: |
| 6 | +# 1. Navigate to your package page at https://www.nuget.org/packages/Mcpb.Cli/ |
| 7 | +# 2. Go to "Manage Package" and select "Publishing" or "Trusted publishers" |
| 8 | +# 3. Click "Add" to configure a new trusted publisher |
| 9 | +# 4. Configure the GitHub Actions OIDC settings: |
| 10 | +# - Subject Repository: asklar/mcpb |
| 11 | +# - Subject Workflow: .github/workflows/publish-dotnet.yml |
| 12 | +# - Subject Environment: nuget (optional but recommended) |
| 13 | +# 5. Save the trusted publisher configuration |
| 14 | +# |
| 15 | +# Setup required in GitHub: |
| 16 | +# 1. Create an environment named "nuget" in repository settings |
| 17 | +# 2. Add protection rules if desired (e.g., required reviewers) |
| 18 | +# |
| 19 | +# The workflow will run automatically when the version in dotnet/mcpb/mcpb.csproj is changed |
| 20 | +# and pushed to the dotnet branch, or it can be triggered manually. |
| 21 | + |
| 22 | +on: |
| 23 | + workflow_dispatch: |
| 24 | + push: |
| 25 | + branches: |
| 26 | + - dotnet |
| 27 | + paths: |
| 28 | + - 'dotnet/mcpb/mcpb.csproj' |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + id-token: write |
| 33 | + |
| 34 | +jobs: |
| 35 | + publish: |
| 36 | + name: Publish to NuGet |
| 37 | + runs-on: ubuntu-latest |
| 38 | + environment: nuget |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 43 | + |
| 44 | + - name: Setup .NET |
| 45 | + uses: actions/setup-dotnet@3e891b0cb619bf60e2c25674b222b8940e2c1c25 # v4.1.0 |
| 46 | + with: |
| 47 | + dotnet-version: '8.0.x' |
| 48 | + |
| 49 | + - name: Restore dependencies |
| 50 | + run: | |
| 51 | + cd dotnet |
| 52 | + dotnet restore |
| 53 | + |
| 54 | + - name: Build |
| 55 | + run: | |
| 56 | + cd dotnet |
| 57 | + dotnet build -c Release --no-restore |
| 58 | + |
| 59 | + - name: Test |
| 60 | + run: | |
| 61 | + cd dotnet |
| 62 | + dotnet test -c Release --no-build --verbosity normal |
| 63 | + |
| 64 | + - name: Pack |
| 65 | + run: | |
| 66 | + cd dotnet/mcpb |
| 67 | + dotnet pack -c Release --no-build --output ./artifacts |
| 68 | + |
| 69 | + - name: Publish to NuGet |
| 70 | + run: | |
| 71 | + cd dotnet/mcpb |
| 72 | + dotnet nuget push ./artifacts/*.nupkg --api-key oy2p --source https://api.nuget.org/v3/index.json --skip-duplicate |
0 commit comments