-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·79 lines (64 loc) · 2.86 KB
/
entrypoint.sh
File metadata and controls
executable file
·79 lines (64 loc) · 2.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
#!/bin/bash
# erode GitHub Action entrypoint
# All analysis, commenting, step summaries, and output handling is done by core.
# This script only handles GitHub Actions-specific bootstrapping that requires bash.
set -euo pipefail
# GitHub Actions sets INPUT_<name> env vars preserving hyphens from input names.
# Bash can't reference vars with hyphens, so normalize to underscores.
while IFS='=' read -r name value; do
norm="${name//-/_}"
if [[ "$name" != "$norm" ]]; then
export "$norm=$value"
fi
done < <(env | grep '^INPUT_')
# ── 1. Extract PR URL from event payload ──
PR_URL=$(jq -r '.pull_request.html_url // .issue.pull_request.html_url // empty' "$GITHUB_EVENT_PATH")
if [ -z "$PR_URL" ]; then
echo "::error::Could not extract PR URL. This action runs on pull_request or issue_comment (on a PR) triggers."
exit 1
fi
# ── 2. Map action inputs to CLI environment variables ──
export ERODE_AI_PROVIDER="${INPUT_AI_PROVIDER:-anthropic}"
export ERODE_ANTHROPIC_API_KEY="${INPUT_ANTHROPIC_API_KEY:-}"
export ERODE_GEMINI_API_KEY="${INPUT_GEMINI_API_KEY:-}"
export ERODE_OPENAI_API_KEY="${INPUT_OPENAI_API_KEY:-}"
export ERODE_GITHUB_TOKEN="${INPUT_GITHUB_TOKEN:?github-token input is required}"
export ERODE_MODEL_FORMAT="${INPUT_MODEL_FORMAT:-likec4}"
export ERODE_MODEL_REPO_PR_TOKEN="${INPUT_MODEL_REPO_TOKEN:-$ERODE_GITHUB_TOKEN}"
# ── 3. Auth setup for model-repo access ──
CLONE_TOKEN="${INPUT_MODEL_REPO_TOKEN:-$ERODE_GITHUB_TOKEN}"
GIT_ASKPASS_SCRIPT="/tmp/git-askpass-$$"
ESCAPED_TOKEN=$(printf '%s' "$CLONE_TOKEN" | sed "s/'/'\\\\''/g")
printf "#!/bin/sh\necho '%s'" "$ESCAPED_TOKEN" > "$GIT_ASKPASS_SCRIPT"
chmod +x "$GIT_ASKPASS_SCRIPT"
# ── 4. Build CLI args and exec ──
CORE_ARGS=(
analyze "${INPUT_MODEL_PATH:-.}"
--url "$PR_URL"
--model-format "$ERODE_MODEL_FORMAT"
--format json
--comment
--github-actions
)
CORE_ARGS+=(--model-repo "$INPUT_MODEL_REPO")
CORE_ARGS+=(--model-ref "${INPUT_MODEL_REF:-main}")
OPEN_PR="${INPUT_OPEN_PR:-false}"
if [ "$OPEN_PR" = "true" ]; then
CORE_ARGS+=(--open-pr)
elif [ "$OPEN_PR" = "auto" ]; then
PR_NUMBER=$(jq -r '.pull_request.number // .issue.number // empty' "$GITHUB_EVENT_PATH")
SOURCE_REPO=$(jq -r '.repository.full_name // empty' "$GITHUB_EVENT_PATH")
if [ -n "$PR_NUMBER" ] && [ -n "$SOURCE_REPO" ]; then
SLUG=$(echo "$SOURCE_REPO" | tr '/' '-')
BRANCH="erode/${SLUG}/pr-${PR_NUMBER}"
if GIT_ASKPASS="$GIT_ASKPASS_SCRIPT" git ls-remote --exit-code --heads \
"https://x-access-token@github.com/${INPUT_MODEL_REPO}.git" \
"$BRANCH" >/dev/null 2>&1; then
CORE_ARGS+=(--open-pr)
fi
fi
fi
rm -f "$GIT_ASKPASS_SCRIPT"
[ "${INPUT_SKIP_FILE_FILTERING:-false}" = "true" ] && CORE_ARGS+=(--skip-file-filtering)
[ "${INPUT_FAIL_ON_VIOLATIONS:-false}" = "true" ] && CORE_ARGS+=(--fail-on-violations)
exec node /app/packages/core/dist/ci-entry.js "${CORE_ARGS[@]}"