Skip to content

Commit 3527921

Browse files
committed
Update entrypoint.js
1 parent b9c2432 commit 3527921

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

entrypoint.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
const core = require('@actions/core');
22
const { execSync } = require('child_process');
33
const fs = require('fs');
4+
const path = require('path');
45

6+
// Get inputs
57
const action = core.getInput('action');
68
const googleApiKeyJsonRaw = core.getInput('google_api_key_json');
79
const spreadsheetId = core.getInput('spreadsheet_id');
810
const 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
3537
core.info(`Action: ${action}`);
3638
core.info(`Google API Key JSON: ${googleApiKeyJson ? 'Provided' : 'Not Provided'}`);
@@ -45,16 +47,18 @@ process.env.SPREADSHEET_ID = spreadsheetId;
4547
process.env.LOCALIZATION_ROOT = localizationRoot;
4648

4749
try {
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

Comments
 (0)