-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (74 loc) · 2.34 KB
/
codegen-check.yml
File metadata and controls
82 lines (74 loc) · 2.34 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
# Reusable workflow: language repos call this to verify their committed
# generated/ directories are up-to-date with the spec.
#
# Caller example (in acars-decoder-typescript/.github/workflows/ci.yml):
#
# jobs:
# ads-up-to-date:
# uses: airframesio/airframes-decoder/.github/workflows/codegen-check.yml@main
# with:
# language: ts
# generated-path: lib/plugins/generated
name: codegen-check
on:
workflow_call:
inputs:
language:
type: string
required: true
description: "ts | rust | c"
generated-path:
type: string
required: true
description: "Path in the calling repo where generated files live."
spec-path:
type: string
default: "vendor/airframes-decoder/spec"
codegen-path:
type: string
default: "vendor/airframes-decoder/codegen"
jobs:
check:
runs-on: ubuntu-latest
env:
LANGUAGE: ${{ inputs.language }}
GENERATED_PATH: ${{ inputs.generated-path }}
SPEC_PATH: ${{ inputs.spec-path }}
CODEGEN_PATH: ${{ inputs.codegen-path }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-node@v4
with:
node-version: "20"
- name: Validate inputs
run: |
case "$LANGUAGE" in
ts|rust|c) ;;
*) echo "::error::language must be one of: ts, rust, c (got '$LANGUAGE')"; exit 1 ;;
esac
for var in GENERATED_PATH SPEC_PATH CODEGEN_PATH; do
val="${!var}"
case "$val" in
*..*|/*|*$'\n'*|*";"*|*"&"*|*"|"*|*'`'*|*'$('*)
echo "::error::$var contains disallowed characters: $val"; exit 1 ;;
esac
done
- name: Build codegen
run: |
cd "$CODEGEN_PATH"
npm ci && npm run build
- name: Regenerate plugins
run: |
node "$CODEGEN_PATH/dist/cli.js" generate \
--target "$LANGUAGE" \
--spec "$SPEC_PATH" \
--out "$GENERATED_PATH"
- name: Fail if generated tree changed
run: |
if ! git diff --quiet -- "$GENERATED_PATH"; then
echo "::error::generated/ is out of date. Run ads-gen and commit the changes."
git diff --stat -- "$GENERATED_PATH"
exit 1
fi