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