|
| 1 | +name: Publish to NuGet |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + package: |
| 7 | + description: 'Package to publish' |
| 8 | + required: true |
| 9 | + type: choice |
| 10 | + options: |
| 11 | + - All |
| 12 | + - NLog.Extensions.AzureBlobStorage |
| 13 | + - NLog.Extensions.AzureDataTables |
| 14 | + - NLog.Extensions.AzureQueueStorage |
| 15 | + - NLog.Extensions.AzureEventGrid |
| 16 | + - NLog.Extensions.AzureEventHub |
| 17 | + - NLog.Extensions.AzureServiceBus |
| 18 | + run_id: |
| 19 | + description: 'CI workflow run ID to publish from (leave empty for latest successful run on master)' |
| 20 | + required: false |
| 21 | + type: string |
| 22 | + dry_run: |
| 23 | + description: 'Dry run (skip actual publish)' |
| 24 | + required: false |
| 25 | + type: boolean |
| 26 | + default: false |
| 27 | + |
| 28 | +permissions: |
| 29 | + contents: read |
| 30 | + actions: read # Required to download artifacts from other workflows |
| 31 | + id-token: write # Required for Trusted Publishing OIDC token |
| 32 | + |
| 33 | +jobs: |
| 34 | + publish: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + |
| 37 | + steps: |
| 38 | + - name: Get CI run ID |
| 39 | + id: get-run-id |
| 40 | + env: |
| 41 | + GH_TOKEN: ${{ github.token }} |
| 42 | + run: | |
| 43 | + if [ -n "${{ inputs.run_id }}" ]; then |
| 44 | + echo "run_id=${{ inputs.run_id }}" >> $GITHUB_OUTPUT |
| 45 | + echo "Using provided run ID: ${{ inputs.run_id }}" |
| 46 | + else |
| 47 | + # Get latest successful CI run on master |
| 48 | + RUN_ID=$(gh api repos/${{ github.repository }}/actions/workflows/ci.yml/runs --jq '[.workflow_runs[] | select(.conclusion == "success" and .head_branch == "master")] | .[0].id') |
| 49 | + if [ -z "$RUN_ID" ] || [ "$RUN_ID" = "null" ]; then |
| 50 | + echo "ERROR: No successful CI runs found on master branch." >&2 |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT |
| 54 | + echo "Using latest successful CI run: $RUN_ID" |
| 55 | + fi |
| 56 | +
|
| 57 | + - name: Download NLog.Extensions.AzureBlobStorage |
| 58 | + if: inputs.package == 'All' || inputs.package == 'NLog.Extensions.AzureBlobStorage' |
| 59 | + uses: actions/download-artifact@v4 |
| 60 | + with: |
| 61 | + name: package-NLog.Extensions.AzureBlobStorage |
| 62 | + path: packages |
| 63 | + github-token: ${{ github.token }} |
| 64 | + run-id: ${{ steps.get-run-id.outputs.run_id }} |
| 65 | + |
| 66 | + - name: Download NLog.Extensions.AzureDataTables |
| 67 | + if: inputs.package == 'All' || inputs.package == 'NLog.Extensions.AzureDataTables' |
| 68 | + uses: actions/download-artifact@v4 |
| 69 | + with: |
| 70 | + name: package-NLog.Extensions.AzureDataTables |
| 71 | + path: packages |
| 72 | + github-token: ${{ github.token }} |
| 73 | + run-id: ${{ steps.get-run-id.outputs.run_id }} |
| 74 | + |
| 75 | + - name: Download NLog.Extensions.AzureQueueStorage |
| 76 | + if: inputs.package == 'All' || inputs.package == 'NLog.Extensions.AzureQueueStorage' |
| 77 | + uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: package-NLog.Extensions.AzureQueueStorage |
| 80 | + path: packages |
| 81 | + github-token: ${{ github.token }} |
| 82 | + run-id: ${{ steps.get-run-id.outputs.run_id }} |
| 83 | + |
| 84 | + - name: Download NLog.Extensions.AzureEventGrid |
| 85 | + if: inputs.package == 'All' || inputs.package == 'NLog.Extensions.AzureEventGrid' |
| 86 | + uses: actions/download-artifact@v4 |
| 87 | + with: |
| 88 | + name: package-NLog.Extensions.AzureEventGrid |
| 89 | + path: packages |
| 90 | + github-token: ${{ github.token }} |
| 91 | + run-id: ${{ steps.get-run-id.outputs.run_id }} |
| 92 | + |
| 93 | + - name: Download NLog.Extensions.AzureEventHub |
| 94 | + if: inputs.package == 'All' || inputs.package == 'NLog.Extensions.AzureEventHub' |
| 95 | + uses: actions/download-artifact@v4 |
| 96 | + with: |
| 97 | + name: package-NLog.Extensions.AzureEventHub |
| 98 | + path: packages |
| 99 | + github-token: ${{ github.token }} |
| 100 | + run-id: ${{ steps.get-run-id.outputs.run_id }} |
| 101 | + |
| 102 | + - name: Download NLog.Extensions.AzureServiceBus |
| 103 | + if: inputs.package == 'All' || inputs.package == 'NLog.Extensions.AzureServiceBus' |
| 104 | + uses: actions/download-artifact@v4 |
| 105 | + with: |
| 106 | + name: package-NLog.Extensions.AzureServiceBus |
| 107 | + path: packages |
| 108 | + github-token: ${{ github.token }} |
| 109 | + run-id: ${{ steps.get-run-id.outputs.run_id }} |
| 110 | + - name: List packages to publish |
| 111 | + run: | |
| 112 | + echo "Packages to publish:" |
| 113 | + if [ ! -d "packages" ]; then |
| 114 | + echo "ERROR: packages directory does not exist. Artifact download may have failed." >&2 |
| 115 | + exit 1 |
| 116 | + fi |
| 117 | + PACKAGES=$(find packages -name "*.nupkg" -type f) |
| 118 | + if [ -z "$PACKAGES" ]; then |
| 119 | + echo "ERROR: No .nupkg files found in packages directory. Check that artifacts were downloaded correctly." >&2 |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | + echo "$PACKAGES" | while read f; do echo " - $(basename $f)"; done |
| 123 | +
|
| 124 | + - name: Setup .NET |
| 125 | + uses: actions/setup-dotnet@v4 |
| 126 | + with: |
| 127 | + dotnet-version: '8.0.x' |
| 128 | + |
| 129 | + # Trusted Publishing - no long-lived API key needed! |
| 130 | + # Uses OIDC to get a temporary token. Requires one-time setup on nuget.org. |
| 131 | + - name: Authenticate with NuGet (Trusted Publishing) |
| 132 | + if: inputs.dry_run == false |
| 133 | + id: nuget-login |
| 134 | + uses: nuget/login@v1 |
| 135 | + with: |
| 136 | + user: ${{ secrets.NUGET_USER }} |
| 137 | + |
| 138 | + - name: Push to NuGet |
| 139 | + if: inputs.dry_run == false |
| 140 | + run: dotnet nuget push 'packages/*.nupkg' --api-key "${{ steps.nuget-login.outputs.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate |
| 141 | + |
| 142 | + - name: Dry run summary |
| 143 | + if: inputs.dry_run == true |
| 144 | + run: | |
| 145 | + echo "DRY RUN - Would push the following packages to NuGet.org:" |
| 146 | + if [ ! -d "packages" ]; then |
| 147 | + echo "ERROR: packages directory does not exist. Artifact download may have failed." >&2 |
| 148 | + exit 1 |
| 149 | + fi |
| 150 | + PACKAGES=$(find packages -name "*.nupkg" -type f) |
| 151 | + if [ -z "$PACKAGES" ]; then |
| 152 | + echo "ERROR: No .nupkg files found in packages directory. Check that artifacts were downloaded correctly." >&2 |
| 153 | + exit 1 |
| 154 | + fi |
| 155 | + echo "$PACKAGES" | while read f; do echo " - $(basename $f)"; done |
0 commit comments