Repository navigation
181 lines (158 loc) · 7.58 KB
/
Copy pathsquad-agents-ai-release.yml
File metadata and controls
181 lines (158 loc) · 7.58 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Publishes Squad.Agents.AI to NuGet.org via Trusted Publishing (OIDC).
#
# ## Authentication
# No long-lived API key is stored. The job uses GitHub Actions OIDC to obtain a
# short-lived (1 hour) NuGet API key via the NuGet/login@v1 action. A Trusted
# Publishing policy must be configured at https://www.nuget.org/account/trusted-publishing
# under the package owner (Squad organization) with:
# Repository Owner: github
# Repository: squad
# Workflow File: squad-agents-ai-release.yml
# Environment: (leave empty)
# Set repository variable NUGET_USER to the nuget.org profile name that should
# perform the token exchange (a member of the Squad org). Use a variable, not a
# secret — the username is non-sensitive.
#
# ## Failure recovery
# Publishing is branch-driven: dev creates prerelease NuGet packages, main creates stable NuGet
# packages, and workflow_dispatch remains an escape hatch. PACKAGE_VERSION is resolved once
# before build/test/pack/push and the nupkgs/* artifacts are uploaded before the registry write.
# If a run is interrupted after NuGet accepted the package but before the workflow completes,
# rerun the same workflow/run: NuGet package versions are immutable and `--skip-duplicate`
# turns already-published packages into no-ops while retrying anything not yet published.
# `cancel-in-progress: false` prevents a recovery rerun from canceling an in-flight publish.
# Dev prereleases use github.run_number in the prerelease field because it is monotonically
# increasing per workflow and participates in NuGet/SemVer ordering; reruns keep the same
# version intentionally, and `--skip-duplicate` makes that safe.
name: Squad.Agents.AI NuGet Release
on:
workflow_dispatch:
inputs:
version:
description: 'Optional NuGet package version override, for example 0.1.0-preview.123'
required: false
type: string
push:
branches:
- dev
- main
paths:
- 'src/Squad.Agents.AI/**'
- 'Directory.*.props'
- 'global.json'
permissions:
contents: read
jobs:
publish:
name: Pack and publish NuGet package
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for OIDC token issuance to NuGet/login
concurrency:
group: squad-agents-ai-release-${{ github.ref }}
cancel-in-progress: false
env:
DOTNET_CLI_TELEMETRY_OPTOUT: '1'
DOTNET_NOLOGO: '1'
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 #v7
with:
fetch-depth: 0
- name: Setup .NET SDK
uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 #v6.1.0
with:
dotnet-version: '10.0.x'
- name: Resolve package version
id: version
shell: bash
run: |
set -euo pipefail
project_file="src/Squad.Agents.AI/Squad.Agents.AI.csproj"
csproj_version="$(sed -nE 's/^[[:space:]]*<Version>([^<]+)<\/Version>[[:space:]]*$/\1/p' "${project_file}" | head -n 1)"
manual_version="${{ inputs.version }}"
version_source=""
if [[ "${GITHUB_EVENT_NAME}" == "workflow_dispatch" && -n "${manual_version}" ]]; then
package_version="${manual_version}"
version_source="workflow_dispatch input"
else
if [[ -z "${csproj_version}" ]]; then
echo "::error::Could not find <Version> in ${project_file}."
exit 1
fi
case "${GITHUB_REF_NAME}" in
main)
# Stable releases mirror the Squad CLI's release workflow: the maintainer bumps
# the source version before merge, and the workflow publishes that exact version.
package_version="${csproj_version}"
version_source="${project_file}"
if [[ "${package_version}" == *-* ]]; then
echo "::error::main publishes stable packages; ${project_file} has prerelease version '${package_version}'. Bump it before merging."
exit 1
fi
;;
dev)
# The Squad CLI derives prereleases from the source version plus commit identity.
# For NuGet, build metadata does not give consumers monotonic prerelease ordering,
# so use github.run_number in the prerelease field instead.
stable_base="${csproj_version%%+*}"
stable_base="${stable_base%%-*}"
package_version="${stable_base}-preview.${GITHUB_RUN_NUMBER}"
version_source="${project_file} + github.run_number"
;;
*)
echo "::error::workflow_dispatch without a version input must run on dev or main; current ref is '${GITHUB_REF_NAME}'."
exit 1
;;
esac
fi
if [[ -z "${package_version}" ]]; then
echo "::error::PACKAGE_VERSION resolved to empty."
exit 1
fi
if [[ ! "${package_version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
echo "::error::PACKAGE_VERSION '${package_version}' from ${version_source} is not a SemVer 2.0 version."
exit 1
fi
echo "PACKAGE_VERSION=${package_version}" >> "${GITHUB_OUTPUT}"
echo "Resolved PACKAGE_VERSION=${package_version} (${version_source})"
- name: Verify NUGET_USER variable
shell: bash
env:
NUGET_USER: ${{ vars.NUGET_USER }}
run: |
set -euo pipefail
if [[ -z "${NUGET_USER}" ]]; then
echo "::error::Missing repository variable NUGET_USER. Set it under Settings → Secrets and variables → Actions → Variables to the nuget.org profile name (NOT email) of a Squad org member that will perform the OIDC token exchange. Configure the matching Trusted Publishing policy at https://www.nuget.org/account/trusted-publishing."
exit 1
fi
- name: Restore package
run: dotnet restore src/Squad.Agents.AI/Squad.Agents.AI.csproj
- name: Restore tests
run: dotnet restore test/Squad.Agents.AI.Tests/Squad.Agents.AI.Tests.csproj
- name: Build package
run: dotnet build src/Squad.Agents.AI/Squad.Agents.AI.csproj -c Release --no-restore -p:Version=${{ steps.version.outputs.PACKAGE_VERSION }}
- name: Build tests
run: dotnet build test/Squad.Agents.AI.Tests/Squad.Agents.AI.Tests.csproj -c Release --no-restore -p:Version=${{ steps.version.outputs.PACKAGE_VERSION }}
- name: Test
run: dotnet test test/Squad.Agents.AI.Tests/Squad.Agents.AI.Tests.csproj -c Release --no-build
- name: Pack
run: dotnet pack src/Squad.Agents.AI/Squad.Agents.AI.csproj -c Release --no-build -o nupkgs -p:Version=${{ steps.version.outputs.PACKAGE_VERSION }}
- name: Upload NuGet package artifacts
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 #v7
with:
name: squad-agents-ai-nupkgs-${{ steps.version.outputs.PACKAGE_VERSION }}
path: nupkgs/*
if-no-files-found: ignore
- name: NuGet login (OIDC → temp API key)
id: nuget-login
uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 #v1
with:
user: ${{ vars.NUGET_USER }}
- name: Push to NuGet.org
shell: bash
env:
NUGET_TEMP_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
run: dotnet nuget push nupkgs/*.nupkg --source https://api.nuget.org/v3/index.json --api-key "${NUGET_TEMP_KEY}" --skip-duplicate