-
Notifications
You must be signed in to change notification settings - Fork 260
188 lines (161 loc) · 6.4 KB
/
Copy pathsync-sample-catalog.yml
File metadata and controls
188 lines (161 loc) · 6.4 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
name: Sync Sample Catalog
on:
workflow_dispatch:
inputs:
commit_sha:
description: "Commit SHA from microsoft-foundry/foundry-samples to pin to"
required: true
type: string
# Least-privilege for the default GITHUB_TOKEN: only what `actions/checkout`
# needs. All writes (push branch + create PR) are performed via the GitHub
# App token generated below, not GITHUB_TOKEN.
permissions:
contents: read
# A single in-flight sync at a time — a re-trigger cancels any earlier run
# rather than racing it for the same PR branch.
concurrency:
group: sync-sample-catalog-${{ github.ref_name }}
cancel-in-progress: true
jobs:
sync:
runs-on: ubuntu-latest
env:
PR_LABEL_CANDIDATES: |
automated-pr
area:samples
area:hosted-agent
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- 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: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Generate sample catalog
env:
REPO_ROOT: ${{ github.workspace }}
GITHUB_TOKEN: ${{ github.token }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_DEPLOYMENT: ${{ secrets.AZURE_OPENAI_DEPLOYMENT }}
run: node .github/scripts/generate_sample_catalog.mjs "${{ inputs.commit_sha }}"
- name: Detect catalog changes
id: diff
shell: bash
run: |
set -euo pipefail
catalog_file="samples/hosted-agent/sample-catalog.json"
if [[ ! -f "$catalog_file" ]]; then
echo "Catalog file not generated."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Stage the file so git diff detects both new and modified files
git add "$catalog_file"
if git diff --cached --quiet -- "$catalog_file"; then
echo "No changes to sample catalog."
echo "has_changes=false" >> "$GITHUB_OUTPUT"
exit 0
fi
echo "Catalog has changes:"
git diff --cached --stat -- "$catalog_file"
{
echo "## Sample Catalog Sync"
echo
echo "The sample catalog was regenerated from \`microsoft-foundry/foundry-samples\`."
echo
echo "### Changed files"
echo "- \`$catalog_file\`"
} >> "$GITHUB_STEP_SUMMARY"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
- name: Resolve pull request labels
if: steps.diff.outputs.has_changes == 'true'
id: labels
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
set -euo pipefail
existing_labels=$(gh api --paginate repos/${{ github.repository }}/labels --jq '.[].name')
matched_labels=""
while IFS= read -r candidate; do
if [[ -z "$candidate" ]]; then
continue
fi
if grep -Fqx "$candidate" <<< "$existing_labels"; then
matched_labels+="$candidate"
matched_labels+=$'\n'
fi
done <<< "$PR_LABEL_CANDIDATES"
{
echo "labels<<EOF"
printf '%s' "$matched_labels"
echo
echo "EOF"
} >> "$GITHUB_OUTPUT"
- name: Generate PR branch name
if: steps.diff.outputs.has_changes == 'true'
id: branch
shell: bash
run: |
date_suffix=$(date -u +%Y%m%d)
echo "name=ci/sync-sample-catalog-${{ github.ref_name }}-${date_suffix}" >> "$GITHUB_OUTPUT"
- 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 }}
branch: ${{ steps.branch.outputs.name }}
base: ${{ github.ref_name }}
delete-branch: true
draft: always-true
commit-message: |
ci: sync sample catalog from foundry-samples (${{ github.ref_name }})
title: "ci: sync sample catalog from foundry-samples (${{ github.ref_name }})"
body: |
## Summary
This automated draft PR updates `samples/hosted-agent/sample-catalog.json` by scanning
the `microsoft-foundry/foundry-samples` repository for hosted-agent sample templates.
## What changed
- New templates added or removed based on the upstream repo structure.
- `commitSha` pinned to the upstream commit supplied via the `commit_sha` workflow input.
- `requiresModel` and `protocol` values re-derived from each sample's `agent.yaml`.
- `displayName` derived from each template's folder name; `description` LLM-generated when empty.
- PM-edited `displayName` and `description` values are preserved from the previous catalog.
## Reviewer Checks
- Confirm new templates have correct `language`, `framework`, and `protocol` values.
- Review the auto-generated `description` for any new templates.
- Confirm no PM-edited display fields were accidentally lost.
labels: ${{ steps.labels.outputs.labels }}
add-paths: |
samples/hosted-agent/sample-catalog.json
- name: Report PR result
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 "PR operation: $PR_OPERATION"
echo "PR URL: $PR_URL"
{
echo
echo "## Pull Request"
echo
if [[ -n "$PR_URL" ]]; then
echo "- Operation: \`$PR_OPERATION\`"
echo "- PR: [#${PR_NUMBER:-?}]($PR_URL)"
else
echo "- No pull request was created or updated (peter-evans/create-pull-request returned no URL)."
fi
} >> "$GITHUB_STEP_SUMMARY"