@surfaice/action 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +64 -0
- package/action.yml +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +91 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 surfaiceai
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# @surfaice/action
|
|
2
|
+
|
|
3
|
+
GitHub Action for detecting UI drift using Surfaice — automatically catch when your live UI diverges from committed `.surfaice.md` manifests.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```yaml
|
|
8
|
+
# .github/workflows/ui-drift.yml
|
|
9
|
+
name: UI Drift Check
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
pull_request:
|
|
13
|
+
push:
|
|
14
|
+
branches: [main]
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
surfaice:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
|
|
22
|
+
# Start your app (or use a preview URL)
|
|
23
|
+
- name: Start app
|
|
24
|
+
run: pnpm dev &
|
|
25
|
+
|
|
26
|
+
- name: Wait for app
|
|
27
|
+
run: npx wait-on http://localhost:3000
|
|
28
|
+
|
|
29
|
+
- name: Check for UI drift
|
|
30
|
+
uses: surfaiceai/surfaice/packages/action@main
|
|
31
|
+
with:
|
|
32
|
+
base-url: 'http://localhost:3000'
|
|
33
|
+
surfaice-dir: 'surfaice/'
|
|
34
|
+
fail-on-drift: 'true'
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Inputs
|
|
38
|
+
|
|
39
|
+
| Input | Required | Default | Description |
|
|
40
|
+
|-------|----------|---------|-------------|
|
|
41
|
+
| `base-url` | ✅ | — | Base URL of the running app |
|
|
42
|
+
| `surfaice-dir` | | `surfaice/` | Directory with `.surfaice.md` files |
|
|
43
|
+
| `fail-on-drift` | | `true` | Fail the action if drift is detected |
|
|
44
|
+
| `output-format` | | `text` | Output format: `text` or `json` |
|
|
45
|
+
|
|
46
|
+
## Outputs
|
|
47
|
+
|
|
48
|
+
| Output | Description |
|
|
49
|
+
|--------|-------------|
|
|
50
|
+
| `drift-detected` | `"true"` or `"false"` |
|
|
51
|
+
| `drift-summary` | Human-readable summary of drift |
|
|
52
|
+
| `diff-json` | JSON-encoded diff results |
|
|
53
|
+
|
|
54
|
+
## Workflow with Surfaice CLI
|
|
55
|
+
|
|
56
|
+
```yaml
|
|
57
|
+
- name: Export UI manifests
|
|
58
|
+
run: npx @surfaice/cli export -u http://localhost:3000 -r /settings /dashboard
|
|
59
|
+
|
|
60
|
+
- name: Commit if changed
|
|
61
|
+
run: |
|
|
62
|
+
git add surfaice/
|
|
63
|
+
git diff --staged --quiet || git commit -m "chore: update surfaice manifests"
|
|
64
|
+
```
|
package/action.yml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: 'Surfaice UI Drift Check'
|
|
2
|
+
description: 'Detect UI drift by comparing committed .surfaice.md files against a live app'
|
|
3
|
+
author: 'surfaiceai'
|
|
4
|
+
|
|
5
|
+
inputs:
|
|
6
|
+
base-url:
|
|
7
|
+
description: 'Base URL of the running app (e.g. https://preview.myapp.com)'
|
|
8
|
+
required: true
|
|
9
|
+
surfaice-dir:
|
|
10
|
+
description: 'Directory containing committed .surfaice.md files'
|
|
11
|
+
required: false
|
|
12
|
+
default: 'surfaice/'
|
|
13
|
+
fail-on-drift:
|
|
14
|
+
description: 'Fail the action if drift is detected'
|
|
15
|
+
required: false
|
|
16
|
+
default: 'true'
|
|
17
|
+
output-format:
|
|
18
|
+
description: 'Output format: "text" or "json"'
|
|
19
|
+
required: false
|
|
20
|
+
default: 'text'
|
|
21
|
+
|
|
22
|
+
outputs:
|
|
23
|
+
drift-detected:
|
|
24
|
+
description: 'Whether UI drift was detected ("true" or "false")'
|
|
25
|
+
drift-summary:
|
|
26
|
+
description: 'Human-readable summary of drift (e.g. "2 added, 1 changed")'
|
|
27
|
+
diff-json:
|
|
28
|
+
description: 'JSON-encoded diff results array'
|
|
29
|
+
|
|
30
|
+
runs:
|
|
31
|
+
using: 'node20'
|
|
32
|
+
main: 'dist/index.js'
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @surfaice/action — GitHub Action entry point
|
|
3
|
+
*/
|
|
4
|
+
import { readFileSync, readdirSync, existsSync, appendFileSync } from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { parse } from '@surfaice/format';
|
|
7
|
+
import { diff } from '@surfaice/differ';
|
|
8
|
+
function getInput(name, defaultValue = '') {
|
|
9
|
+
const envName = `INPUT_${name.toUpperCase().replace(/-/g, '_')}`;
|
|
10
|
+
return process.env[envName] ?? defaultValue;
|
|
11
|
+
}
|
|
12
|
+
function setOutput(name, value) {
|
|
13
|
+
const outputFile = process.env.GITHUB_OUTPUT;
|
|
14
|
+
if (outputFile) {
|
|
15
|
+
appendFileSync(outputFile, `${name}=${value}\n`);
|
|
16
|
+
}
|
|
17
|
+
console.log(`::set-output name=${name}::${value}`);
|
|
18
|
+
}
|
|
19
|
+
async function run() {
|
|
20
|
+
const baseUrl = getInput('base-url');
|
|
21
|
+
const surfaiceDir = getInput('surfaice-dir', 'surfaice/');
|
|
22
|
+
const failOnDrift = getInput('fail-on-drift', 'true') !== 'false';
|
|
23
|
+
if (!baseUrl) {
|
|
24
|
+
console.error('::error::base-url input is required');
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
if (!existsSync(surfaiceDir)) {
|
|
28
|
+
console.error(`::error::Directory not found: ${surfaiceDir}`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
const files = readdirSync(surfaiceDir).filter((f) => f.endsWith('.surfaice.md'));
|
|
32
|
+
if (files.length === 0) {
|
|
33
|
+
console.log(`::warning::No .surfaice.md files found in ${surfaiceDir}`);
|
|
34
|
+
setOutput('drift-detected', 'false');
|
|
35
|
+
setOutput('drift-summary', 'No .surfaice.md files found');
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const diffs = [];
|
|
39
|
+
let failures = 0;
|
|
40
|
+
for (const file of files) {
|
|
41
|
+
const committed = readFileSync(join(surfaiceDir, file), 'utf-8');
|
|
42
|
+
const expected = parse(committed);
|
|
43
|
+
const route = expected.route;
|
|
44
|
+
let response;
|
|
45
|
+
try {
|
|
46
|
+
response = await fetch(new URL(route, baseUrl).toString(), {
|
|
47
|
+
headers: { 'Accept': 'text/surfaice' },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.error(`::error::Failed to fetch ${route}: ${String(err)}`);
|
|
52
|
+
failures++;
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
console.error(`::error::${route} returned ${response.status} ${response.statusText}`);
|
|
57
|
+
failures++;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
const live = parse(await response.text());
|
|
61
|
+
const result = diff(expected, live);
|
|
62
|
+
diffs.push({ ...result, file });
|
|
63
|
+
if (result.status === 'match') {
|
|
64
|
+
console.log(`✅ ${route} — no drift`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
console.log(`❌ ${route} — DRIFT: ${result.summary}`);
|
|
68
|
+
for (const a of result.added)
|
|
69
|
+
console.log(` + [${a.id}] ${a.type} "${a.label}"`);
|
|
70
|
+
for (const r of result.removed)
|
|
71
|
+
console.log(` - [${r.id}] ${r.type} "${r.label}"`);
|
|
72
|
+
for (const c of result.changed)
|
|
73
|
+
console.log(` ~ [${c.id}].${c.field}: "${c.expected}" → "${c.actual}"`);
|
|
74
|
+
failures++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const driftDetected = diffs.some(d => d.status === 'drift') || failures > 0;
|
|
78
|
+
const summaries = diffs.filter(d => d.status === 'drift').map(d => `${d.route}: ${d.summary}`);
|
|
79
|
+
const driftSummary = summaries.length > 0 ? summaries.join('; ') : 'No drift detected';
|
|
80
|
+
setOutput('drift-detected', String(driftDetected));
|
|
81
|
+
setOutput('drift-summary', driftSummary);
|
|
82
|
+
setOutput('diff-json', JSON.stringify(diffs));
|
|
83
|
+
if (driftDetected && failOnDrift) {
|
|
84
|
+
console.error(`\n::error::UI drift detected! ${driftSummary}`);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
run().catch((err) => {
|
|
89
|
+
console.error(`::error::${String(err)}`);
|
|
90
|
+
process.exit(1);
|
|
91
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@surfaice/action",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "GitHub Action for detecting UI drift with Surfaice",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"action.yml",
|
|
15
|
+
"README.md"
|
|
16
|
+
],
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public",
|
|
19
|
+
"registry": "https://registry.npmjs.org"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/surfaiceai/surfaice",
|
|
25
|
+
"directory": "packages/action"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@surfaice/differ": "0.0.1",
|
|
29
|
+
"@surfaice/format": "0.0.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"vitest": "^2.0.0",
|
|
33
|
+
"typescript": "^5.5.0",
|
|
34
|
+
"@types/node": "^22.0.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"test": "vitest run",
|
|
39
|
+
"dev": "tsc --watch"
|
|
40
|
+
}
|
|
41
|
+
}
|