Skip to content

Commit ce71b9c

Browse files
committed
fix(ci): fix hardcoded font paths in test mocks and enhance pr preview url reporting
1 parent c82bd03 commit ce71b9c

4 files changed

Lines changed: 49 additions & 19 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
- name: Upload Cloudflare Worker Preview Version
107107
id: upload_preview
108108
run: |
109-
OUTPUT=$(pnpm --filter @codingcatdev/site exec wrangler versions upload --tag "pr-${{ github.event.pull_request.number }}" --message "PR #${{ github.event.pull_request.number }}: ${{ github.event.pull_request.title }}")
109+
OUTPUT=$(pnpm --filter @codingcatdev/site exec wrangler versions upload --tag "pr-${PR_NUMBER}" --message "PR #${PR_NUMBER}: ${PR_TITLE}")
110110
echo "$OUTPUT"
111111
112112
PREVIEW_URL=$(echo "$OUTPUT" | grep -i "Version Preview URL:" | awk '{print $NF}' | head -n 1)
@@ -115,26 +115,43 @@ jobs:
115115
echo "preview_url=$PREVIEW_URL" >> $GITHUB_OUTPUT
116116
echo "version_id=$VERSION_ID" >> $GITHUB_OUTPUT
117117
118+
echo "::notice title=Cloudflare Worker Preview URL::${PREVIEW_URL}"
119+
118120
echo "### ⚡ Cloudflare Worker Preview Ready" >> $GITHUB_STEP_SUMMARY
119121
echo "" >> $GITHUB_STEP_SUMMARY
120122
echo "- **Preview URL**: [${PREVIEW_URL}](${PREVIEW_URL})" >> $GITHUB_STEP_SUMMARY
121123
echo "- **Version ID**: \`${VERSION_ID}\`" >> $GITHUB_STEP_SUMMARY
122124
echo "- **Target Worker**: \`codingcatdev-dev\`" >> $GITHUB_STEP_SUMMARY
123125
124126
if [ -n "$PREVIEW_URL" ]; then
125-
echo "### ⚡ Cloudflare Worker Preview Ready!" > pr_comment.md
126-
echo "" >> pr_comment.md
127-
echo "| Environment | URL |" >> pr_comment.md
128-
echo "|---|---|" >> pr_comment.md
129-
echo "| **PR Preview** | [${PREVIEW_URL}](${PREVIEW_URL}) |" >> pr_comment.md
130-
echo "| **Dev Custom Domain** | [https://dev.codingcat.dev](https://dev.codingcat.dev) |" >> pr_comment.md
131-
echo "" >> pr_comment.md
132-
echo "- **Worker Version ID**: \`${VERSION_ID}\`" >> pr_comment.md
133-
echo "- **Protection**: Restricted to \`@codingcat.dev\` accounts via Cloudflare Zero Trust Access" >> pr_comment.md
134-
gh pr comment ${{ github.event.pull_request.number }} --body-file pr_comment.md
127+
cat << 'EOF' > pr_comment.md
128+
### ⚡ Cloudflare Worker Preview Ready!
129+
130+
| Environment | URL |
131+
|---|---|
132+
| **PR Preview** | [${PREVIEW_URL}](${PREVIEW_URL}) |
133+
| **Dev Custom Domain** | [https://dev.codingcat.dev](https://dev.codingcat.dev) |
134+
135+
- **Worker Version ID**: `${VERSION_ID}`
136+
- **Protection**: Restricted to `@codingcat.dev` accounts via Cloudflare Zero Trust Access
137+
EOF
138+
# Replace placeholder variables with actual values in pr_comment.md
139+
sed -i "s|\${PREVIEW_URL}|${PREVIEW_URL}|g" pr_comment.md
140+
sed -i "s|\${VERSION_ID}|${VERSION_ID}|g" pr_comment.md
141+
142+
# Check if bot has already posted a preview comment on this PR
143+
COMMENT_ID=$(gh api "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" --jq '.[] | select((.user.login=="github-actions[bot]" or .user.login=="app/github-actions") and (.body | contains("Cloudflare Worker Preview Ready"))) | .id' | tail -n 1)
144+
145+
if [ -n "$COMMENT_ID" ]; then
146+
gh api -X PATCH "repos/${{ github.repository }}/issues/comments/${COMMENT_ID}" -f body="$(cat pr_comment.md)"
147+
else
148+
gh pr comment "$PR_NUMBER" --body-file pr_comment.md
149+
fi
135150
fi
136151
env:
137152
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
138153
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID || 'c46bd0f3b9ed47b8692cca098030edbf' }}
139154
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
155+
PR_NUMBER: ${{ github.event.pull_request.number }}
156+
PR_TITLE: ${{ github.event.pull_request.title }}
140157

‎apps/site/tests/font-bold-mock.mjs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from "node:fs";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
24

3-
const buf = fs.readFileSync(
4-
"/home/alex/codingcat.dev/apps/site/src/assets/fonts/Inter-Bold.ttf",
5-
);
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
const fontPath = path.resolve(__dirname, "../src/assets/fonts/Inter-Bold.ttf");
7+
const buf = fs.existsSync(fontPath) ? fs.readFileSync(fontPath) : Buffer.from([]);
68
export default new Uint8Array(buf);

‎apps/site/tests/font-reg-mock.mjs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from "node:fs";
2+
import path from "node:path";
3+
import { fileURLToPath } from "node:url";
24

3-
const buf = fs.readFileSync(
4-
"/home/alex/codingcat.dev/apps/site/src/assets/fonts/Inter-Regular.ttf",
5-
);
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
6+
const fontPath = path.resolve(__dirname, "../src/assets/fonts/Inter-Regular.ttf");
7+
const buf = fs.existsSync(fontPath) ? fs.readFileSync(fontPath) : Buffer.from([]);
68
export default new Uint8Array(buf);

‎apps/site/tests/run-e2e.mjs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,19 @@ async function main() {
9898
files: filesToRun,
9999
});
100100

101+
const failureDetails = [];
102+
101103
stream.compose(new spec()).pipe(process.stdout);
102104

103105
stream.on("test:pass", () => {
104106
passedTests++;
105107
totalTests++;
106108
});
107109

108-
stream.on("test:fail", () => {
110+
stream.on("test:fail", (data) => {
109111
failedTests++;
110112
totalTests++;
113+
failureDetails.push(data);
111114
});
112115

113116
await new Promise((resolve) => stream.on("end", resolve));
@@ -142,7 +145,13 @@ async function main() {
142145
);
143146

144147
if (failedTests > 0) {
145-
console.error(`\n❌ TEST SUITE FAILED with ${failedTests} failure(s).`);
148+
console.error(`\n❌ TEST SUITE FAILED with ${failedTests} failure(s):`);
149+
for (const f of failureDetails) {
150+
console.error(`\n- Test: ${f.name}`);
151+
if (f.details?.error) {
152+
console.error(f.details.error.stack || f.details.error.message || f.details.error);
153+
}
154+
}
146155
process.exit(1);
147156
} else {
148157
console.log(

0 commit comments

Comments
 (0)