-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
200 lines (185 loc) · 6.07 KB
/
Copy pathaction.yml
File metadata and controls
200 lines (185 loc) · 6.07 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
name: 'layout-audit'
description: 'Analyze binary memory layouts to detect padding inefficiencies'
author: 'avifen'
branding:
icon: 'cpu'
color: 'orange'
inputs:
binary:
description: 'Path to the binary file to analyze'
required: true
command:
description: 'Command to run: inspect, diff, check, or suggest'
required: false
default: 'inspect'
baseline:
description: 'Path to baseline binary (for diff command)'
required: false
config:
description: 'Path to config file (for check command)'
required: false
default: '.layout-audit.yaml'
filter:
description: 'Filter structs by name (substring match)'
required: false
output:
description: 'Output format: table, json, or sarif'
required: false
default: 'table'
sort-by:
description: 'Sort by: name, size, padding, or padding-pct'
required: false
default: 'padding'
top:
description: 'Show only top N structs'
required: false
min-padding:
description: 'Show only structs with at least N bytes of padding'
required: false
min-savings:
description: 'Show only structs with at least N bytes of potential savings (for suggest command)'
required: false
sort-by-savings:
description: 'Sort suggestions by savings amount (for suggest command)'
required: false
default: 'false'
fail-on-regression:
description: 'Fail if size or padding increased (for diff command)'
required: false
default: 'false'
version:
description: 'Version of layout-audit to use'
required: false
default: 'latest'
outputs:
report:
description: 'The layout-audit output'
value: ${{ steps.run.outputs.report }}
sarif-path:
description: 'Path to SARIF file (when output=sarif)'
value: ${{ steps.run.outputs.sarif_path }}
runs:
using: 'composite'
steps:
- name: Install layout-audit
shell: bash
env:
INSTALL_VERSION: ${{ inputs.version }}
run: |
if [ "$INSTALL_VERSION" = "latest" ]; then
cargo install layout-audit --locked
else
cargo install layout-audit --version "$INSTALL_VERSION" --locked
fi
- name: Run layout-audit
id: run
shell: bash
continue-on-error: true
env:
INPUT_COMMAND: ${{ inputs.command }}
INPUT_BINARY: ${{ inputs.binary }}
INPUT_BASELINE: ${{ inputs.baseline }}
INPUT_CONFIG: ${{ inputs.config }}
INPUT_FILTER: ${{ inputs.filter }}
INPUT_OUTPUT: ${{ inputs.output }}
INPUT_SORT_BY: ${{ inputs.sort-by }}
INPUT_TOP: ${{ inputs.top }}
INPUT_MIN_PADDING: ${{ inputs.min-padding }}
INPUT_MIN_SAVINGS: ${{ inputs.min-savings }}
INPUT_SORT_BY_SAVINGS: ${{ inputs.sort-by-savings }}
INPUT_FAIL_ON_REGRESSION: ${{ inputs.fail-on-regression }}
run: |
set +e
args=()
case "$INPUT_COMMAND" in
inspect)
args+=(inspect "$INPUT_BINARY")
if [ -n "$INPUT_FILTER" ]; then
args+=(--filter "$INPUT_FILTER")
fi
args+=(--output "$INPUT_OUTPUT")
args+=(--sort-by "$INPUT_SORT_BY")
if [ -n "$INPUT_TOP" ]; then
args+=(--top "$INPUT_TOP")
fi
if [ -n "$INPUT_MIN_PADDING" ]; then
args+=(--min-padding "$INPUT_MIN_PADDING")
fi
;;
diff)
if [ -z "$INPUT_BASELINE" ]; then
echo "Error: baseline input is required for diff command"
exit 1
fi
args+=(diff "$INPUT_BASELINE" "$INPUT_BINARY")
if [ -n "$INPUT_FILTER" ]; then
args+=(--filter "$INPUT_FILTER")
fi
args+=(--output "$INPUT_OUTPUT")
if [ "$INPUT_FAIL_ON_REGRESSION" = "true" ]; then
args+=(--fail-on-regression)
fi
;;
check)
args+=(check "$INPUT_BINARY" --config "$INPUT_CONFIG" --output "$INPUT_OUTPUT")
;;
suggest)
args+=(suggest "$INPUT_BINARY")
if [ -n "$INPUT_FILTER" ]; then
args+=(--filter "$INPUT_FILTER")
fi
args+=(--output "$INPUT_OUTPUT")
if [ -n "$INPUT_MIN_SAVINGS" ]; then
args+=(--min-savings "$INPUT_MIN_SAVINGS")
fi
if [ "$INPUT_SORT_BY_SAVINGS" = "true" ]; then
args+=(--sort-by-savings)
fi
;;
*)
echo "Error: unknown command '$INPUT_COMMAND'"
exit 1
;;
esac
echo "Running: layout-audit ${args[*]}"
if [ "$INPUT_OUTPUT" = "sarif" ]; then
SARIF_FILE="${RUNNER_TEMP:-/tmp}/layout-audit.sarif"
layout-audit "${args[@]}" > "$SARIF_FILE"
EXIT_CODE=$?
cat "$SARIF_FILE"
DELIMITER="EOF_${RANDOM}_${RANDOM}"
{
echo "report<<${DELIMITER}"
cat "$SARIF_FILE"
echo "${DELIMITER}"
} >> "$GITHUB_OUTPUT"
if [ -s "$SARIF_FILE" ]; then
echo "sarif_path=$SARIF_FILE" >> "$GITHUB_OUTPUT"
else
echo "sarif_path=" >> "$GITHUB_OUTPUT"
fi
else
OUTPUT=$(layout-audit "${args[@]}" 2>&1)
EXIT_CODE=$?
echo "$OUTPUT"
# Set output for use in subsequent steps
# Use unique delimiter to prevent output smuggling if OUTPUT contains "EOF"
DELIMITER="EOF_${RANDOM}_${RANDOM}"
{
echo "report<<${DELIMITER}"
echo "$OUTPUT"
echo "${DELIMITER}"
} >> "$GITHUB_OUTPUT"
echo "sarif_path=" >> "$GITHUB_OUTPUT"
fi
echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
exit 0
- name: Upload SARIF
if: ${{ steps.run.outputs.sarif_path != '' }}
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.run.outputs.sarif_path }}
- name: Fail if layout-audit failed
if: ${{ steps.run.outputs.exit_code != '0' }}
shell: bash
run: exit ${{ steps.run.outputs.exit_code }}