-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
188 lines (164 loc) · 6.47 KB
/
action.yml
File metadata and controls
188 lines (164 loc) · 6.47 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
name: "StructLint"
description: "Validate and enforce directory structure and file naming patterns"
author: "AxeForging"
inputs:
config:
description: "Path to .structlint.yaml config file"
required: false
default: ".structlint.yaml"
path:
description: "Directory to validate"
required: false
default: "."
json-output:
description: "Path to write JSON report (empty = no report)"
required: false
log-level:
description: "Log level: debug, info, warn, error"
required: false
default: "info"
silent:
description: "Silent mode - only exit code, no output"
required: false
default: "false"
version:
description: "Version of structlint to use (e.g. v0.2.0). Defaults to latest."
required: false
comment-on-pr:
description: "Post validation results as a PR comment (requires pull_request event and GITHUB_TOKEN)"
required: false
default: "false"
GITHUB_TOKEN:
description: "GitHub token for PR comments (required if comment-on-pr is true)"
required: false
runs:
using: "composite"
steps:
- name: Download StructLint
shell: bash
run: |
OS="linux"
ARCH="amd64"
if [[ "${{ runner.os }}" == "macOS" ]]; then OS="darwin"; fi
if [[ "${{ runner.arch }}" == "ARM64" ]]; then ARCH="arm64"; fi
VERSION="${{ inputs.version }}"
if [ -z "$VERSION" ]; then
VERSION="${{ github.action_ref }}"
fi
if [ -z "$VERSION" ] || [ "$VERSION" == "main" ]; then
# Fetch latest release tag
VERSION=$(curl -sS -o /dev/null -w '%{redirect_url}' \
"https://github.com/AxeForging/structlint/releases/latest" | grep -oP '[^/]+$')
echo "Resolved latest version: ${VERSION}"
fi
URL="https://github.com/AxeForging/structlint/releases/download/${VERSION}/structlint-${OS}-${ARCH}.tar.gz"
echo "Downloading structlint ${VERSION} from ${URL}..."
curl -sSL "$URL" -o /tmp/structlint.tar.gz
tar -xzf /tmp/structlint.tar.gz -C /tmp
chmod +x /tmp/structlint
echo "structlint ${VERSION} installed successfully"
- name: Run StructLint
id: validate
shell: bash
run: |
ARGS="validate --config ${{ inputs.config }} --json-output /tmp/structlint-report.json"
if [ "${{ inputs.path }}" != "." ]; then
ARGS="${ARGS} --path ${{ inputs.path }}"
fi
if [ "${{ inputs.log-level }}" != "info" ]; then
ARGS="${ARGS} --log-level ${{ inputs.log-level }}"
fi
if [ "${{ inputs.silent }}" == "true" ]; then
ARGS="${ARGS} --silent"
fi
EXIT_CODE=0
/tmp/structlint ${ARGS} || EXIT_CODE=$?
# Copy to user-specified path if requested
if [ -n "${{ inputs.json-output }}" ]; then
cp /tmp/structlint-report.json "${{ inputs.json-output }}"
fi
echo "exit_code=${EXIT_CODE}" >> "$GITHUB_OUTPUT"
- name: Generate Summary
if: always()
shell: bash
env:
CONFIG_PATH: ${{ inputs.config }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
REPORT="/tmp/structlint-report.json"
if [ ! -f "$REPORT" ]; then
echo "No report file found, skipping summary."
exit 0
fi
SUCCESSES=$(jq -r '.successes' "$REPORT")
FAILURES=$(jq -r '.failures' "$REPORT")
TOTAL=$((SUCCESSES + FAILURES))
{
if [ "$FAILURES" -eq 0 ]; then
echo "## StructLint — All checks passed"
echo ""
echo "**${SUCCESSES}** rules validated against \`${CONFIG_PATH}\`. No violations found."
else
echo "## StructLint — ${FAILURES} violation(s) found"
echo ""
echo "**${SUCCESSES}**/${TOTAL} rules passed · **${FAILURES}** violation(s) detected against \`${CONFIG_PATH}\`."
echo ""
# Render each violation category
jq -r '.summary.violations[]? | @json' "$REPORT" | while IFS= read -r v; do
DESC=$(echo "$v" | jq -r '.description')
COUNT=$(echo "$v" | jq -r '.count')
EXAMPLES=$(echo "$v" | jq -r '.examples[]?')
EXAMPLE_COUNT=$(echo "$v" | jq -r '.examples | length')
echo "<details>"
echo "<summary><strong>${DESC}</strong> (${COUNT})</summary>"
echo ""
echo "$EXAMPLES" | while IFS= read -r ex; do
echo "- \`${ex}\`"
done
if [ "$COUNT" -gt "$EXAMPLE_COUNT" ]; then
REMAINING=$((COUNT - EXAMPLE_COUNT))
echo "- _…and ${REMAINING} more_"
fi
echo ""
echo "</details>"
echo ""
done
fi
echo "---"
echo "<sub><a href=\"${RUN_URL}\">View full run</a> · Powered by <a href=\"https://github.com/AxeForging/structlint\">StructLint</a></sub>"
} > /tmp/structlint-md.tmp
MD=$(cat /tmp/structlint-md.tmp)
# Write to job summary
echo "$MD" >> "$GITHUB_STEP_SUMMARY"
# Save for PR comment step
echo "$MD" > /tmp/structlint-comment.md
- name: Comment on PR
if: always() && inputs.comment-on-pr == 'true' && github.event_name == 'pull_request'
shell: bash
env:
GH_TOKEN: ${{ inputs.GITHUB_TOKEN }}
run: |
if [ ! -f /tmp/structlint-comment.md ]; then
echo "No comment file found, skipping."
exit 0
fi
PR_NUMBER="${{ github.event.pull_request.number }}"
REPO="${{ github.repository }}"
COMMENT_TAG="<!-- structlint-report -->"
BODY="$(printf '%s\n%s' "$COMMENT_TAG" "$(cat /tmp/structlint-comment.md)")"
# Check for existing structlint comment to update
EXISTING_COMMENT_ID=$(gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
--jq ".[] | select(.body | startswith(\"${COMMENT_TAG}\")) | .id" 2>/dev/null | head -1)
if [ -n "$EXISTING_COMMENT_ID" ]; then
gh api "repos/${REPO}/issues/comments/${EXISTING_COMMENT_ID}" \
-X PATCH -f body="$BODY"
echo "Updated existing PR comment."
else
gh api "repos/${REPO}/issues/${PR_NUMBER}/comments" \
-X POST -f body="$BODY"
echo "Created new PR comment."
fi
- name: Exit with validation result
if: always()
shell: bash
run: exit ${{ steps.validate.outputs.exit_code }}