11const core = require ( '@actions/core' ) ;
22const { execSync } = require ( 'child_process' ) ;
33const fs = require ( 'fs' ) ;
4+ const path = require ( 'path' ) ;
45
6+ // Get inputs
57const action = core . getInput ( 'action' ) ;
68const googleApiKeyJsonRaw = core . getInput ( 'google_api_key_json' ) ;
79const spreadsheetId = core . getInput ( 'spreadsheet_id' ) ;
810const localizationRoot = core . getInput ( 'localization_root' ) ;
911
10- // Parse the JSON
11- let googleApiKeyJson ;
12- try {
13- googleApiKeyJson = JSON . parse ( googleApiKeyJsonRaw ) ;
14- } catch ( error ) {
15- core . setFailed ( 'Invalid Google API Key JSON.' ) ;
16- process . exit ( 1 ) ;
17- }
18-
19- if ( ! googleApiKeyJson ) {
12+ if ( ! googleApiKeyJsonRaw ) {
2013 core . setFailed ( 'Google API Key JSON is required.' ) ;
2114 process . exit ( 1 ) ;
2215}
@@ -31,6 +24,15 @@ if (!localizationRoot) {
3124 process . exit ( 1 ) ;
3225}
3326
27+ // Parse the Google API Key JSON
28+ let googleApiKeyJson ;
29+ try {
30+ googleApiKeyJson = JSON . parse ( googleApiKeyJsonRaw ) ;
31+ } catch ( error ) {
32+ core . setFailed ( 'Invalid Google API Key JSON.' ) ;
33+ process . exit ( 1 ) ;
34+ }
35+
3436// Debug logging
3537core . info ( `Action: ${ action } ` ) ;
3638core . info ( `Google API Key JSON: ${ googleApiKeyJson ? 'Provided' : 'Not Provided' } ` ) ;
@@ -45,16 +47,18 @@ process.env.SPREADSHEET_ID = spreadsheetId;
4547process . env . LOCALIZATION_ROOT = localizationRoot ;
4648
4749try {
50+ let scriptPath ;
4851 if ( action === 'push' ) {
49- const scriptPath = require . resolve ( './scripts/push-json-to-google-sheets.js' ) ;
50- execSync ( `node ${ scriptPath } ` , { stdio : 'inherit' } ) ;
52+ scriptPath = path . join ( __dirname , 'scripts' , 'push-json-to-google-sheets.js' ) ;
5153 } else if ( action === 'pull' ) {
52- const scriptPath = require . resolve ( './scripts/pull-google-sheets-to-json.js' ) ;
53- execSync ( `node ${ scriptPath } ` , { stdio : 'inherit' } ) ;
54+ scriptPath = path . join ( __dirname , 'scripts' , 'pull-google-sheets-to-json.js' ) ;
5455 } else {
5556 core . setFailed ( `Unknown action: ${ action } ` ) ;
5657 process . exit ( 1 ) ;
5758 }
59+
60+ // Execute the corresponding script
61+ execSync ( `node ${ scriptPath } ` , { stdio : 'inherit' } ) ;
5862} catch ( error ) {
5963 core . setFailed ( `Action failed with error: ${ error . message } ` ) ;
6064 process . exit ( 1 ) ;
0 commit comments