Skip to content

Commit e22f784

Browse files
add node step
1 parent 9b02250 commit e22f784

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

.github/workflows/deploy.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
- name: Checkout
2626
uses: actions/checkout@v4
2727

28+
- name: Setup Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: '20'
32+
2833
- name: Debug environment
2934
run: |
3035
echo "Current directory contents:"
@@ -45,17 +50,8 @@ jobs:
4550
echo "Before injection (showing relevant line):"
4651
grep -n "let webhookUrl = null;" index.html || echo "Pattern not found"
4752
48-
# Create a temporary file with the exact replacement
49-
sed '/let webhookUrl = null;/c\ const webhookUrl = "'"$WEBHOOK_URL"'"; // Injected by GitHub Actions' index.html > index.html.tmp
50-
51-
echo "Checking if replacement was successful..."
52-
if ! grep -q "Injected by GitHub Actions" index.html.tmp; then
53-
echo "Error: Replacement string not found in temporary file"
54-
exit 1
55-
fi
56-
57-
# Replace the original file
58-
mv index.html.tmp index.html
53+
# Use Node.js script to inject the webhook URL
54+
node scripts/inject-webhook.js "$WEBHOOK_URL"
5955
6056
echo "After injection (showing relevant line, URL hidden):"
6157
grep -n "webhookUrl = " index.html | sed 's|https://[^"]*|[WEBHOOK_URL_HIDDEN]|'

scripts/inject-webhook.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const fs = require('fs');
2+
3+
// Get the webhook URL from command line argument
4+
const webhookUrl = process.argv[2];
5+
if (!webhookUrl) {
6+
console.error('No webhook URL provided');
7+
process.exit(1);
8+
}
9+
10+
// Read the index.html file
11+
const indexPath = 'index.html';
12+
let content = fs.readFileSync(indexPath, 'utf8');
13+
14+
// Find and replace the webhook URL line
15+
const searchString = 'let webhookUrl = null;';
16+
const replaceString = `const webhookUrl = "${webhookUrl}"; // Injected by GitHub Actions`;
17+
18+
if (!content.includes(searchString)) {
19+
console.error('Could not find the webhook URL placeholder');
20+
process.exit(1);
21+
}
22+
23+
// Replace the line
24+
content = content.replace(searchString, replaceString);
25+
26+
// Verify the replacement
27+
if (!content.includes(replaceString)) {
28+
console.error('Failed to inject webhook URL');
29+
process.exit(1);
30+
}
31+
32+
// Write the file back
33+
fs.writeFileSync(indexPath, content, 'utf8');
34+
35+
console.log('Successfully injected webhook URL');

0 commit comments

Comments
 (0)