-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
179 lines (154 loc) · 5.86 KB
/
action.yml
File metadata and controls
179 lines (154 loc) · 5.86 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
name: "Tempo Lints"
description: "Run Tempo lint rules on your codebase"
author: "Tempo Labs"
branding:
icon: "check-circle"
color: "purple"
inputs:
language:
description: "Language to lint: rust, typescript, or all"
required: true
path:
description: "Path to scan (defaults to current directory)"
required: false
default: "."
fail-on-error:
description: "Fail the action if lint errors are found"
required: false
default: "true"
exclude-rules:
description: 'Comma-separated list of rule IDs to exclude (e.g., "no-dbg-macro,no-console-log")'
required: false
default: ""
fix:
description: "Apply auto-fixes where available"
required: false
default: "false"
post-comment:
description: "Post lint results as a PR comment"
required: false
default: "false"
github-token:
description: "GitHub token for posting PR comments (required if post-comment is true)"
required: false
default: ""
outputs:
has-errors:
description: "Whether any error-level issues were found"
value: ${{ steps.run-lint.outputs.has_errors }}
runs:
using: "composite"
steps:
- name: Setup Node.js
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0
with:
node-version: "lts/*"
- name: Enable corepack
shell: bash
run: corepack enable
- name: Get cache keys
id: cache-keys
shell: bash
run: |
echo "PNPM_STORE=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
# Hash the lockfile for cache key
LOCK_HASH=$(sha256sum "${{ github.action_path }}/pnpm-lock.yaml" | cut -d' ' -f1 | head -c 16)
echo "LOCK_HASH=$LOCK_HASH" >> $GITHUB_OUTPUT
- name: Cache pnpm store
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ${{ steps.cache-keys.outputs.PNPM_STORE }}
key: tempo-lints-pnpm-store-${{ runner.os }}-${{ steps.cache-keys.outputs.LOCK_HASH }}
restore-keys: |
tempo-lints-pnpm-store-${{ runner.os }}-
- name: Cache node_modules (includes sg binary)
id: cache-node-modules
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: ${{ github.action_path }}/node_modules
key: tempo-lints-node-modules-${{ runner.os }}-${{ steps.cache-keys.outputs.LOCK_HASH }}
- name: Install tempo-lints dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
shell: bash
run: cd "${{ github.action_path }}" && pnpm install --frozen-lockfile
- name: Run Tempo Lints
id: run-lint
shell: bash
working-directory: ${{ github.workspace }}
run: |
# Resolve scan path (default to workspace root)
SCAN_PATH="${{ inputs.path }}"
if [ "$SCAN_PATH" = "." ]; then
SCAN_PATH="${{ github.workspace }}"
fi
# Build CLI args - use JSON output if PR comment is needed
if [ "${{ inputs.post-comment }}" = "true" ] && [ "${{ github.event_name }}" = "pull_request" ]; then
OUTPUT_FORMAT="--json"
else
OUTPUT_FORMAT="--github-action"
fi
# Build CLI args array for safe parameter passing
CLI_ARGS=("${{ inputs.language }}" "$SCAN_PATH" "$OUTPUT_FORMAT")
if [ -n "${{ inputs.exclude-rules }}" ]; then
CLI_ARGS+=("--exclude" "${{ inputs.exclude-rules }}")
fi
if [ "${{ inputs.fix }}" = "true" ]; then
CLI_ARGS+=("--fix")
fi
# Debug: show what we're scanning
echo "Scanning: $SCAN_PATH"
echo "CLI args: ${CLI_ARGS[*]}"
# Run lint and capture output
OUTPUT_FILE="${{ runner.temp }}/tempo-lints-output.json"
set +e
if [ "$OUTPUT_FORMAT" = "--json" ]; then
pnpm --dir "${{ github.action_path }}" exec tsx "${{ github.action_path }}/bin/tempo-lints.ts" "${CLI_ARGS[@]}" > "$OUTPUT_FILE" 2>/dev/null
else
pnpm --dir "${{ github.action_path }}" exec tsx "${{ github.action_path }}/bin/tempo-lints.ts" "${CLI_ARGS[@]}"
fi
EXIT_CODE=$?
set -e
# Set outputs based on exit code
HAS_ERRORS="false"
if [ "$EXIT_CODE" != "0" ]; then
HAS_ERRORS="true"
fi
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
echo "has_errors=$HAS_ERRORS" >> $GITHUB_OUTPUT
# Only set output_file when using JSON format
if [ "$OUTPUT_FORMAT" = "--json" ]; then
echo "output_file=$OUTPUT_FILE" >> $GITHUB_OUTPUT
fi
- name: Post PR comment
if: inputs.post-comment == 'true' && github.event_name == 'pull_request'
shell: bash
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
run: |
if [ -z "$GITHUB_TOKEN" ]; then
echo "::warning::github-token is required for posting PR comments"
exit 0
fi
OUTPUT_FILE="${{ steps.run-lint.outputs.output_file }}"
# Validate output file exists
if [ ! -f "$OUTPUT_FILE" ]; then
echo "::error::Output file not found at $OUTPUT_FILE"
exit 1
fi
# Count issues from JSON output
TOTAL_ISSUES=$(node -p "try { JSON.parse(require('fs').readFileSync('$OUTPUT_FILE','utf8')).length } catch { 0 }" 2>/dev/null || echo "0")
pnpm --dir "${{ github.action_path }}" exec tsx "${{ github.action_path }}/scripts/post-pr-comment.ts" \
"$OUTPUT_FILE" \
"$TOTAL_ISSUES" \
"${{ github.repository }}" \
"${{ github.event.pull_request.number }}" \
"${{ inputs.language }}"
- name: Check for failures
if: inputs.fail-on-error == 'true'
shell: bash
run: |
EXIT_CODE="${{ steps.run-lint.outputs.exit_code }}"
if [ "$EXIT_CODE" != "0" ]; then
echo "::error::Lint errors found. Fix the issues above or set fail-on-error to false."
exit 1
fi