Skip to content

Commit dc09cc4

Browse files
committed
review fixes
1 parent b30f99c commit dc09cc4

7 files changed

Lines changed: 45 additions & 12 deletions

File tree

.github/workflows/extract.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: Extract Snippets
33
on:
44
push:
55
branches: [main]
6+
pull_request:
7+
paths:
8+
- "samples/**"
9+
- "scripts/**"
10+
- "placeholder-map.yaml"
611
workflow_dispatch:
712

813
permissions:
@@ -36,13 +41,20 @@ jobs:
3641
working-directory: scripts
3742
run: yarn validate
3843

44+
- name: Verify no drift (PR only)
45+
if: github.event_name == 'pull_request'
46+
run: |
47+
git diff --exit-code snippets.json snippet-manifest.yaml || \
48+
(echo "::error::Extracted artifacts are out of date. Run 'cd scripts && yarn all' and commit the results." && exit 1)
49+
3950
- name: Check for changes
4051
id: diff
52+
if: github.event_name == 'push'
4153
run: |
4254
git diff --quiet snippets.json snippet-manifest.yaml || echo "changed=true" >> "$GITHUB_OUTPUT"
4355
4456
- name: Commit updated artifacts
45-
if: steps.diff.outputs.changed == 'true'
57+
if: github.event_name == 'push' && steps.diff.outputs.changed == 'true'
4658
run: |
4759
git config user.name "github-actions[bot]"
4860
git config user.email "github-actions[bot]@users.noreply.github.com"

samples/react/login-pkce/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Minimal React app demonstrating OIDC login using Authorization Code + PKCE via `
55
## Setup
66

77
1. Copy `.env.example` to `.env` and fill in your SecureAuth values
8-
2. `npm install`
9-
3. `npm run dev`
8+
2. `yarn install`
9+
3. `yarn dev`
1010
4. Open http://localhost:3000
1111

1212
## What this demonstrates

samples/react/login-pkce/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ function AuthButtons() {
3030
return (
3131
<div>
3232
<p>Welcome, {auth.user?.profile.name}</p>
33-
<button onClick={() => auth.removeUser()}>Sign out</button>
33+
<button onClick={() => auth.signoutRedirect()}>Sign out</button>
3434
</div>
3535
);
3636
}

samples/react/manifest.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ scenarios:
1919
- label: "Redirect URI"
2020
value: "{{REDIRECT_URI}}"
2121
- label: "Scopes"
22-
value: "openid profile email"
22+
value: "{{SCOPES}}"
2323
- label: "Grant"
2424
value: "Authorization Code + PKCE"

scripts/aggregate-manifests.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { readFileSync, writeFileSync } from "fs";
22
import { glob } from "glob";
33
import yaml from "js-yaml";
44
import path from "path";
5+
import { fileURLToPath } from "url";
56

67
interface ConfigRow {
78
label: string;
@@ -31,7 +32,7 @@ interface AggregatedScenario extends ScenarioManifest {
3132
frameworks: string[];
3233
}
3334

34-
const ROOT = path.resolve(import.meta.dirname, "..");
35+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
3536
const SAMPLES = path.join(ROOT, "samples");
3637

3738
async function main() {

scripts/extract-snippets.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { readFileSync, writeFileSync } from "fs";
22
import { glob } from "glob";
33
import yaml from "js-yaml";
44
import path from "path";
5+
import { fileURLToPath } from "url";
56

67
interface PlaceholderMapping {
78
pattern: string;
@@ -39,7 +40,7 @@ interface FrameworkManifest {
3940
scenarios: Record<string, unknown>;
4041
}
4142

42-
const ROOT = path.resolve(import.meta.dirname, "..");
43+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
4344
const SAMPLES = path.join(ROOT, "samples");
4445
const TAG_START = /\/\/\s*@snippet:step(\d+):start/;
4546
const TAG_END = /\/\/\s*@snippet:step(\d+):end/;
@@ -113,6 +114,12 @@ function extractStepsFromFile(
113114

114115
const endMatch = line.match(TAG_END);
115116
if (endMatch && currentStep !== null) {
117+
const endStep = parseInt(endMatch[1], 10);
118+
if (endStep !== currentStep) {
119+
throw new Error(
120+
`Mismatched snippet end tag in ${filePath}:${i + 1}. Expected @snippet:step${currentStep}:end but found @snippet:step${endStep}:end.`
121+
);
122+
}
116123
const code = applyPlaceholders(currentLines.join("\n"), lang, placeholderMap);
117124
steps.push({
118125
step: currentStep,

scripts/validate-structure.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ import { existsSync, readFileSync } from "fs";
22
import { glob } from "glob";
33
import yaml from "js-yaml";
44
import path from "path";
5+
import { fileURLToPath } from "url";
56

67
interface FrameworkManifest {
78
framework: string;
89
scenarios: Record<string, unknown>;
910
}
1011

11-
const ROOT = path.resolve(import.meta.dirname, "..");
12+
const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
1213
const SAMPLES = path.join(ROOT, "samples");
13-
const TAG_PATTERN = /@snippet:step\d+:start/;
14+
const TAG_START = /@snippet:step(\d+):start/g;
15+
const TAG_END = /@snippet:step(\d+):end/g;
1416

1517
let errors = 0;
1618

@@ -51,9 +53,20 @@ async function main() {
5153
let hasSnippetTag = false;
5254
for (const file of sourceFiles) {
5355
const fileContent = readFileSync(path.join(scenarioDir, file), "utf-8");
54-
if (TAG_PATTERN.test(fileContent)) {
55-
hasSnippetTag = true;
56-
break;
56+
const starts = [...fileContent.matchAll(TAG_START)].map((m) => parseInt(m[1], 10));
57+
const ends = [...fileContent.matchAll(TAG_END)].map((m) => parseInt(m[1], 10));
58+
59+
if (starts.length > 0) hasSnippetTag = true;
60+
61+
for (const step of starts) {
62+
if (!ends.includes(step)) {
63+
error(`Missing @snippet:step${step}:end in samples/${manifest.framework}/${dirName}/${file}`);
64+
}
65+
}
66+
for (const step of ends) {
67+
if (!starts.includes(step)) {
68+
error(`Missing @snippet:step${step}:start in samples/${manifest.framework}/${dirName}/${file}`);
69+
}
5770
}
5871
}
5972

0 commit comments

Comments
 (0)