File tree Expand file tree Collapse file tree 2 files changed +42
-11
lines changed
Expand file tree Collapse file tree 2 files changed +42
-11
lines changed Original file line number Diff line number Diff line change 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:"
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]|'
Original file line number Diff line number Diff line change 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' ) ;
You can’t perform that action at this time.
0 commit comments