-
Notifications
You must be signed in to change notification settings - Fork 256
279 lines (242 loc) · 9.07 KB
/
Copy pathsync-microsoft-foundry.yml
File metadata and controls
279 lines (242 loc) · 9.07 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
name: Sync microsoft-foundry canvas
on:
workflow_dispatch:
inputs:
source_ref:
description: "Branch, tag, or commit from SmallBlackHole/foundry-agent-canvas"
required: true
default: "main"
type: string
marketplace_version:
description: "Optional new marketplace version using stable X.Y.Z format"
required: false
type: string
permissions:
contents: read
env:
CANVAS_SOURCE_REF: ${{ inputs.source_ref || 'main' }}
MARKETPLACE_VERSION: ${{ inputs.marketplace_version || '' }}
concurrency:
group: sync-microsoft-foundry
cancel-in-progress: false
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
source_sha: ${{ steps.source.outputs.sha }}
source_short_sha: ${{ steps.source.outputs.short_sha }}
steps:
- name: Checkout canvas source
uses: actions/checkout@v4
with:
repository: SmallBlackHole/foundry-agent-canvas
ref: ${{ env.CANVAS_SOURCE_REF }}
path: source
persist-credentials: false
- name: Resolve source commit
id: source
working-directory: source
shell: bash
run: |
set -euo pipefail
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
echo "short_sha=$(git rev-parse --short=12 HEAD)" >> "$GITHUB_OUTPUT"
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.19"
- name: Install dependencies
working-directory: source
run: npm ci
- name: Run tests
working-directory: source
run: npm test
- name: Build package
working-directory: source
shell: bash
env:
FOUNDRY_CANVAS_APPINSIGHTS_CONNECTION_STRING: ${{ secrets.FOUNDRY_CANVAS_APPINSIGHTS_CONNECTION_STRING }}
run: |
set -euo pipefail
if [[ -z "$FOUNDRY_CANVAS_APPINSIGHTS_CONNECTION_STRING" ]]; then
echo "::error::FOUNDRY_CANVAS_APPINSIGHTS_CONNECTION_STRING is not configured"
exit 1
fi
npm run package
node <<'NODE'
const { readFileSync } = require("node:fs");
const connectionString =
process.env.FOUNDRY_CANVAS_APPINSIGHTS_CONNECTION_STRING || "";
const encoded = Buffer.from(connectionString, "utf8").toString("base64");
const bundle = readFileSync("dist/pkg/extension.mjs", "utf8");
if (!encoded || !bundle.includes(encoded)) {
throw new Error("Packaged extension is missing the bundled telemetry configuration");
}
if (bundle.includes(connectionString)) {
throw new Error("Packaged extension contains the raw telemetry connection string");
}
NODE
- name: Validate package
working-directory: source
shell: bash
run: |
set -euo pipefail
test -f dist/pkg/extension.mjs
test -f dist/pkg/package.json
test -d dist/pkg/public
test -d dist/pkg/inspector-ui
node --check dist/pkg/extension.mjs
- name: Upload runtime package
uses: actions/upload-artifact@v4
with:
name: microsoft-foundry-${{ steps.source.outputs.short_sha }}
path: |
source/dist/pkg/extension.mjs
source/dist/pkg/package.json
source/dist/pkg/public
source/dist/pkg/inspector-ui
if-no-files-found: error
retention-days: 3
publish:
needs: build
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout workflow automation
uses: actions/checkout@v4
with:
ref: ${{ github.sha }}
path: automation
persist-credentials: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20.19"
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.SYNC_APP_ID }}
private-key: ${{ secrets.SYNC_APP_PRIVATE_KEY }}
- name: Checkout foundry-toolkit
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
ref: main
fetch-depth: 0
path: target
persist-credentials: false
- name: Download runtime package
uses: actions/download-artifact@v4
with:
name: microsoft-foundry-${{ needs.build.outputs.source_short_sha }}
path: bundle
- name: Sync runtime package
run: |
node automation/.github/scripts/sync_microsoft_foundry.mjs \
bundle \
target/microsoft-foundry/extensions/microsoft-foundry \
target/microsoft-foundry/.github/plugin/plugin.json \
"$MARKETPLACE_VERSION"
- name: Resolve pull request metadata
id: metadata
shell: bash
env:
SOURCE_SHORT_SHA: ${{ needs.build.outputs.source_short_sha }}
run: |
set -euo pipefail
if [[ -n "$MARKETPLACE_VERSION" ]]; then
branch_suffix="v$MARKETPLACE_VERSION"
title="chore: sync microsoft-foundry v$MARKETPLACE_VERSION"
version_label="$MARKETPLACE_VERSION"
else
branch_suffix="$SOURCE_SHORT_SHA"
title="chore: sync microsoft-foundry ($SOURCE_SHORT_SHA)"
version_label="unchanged"
fi
{
echo "branch_suffix=$branch_suffix"
echo "title=$title"
echo "version_label=$version_label"
} >> "$GITHUB_OUTPUT"
- name: Detect package changes
id: diff
shell: bash
run: |
set -euo pipefail
git -C target add -- \
microsoft-foundry/.github/plugin/plugin.json \
microsoft-foundry/extensions/microsoft-foundry/extension.mjs \
microsoft-foundry/extensions/microsoft-foundry/package.json \
microsoft-foundry/extensions/microsoft-foundry/public \
microsoft-foundry/extensions/microsoft-foundry/inspector-ui
if git -C target diff --cached --quiet -- microsoft-foundry; then
echo "No package changes detected."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git -C target diff --cached --stat -- microsoft-foundry
echo "has_changes=true" >> "$GITHUB_OUTPUT"
{
echo "## Sync microsoft-foundry canvas"
echo
echo "- Source: \`SmallBlackHole/foundry-agent-canvas@${{ needs.build.outputs.source_sha }}\`"
echo "- Marketplace version: \`${{ steps.metadata.outputs.version_label }}\`"
echo
echo "### Changed files"
echo
echo '```text'
git -C target diff --cached --name-status -- microsoft-foundry
echo '```'
} >> "$GITHUB_STEP_SUMMARY"
- name: Create draft pull request
if: steps.diff.outputs.has_changes == 'true'
id: cpr
uses: peter-evans/create-pull-request@v8
with:
token: ${{ steps.app-token.outputs.token }}
path: target
base: main
branch: bot/sync-microsoft-foundry-${{ steps.metadata.outputs.branch_suffix }}
delete-branch: true
draft: always-true
commit-message: ${{ steps.metadata.outputs.title }}
title: ${{ steps.metadata.outputs.title }}
body: |
## Summary
This automated draft PR updates the bundled Microsoft Foundry runtime.
## Source
- Repository: `SmallBlackHole/foundry-agent-canvas`
- Requested ref: `${{ env.CANVAS_SOURCE_REF }}`
- Resolved commit: `${{ needs.build.outputs.source_sha }}`
- Marketplace version: `${{ steps.metadata.outputs.version_label }}`
- Workflow run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
## Validation
- `npm ci`
- `npm test`
- Telemetry-enabled `npm run package`
- `node --check dist/pkg/extension.mjs`
add-paths: |
microsoft-foundry/.github/plugin/plugin.json
microsoft-foundry/extensions/microsoft-foundry/extension.mjs
microsoft-foundry/extensions/microsoft-foundry/package.json
microsoft-foundry/extensions/microsoft-foundry/public
microsoft-foundry/extensions/microsoft-foundry/inspector-ui
- name: Report pull request
if: steps.diff.outputs.has_changes == 'true'
shell: bash
env:
PR_OPERATION: ${{ steps.cpr.outputs.pull-request-operation }}
PR_URL: ${{ steps.cpr.outputs.pull-request-url }}
PR_NUMBER: ${{ steps.cpr.outputs.pull-request-number }}
run: |
{
echo
echo "## Pull Request"
echo
echo "- Operation: \`${PR_OPERATION:-unknown}\`"
echo "- PR: [#${PR_NUMBER:-?}](${PR_URL})"
} >> "$GITHUB_STEP_SUMMARY"