Skip to content

Commit 4ad35bb

Browse files
committed
fix: refactor build script and newline handling in workflow
1 parent 2ad8e5d commit 4ad35bb

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

.github/workflows/update_error_databases.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,8 @@ jobs:
117117
# Generate a comment body:
118118
body="This PR\n\n- updates the error databases\n\nThe following error codes were added:\n\n${table}"
119119
120-
# Add the comment body to the workflow output after escaping to preserve newlines:
121-
body="${body//'%'/'%25'}"
122-
body="${body//$'\n'/'%0A'}"
123-
body="${body//$'\r'/'%0D'}"
120+
# Add the comment body to the workflow output after escaping to render newlines:
121+
body="${body//\\n/'%0A'}"
124122
echo "body=${body}" >> $GITHUB_OUTPUT
125123
126124
# Disable Git hooks:

lib/node_modules/@stdlib/error/tools/database/scripts/build.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ var shell = require( 'child_process' ).execSync;
2727
var logger = require( 'debug' );
2828
var writeFile = require( '@stdlib/fs/write-file' ).sync;
2929
var objectKeys = require( '@stdlib/utils/keys' );
30-
var data = require( './../data/data.json' );
30+
var merge = require( '@stdlib/utils/merge' );
31+
var existing = require( './../data/data.json' );
3132

3233

3334
// VARIABLES //
@@ -125,6 +126,7 @@ function main() {
125126
var codes;
126127
var fopts;
127128
var code;
129+
var data;
128130
var msgs;
129131
var next;
130132
var keys;
@@ -136,10 +138,10 @@ function main() {
136138
debug( 'Extracting errors and generate error codes if not yet present...' );
137139
messages = new Set();
138140
next = '00';
139-
codes = objectKeys( data );
141+
codes = objectKeys( existing );
140142
for ( i = 0; i < codes.length; i++ ) {
141143
code = codes[ i ];
142-
messages.add( data[ code ] );
144+
messages.add( existing[ code ] );
143145
if ( code >= next ) {
144146
next = nextCode( code );
145147
}
@@ -182,6 +184,7 @@ function main() {
182184
debug( 'Executing command: %s', command );
183185
msgs = msgs.concat( shell( command ).toString().split( '\n' ) );
184186

187+
data = {};
185188
types = {};
186189
for ( i = 0; i < msgs.length; i++ ) {
187190
msg = msgs[ i ];
@@ -203,11 +206,12 @@ function main() {
203206
fopts = {
204207
'encoding': 'utf8'
205208
};
206-
writeFile( OUTPUT_JSON, JSON.stringify( data ), fopts );
209+
writeFile( OUTPUT_JSON, JSON.stringify( merge( existing, data ), fopts ) );
207210

208211
debug( 'Writing to CSV file...' );
209212
fopts = {
210-
'encoding': 'utf8'
213+
'encoding': 'utf8',
214+
'flag': 'a' // Append to existing file
211215
};
212216
keys = objectKeys( data );
213217
csv = '';

0 commit comments

Comments
 (0)