-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
132 lines (118 loc) · 4.69 KB
/
Copy pathaction.yml
File metadata and controls
132 lines (118 loc) · 4.69 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
name: 'MetaObjects Verify'
description: 'Catch metadata-vs-code drift in a MetaObjects project at PR time. Wraps `meta verify`.'
author: 'MetaObjects'
branding:
icon: 'check-circle'
color: 'blue'
inputs:
working-directory:
description: 'Project root containing metaobjects.config.ts. Defaults to the checked-out repo root.'
required: false
default: '${{ github.workspace }}'
cli-version:
description: 'Version range of @metaobjectsdev/cli to install (e.g. "^0.7.0", "next", "latest", "0.7.0-rc.12").'
required: false
default: 'next'
node-version:
description: 'Node.js version for the runner. Anything Node 20+ works.'
required: false
default: '20'
database-url:
description: 'Optional DATABASE_URL for DB-vs-metadata drift checks. Typically a secret.'
required: false
prompts-dir:
description: 'Directory holding the provider-resolved template text. Defaults to ./prompts (the CLI default). Pass to override.'
required: false
default: ''
comment-on-pr:
description: 'Post drift summary as a PR comment on failure. Requires `pull-requests: write` permission.'
required: false
default: 'true'
install-command:
description: 'How to install dependencies before running verify. Useful if the project uses bun / pnpm / yarn instead of npm. Default skips install (relies on cli-version pull).'
required: false
default: ''
outputs:
drift-summary:
description: 'Markdown summary of detected drifts (empty when clean).'
value: ${{ steps.run.outputs.summary }}
exit-code:
description: 'Exit code from `meta verify` (0 = clean, non-zero = drift).'
value: ${{ steps.run.outputs.exit_code }}
runs:
using: 'composite'
steps:
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.node-version }}
- name: Install project dependencies (optional)
if: inputs.install-command != ''
shell: bash
working-directory: ${{ inputs.working-directory }}
run: ${{ inputs.install-command }}
- name: Install @metaobjectsdev/cli
shell: bash
working-directory: ${{ inputs.working-directory }}
run: |
echo "Installing @metaobjectsdev/cli@${{ inputs.cli-version }} into a side-pocket..."
npm install --no-save --no-package-lock --no-audit --no-fund \
"@metaobjectsdev/cli@${{ inputs.cli-version }}"
- id: run
name: Run meta verify
shell: bash
working-directory: ${{ inputs.working-directory }}
env:
DATABASE_URL: ${{ inputs.database-url }}
run: |
PROMPTS_FLAG=""
if [ -n "${{ inputs.prompts-dir }}" ]; then
PROMPTS_FLAG="--prompts ${{ inputs.prompts-dir }}"
fi
set +e
npx --no-install meta verify $PROMPTS_FLAG 2>&1 | tee /tmp/meta-verify.out
EXIT_CODE=${PIPESTATUS[0]}
set -e
echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
# Capture the output as a multi-line step output for downstream steps.
{
echo "summary<<METAOBJECTS_EOF"
cat /tmp/meta-verify.out
echo "METAOBJECTS_EOF"
} >> "$GITHUB_OUTPUT"
# Emit GitHub annotations on failure (file-line hints for the PR
# review surface, when meta verify provides them).
if [ "$EXIT_CODE" != "0" ]; then
echo "::error title=MetaObjects drift detected::Run \`meta gen\` locally, commit the regenerated files, and re-push."
fi
exit $EXIT_CODE
- name: Post PR comment on failure
if: failure() && inputs.comment-on-pr == 'true' && github.event_name == 'pull_request'
uses: actions/github-script@v9
with:
script: |
const summary = `${{ steps.run.outputs.summary }}`;
const body = [
'## ❌ MetaObjects drift detected',
'',
'`meta verify` reported drift between your metadata declarations and the generated code (or the database, if `DATABASE_URL` was supplied).',
'',
'<details><summary>Drift report</summary>',
'',
'```',
summary || '(no output captured)',
'```',
'',
'</details>',
'',
'**To fix:** run `meta gen` (or your project equivalent — e.g. `npm run gen:db`) locally, commit the regenerated files, and re-push.',
'',
'---',
'_Generated by [`metaobjectsdev/meta-verify-action`](https://github.com/metaobjectsdev/meta-verify-action)._',
].join('\n');
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});