Skip to content

Commit d182ff5

Browse files
committed
Merge branch 'main' into work/tw/fpl-import
2 parents 43348d1 + 172f66c commit d182ff5

1 file changed

Lines changed: 176 additions & 0 deletions

File tree

.github/workflows/pr-run.yaml

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
name: Validate & Deploy Plugins
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
validate-and-deploy:
8+
runs-on: ubuntu-latest
9+
permissions:
10+
pull-requests: write
11+
steps:
12+
- uses: actions/checkout@v6
13+
with:
14+
fetch-depth: 0
15+
16+
- name: Detect modified plugins
17+
id: detect
18+
run: |
19+
echo "Scanning for modified plugins against origin/main..."
20+
changed_files=$(git diff --name-only origin/main... -- ./plugins)
21+
plugin_paths=$(echo "$changed_files" | grep -oP 'plugins/[^/]+/v[^/]+' | sort -u)
22+
23+
if [ -z "$plugin_paths" ]; then
24+
echo "No plugins were modified in this PR."
25+
echo "plugins_modified=false" >> $GITHUB_OUTPUT
26+
else
27+
echo "Found modified plugin(s):"
28+
echo "$plugin_paths"
29+
echo "plugins_modified=true" >> $GITHUB_OUTPUT
30+
echo "plugin_paths<<EOF" >> $GITHUB_OUTPUT
31+
echo "$plugin_paths" >> $GITHUB_OUTPUT
32+
echo "EOF" >> $GITHUB_OUTPUT
33+
fi
34+
35+
- name: Install & Configure SquaredUp CLI
36+
if: steps.detect.outputs.plugins_modified == 'true'
37+
env:
38+
SQUAREDUP_API_KEY: ${{ secrets.SQUAREDUP_API_KEY }}
39+
run: |
40+
echo "Installing SquaredUp CLI..."
41+
npm install -g @squaredup/cli
42+
echo "Configuring SquaredUp CLI with API key..."
43+
squaredup login --apiKey "$SQUAREDUP_API_KEY"
44+
45+
- name: Validate modified plugins
46+
id: validate
47+
if: steps.detect.outputs.plugins_modified == 'true'
48+
run: |
49+
validation_failed=false
50+
51+
while IFS= read -r plugin_path; do
52+
echo "Validating ${plugin_path}..."
53+
result=$(squaredup validate "${plugin_path}" --json) || true
54+
echo "$result" | jq '.'
55+
valid=$(echo "$result" | jq -r '.valid')
56+
57+
echo "$result" | jq -c --arg path "$plugin_path" '. + {plugin_path: $path}' >> /tmp/validation_results.ndjson
58+
59+
if [ "$valid" = "true" ]; then
60+
plugin_name=$(echo "$result" | jq -r '.pluginName')
61+
echo "[PASS] ${plugin_name} passed validation"
62+
echo "$result" | jq '.summary'
63+
else
64+
echo "[FAIL] Validation failed for ${plugin_path}"
65+
echo "$result" | jq -r '.errors[] | " - [\(.file)] \(.message) (path: \(.path | join(".")))"'
66+
validation_failed=true
67+
fi
68+
echo ""
69+
done <<< "${{ steps.detect.outputs.plugin_paths }}"
70+
71+
if [ "$validation_failed" = "true" ]; then
72+
echo "One or more plugins failed validation."
73+
exit 1
74+
fi
75+
76+
- name: Deploy modified plugins
77+
id: deploy
78+
if: steps.detect.outputs.plugins_modified == 'true'
79+
run: |
80+
while IFS= read -r plugin_path; do
81+
echo "Deploying ${plugin_path}..."
82+
squaredup deploy "${plugin_path}" --suffix "${{ github.event.pull_request.number }}" --force
83+
echo "Deployed ${plugin_path} successfully."
84+
echo ""
85+
done <<< "${{ steps.detect.outputs.plugin_paths }}"
86+
87+
- name: Summary
88+
if: always()
89+
run: |
90+
OUT=/tmp/summary.md
91+
92+
echo "## 🧩 Plugin PR Summary" >> $OUT
93+
echo "" >> $OUT
94+
95+
if [ "${{ steps.detect.outputs.plugins_modified }}" != "true" ]; then
96+
echo "ℹ️ No plugins were modified in this PR." >> $OUT
97+
cat $OUT >> $GITHUB_STEP_SUMMARY
98+
exit 0
99+
fi
100+
101+
echo "### 📦 Modified Plugins" >> $OUT
102+
while IFS= read -r plugin_path; do
103+
echo "- \`${plugin_path}\`" >> $OUT
104+
done <<< "${{ steps.detect.outputs.plugin_paths }}"
105+
echo "" >> $OUT
106+
107+
echo "### 📋 Results" >> $OUT
108+
echo "| Step | Status |" >> $OUT
109+
echo "|------|--------|" >> $OUT
110+
111+
validate_conclusion="${{ steps.validate.conclusion }}"
112+
deploy_conclusion="${{ steps.deploy.conclusion }}"
113+
114+
[ "$validate_conclusion" = "success" ] && v_status="✅ Passed" || v_status="❌ Failed"
115+
[ "$deploy_conclusion" = "success" ] && d_status="🚀 Deployed" || d_status="⏭️ Skipped"
116+
117+
echo "| Validation | ${v_status} |" >> $OUT
118+
echo "| Deployment | ${d_status} |" >> $OUT
119+
echo "" >> $OUT
120+
121+
if [ -f /tmp/validation_results.ndjson ]; then
122+
echo "### 🔍 Validation Details" >> $OUT
123+
echo "" >> $OUT
124+
while IFS= read -r line; do
125+
plugin_path=$(echo "$line" | jq -r '.plugin_path')
126+
valid=$(echo "$line" | jq -r '.valid')
127+
plugin_name=$(echo "$line" | jq -r '.pluginName // .plugin_path')
128+
[ "$valid" = "true" ] && icon="✅" || icon="❌"
129+
130+
echo "<details>" >> $OUT
131+
echo "<summary>${icon} <code>${plugin_name}</code></summary>" >> $OUT
132+
echo "" >> $OUT
133+
echo '```json' >> $OUT
134+
echo "$line" | jq 'del(.plugin_path)' >> $OUT
135+
echo '```' >> $OUT
136+
echo "</details>" >> $OUT
137+
echo "" >> $OUT
138+
done < /tmp/validation_results.ndjson
139+
fi
140+
141+
cat $OUT >> $GITHUB_STEP_SUMMARY
142+
143+
- name: Post PR comment
144+
if: always()
145+
uses: actions/github-script@v7
146+
with:
147+
script: |
148+
const fs = require('fs');
149+
const marker = '<!-- plugin-pr-summary -->';
150+
const summary = fs.existsSync('/tmp/summary.md')
151+
? fs.readFileSync('/tmp/summary.md', 'utf8')
152+
: '_No summary available._';
153+
const body = `${marker}\n${summary}`;
154+
155+
const comments = await github.paginate(github.rest.issues.listComments, {
156+
owner: context.repo.owner,
157+
repo: context.repo.repo,
158+
issue_number: context.issue.number,
159+
});
160+
161+
const existing = comments.find(c => c.body.includes(marker));
162+
163+
if (existing) {
164+
await github.rest.issues.deleteComment({
165+
owner: context.repo.owner,
166+
repo: context.repo.repo,
167+
comment_id: existing.id,
168+
});
169+
}
170+
171+
await github.rest.issues.createComment({
172+
owner: context.repo.owner,
173+
repo: context.repo.repo,
174+
issue_number: context.issue.number,
175+
body,
176+
});

0 commit comments

Comments
 (0)