Skip to content

Commit 64fbe3f

Browse files
authored
Merge pull request #2 from AzureCosmosDB/copilot/add-validation-workflow
Add per-language validation workflow and branch ruleset recommendations
2 parents c605e8f + 4a11a96 commit 64fbe3f

2 files changed

Lines changed: 157 additions & 0 deletions

File tree

‎.github/workflows/validate.yml‎

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
name: Validate Samples
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
validate-structure:
18+
name: Validate Sample Structure
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v4
23+
- name: Validate naming and README presence
24+
run: |
25+
for dir in python javascript java dotnet go; do
26+
[ -d "$dir" ] || continue
27+
for sample in "$dir"/*/; do
28+
name=$(basename "$sample")
29+
if ! [[ "$name" =~ ^[0-9]{3}-[a-z0-9]+(-[a-z0-9]+)*$ ]]; then
30+
echo "::error::$name does not follow NNN-kebab-case naming"
31+
exit 1
32+
fi
33+
if [ ! -f "${sample}README.md" ]; then
34+
echo "::error::$name is missing README.md"
35+
exit 1
36+
fi
37+
done
38+
done
39+
40+
validate-python:
41+
name: Validate Python Samples
42+
runs-on: ubuntu-latest
43+
strategy:
44+
fail-fast: false
45+
steps:
46+
- name: Checkout repository
47+
uses: actions/checkout@v4
48+
- name: Set up Python
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: '3.12'
52+
- name: Install dependencies
53+
run: |
54+
[ -d python ] || exit 0
55+
for sample in python/*/; do
56+
[ -f "${sample}requirements.txt" ] && pip install -r "${sample}requirements.txt" -q
57+
done
58+
- name: Run tests
59+
run: |
60+
[ -d python ] || exit 0
61+
for sample in python/*/; do
62+
python -m pytest "$sample" -q || find "$sample" -name '*.py' -exec python -m py_compile {} +
63+
done
64+
65+
validate-javascript:
66+
name: Validate JavaScript/TypeScript Samples
67+
runs-on: ubuntu-latest
68+
strategy:
69+
fail-fast: false
70+
steps:
71+
- name: Checkout repository
72+
uses: actions/checkout@v4
73+
- name: Set up Node.js
74+
uses: actions/setup-node@v4
75+
with:
76+
node-version: '20'
77+
- name: Install and test
78+
run: |
79+
[ -d javascript ] || exit 0
80+
for sample in javascript/*/; do
81+
[ -f "${sample}package.json" ] || continue
82+
npm install --prefix "$sample" --silent
83+
npm test --prefix "$sample" --if-present
84+
done
85+
86+
validate-java:
87+
name: Validate Java Samples
88+
runs-on: ubuntu-latest
89+
strategy:
90+
fail-fast: false
91+
steps:
92+
- name: Checkout repository
93+
uses: actions/checkout@v4
94+
- name: Set up Java
95+
uses: actions/setup-java@v4
96+
with:
97+
distribution: microsoft
98+
java-version: '21'
99+
- name: Build and test
100+
run: |
101+
[ -d java ] || exit 0
102+
for sample in java/*/; do
103+
if [ -f "${sample}pom.xml" ]; then
104+
mvn -q --no-transfer-progress test -f "${sample}pom.xml"
105+
elif [ -f "${sample}build.gradle" ] || [ -f "${sample}build.gradle.kts" ]; then
106+
(cd "$sample" && gradle test --no-daemon -q)
107+
fi
108+
done
109+
110+
validate-dotnet:
111+
name: Validate .NET Samples
112+
runs-on: ubuntu-latest
113+
strategy:
114+
fail-fast: false
115+
steps:
116+
- name: Checkout repository
117+
uses: actions/checkout@v4
118+
- name: Set up .NET
119+
uses: actions/setup-dotnet@v4
120+
with:
121+
dotnet-version: '9.0'
122+
- name: Build
123+
run: |
124+
[ -d dotnet ] || exit 0
125+
for sample in dotnet/*/; do
126+
proj=$(find "$sample" -maxdepth 2 \( -name '*.sln' -o -name '*.csproj' \) | head -1)
127+
[ -n "$proj" ] && dotnet build "$proj" --configuration Release -q
128+
done
129+
130+
validate-go:
131+
name: Validate Go Samples
132+
runs-on: ubuntu-latest
133+
strategy:
134+
fail-fast: false
135+
steps:
136+
- name: Checkout repository
137+
uses: actions/checkout@v4
138+
- name: Set up Go
139+
uses: actions/setup-go@v5
140+
with:
141+
go-version: '1.22'
142+
- name: Build and test
143+
run: |
144+
[ -d go ] || exit 0
145+
for sample in go/*/; do
146+
[ -f "${sample}go.mod" ] || continue
147+
(cd "$sample" && go build ./... && go test ./...)
148+
done

‎readme.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ Each sample folder is prefixed with a three-digit number that indicates its cate
3838
| `300–399` | **Patterns** | Common application patterns and best practices |
3939
| `400–499` | **Advanced** | Advanced scenarios including AI and vector search integrations |
4040
| `500–599` | **Vertical integration** | End-to-end vertical integration scenarios |
41+
42+
43+
## Validation
44+
45+
Every pull request and push to `main` runs the [validation workflow](.github/workflows/validate.yml), which enforces two things:
46+
47+
- **Sample structure** — all sample directories must follow the `NNN-kebab-case-name` naming convention (e.g. `001-quickstart`) and include a `README.md`.
48+
- **Language correctness** — changes under a language root folder (`python/`, `javascript/`, `java/`, `dotnet/`, `go/`) trigger the corresponding build and test job for that language only. Unmodified languages are skipped.
49+
One stop repo for all Azure Cosmos DB samples.

0 commit comments

Comments
 (0)