Skip to content

Commit dd709f2

Browse files
Fix: Simplify wrangler.jsonc update script by removing comments and directly replacing values
1 parent ae676bd commit dd709f2

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,23 @@ jobs:
3232

3333
- name: Update wrangler config with environment variables
3434
run: |
35-
# Create script to update wrangler.jsonc (using .cjs extension for CommonJS)
35+
# Create script to update wrangler.jsonc using string replacement
3636
cat > update_config.cjs << 'EOF'
3737
const fs = require('fs');
3838
3939
try {
4040
// Read the file
4141
let content = fs.readFileSync('wrangler.jsonc', 'utf8');
4242
43-
// Remove single-line comments
44-
content = content.replace(/\/\/.*$/gm, '');
43+
// Replace specific values in the vars section using regex
44+
content = content.replace(/"MEMBERSHIP_NUMBER_PREFIX":\s*"[^"]*"/, `"MEMBERSHIP_NUMBER_PREFIX": "${process.env.MEMBERSHIP_NUMBER_PREFIX}"`);
45+
content = content.replace(/"MOODLE_API_URL":\s*"[^"]*"/, `"MOODLE_API_URL": "${process.env.MOODLE_API_URL}"`);
46+
content = content.replace(/"SMTP_HOST":\s*"[^"]*"/, `"SMTP_HOST": "${process.env.SMTP_HOST}"`);
47+
content = content.replace(/"SMTP_PORT":\s*"[^"]*"/, `"SMTP_PORT": "${process.env.SMTP_PORT}"`);
48+
content = content.replace(/"SMTP_USER":\s*"[^"]*"/, `"SMTP_USER": "${process.env.SMTP_USER}"`);
4549
46-
// Remove multi-line comments
47-
content = content.replace(/\/\*[\s\S]*?\*\//g, '');
48-
49-
// Parse JSON
50-
const config = JSON.parse(content);
51-
52-
// Update vars
53-
if (!config.vars) config.vars = {};
54-
config.vars.MEMBERSHIP_NUMBER_PREFIX = process.env.MEMBERSHIP_NUMBER_PREFIX;
55-
config.vars.MOODLE_API_URL = process.env.MOODLE_API_URL;
56-
config.vars.SMTP_HOST = process.env.SMTP_HOST;
57-
config.vars.SMTP_PORT = process.env.SMTP_PORT;
58-
config.vars.SMTP_USER = process.env.SMTP_USER;
59-
60-
// Write back as JSON (not JSONC)
61-
fs.writeFileSync('wrangler.jsonc', JSON.stringify(config, null, 2));
50+
// Write back the modified content
51+
fs.writeFileSync('wrangler.jsonc', content);
6252
console.log('Successfully updated wrangler.jsonc with environment variables');
6353
} catch (error) {
6454
console.error('Error updating config:', error);

0 commit comments

Comments
 (0)