Skip to content

Commit

Permalink
better error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
WizardCM committed Oct 5, 2024
1 parent 2ae90d2 commit 3ee277a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Build
run: npm run build
- name: Push
if: ${{ github.event_name == 'push' && github.ref_name == 'main' }}
if: ${{ github.event_name == 'push' }}
run: |
git config --global user.email "<>"
git config --global user.name "Build Bot"
Expand Down
102 changes: 63 additions & 39 deletions src/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ export async function processBuild(
*/
export async function createDesktopFile(languageFiles: Map<string, Map<string, string>>): Promise<void> {
const filePath = 'UI/cmake/linux/com.obsproject.Studio.desktop';
const fileExists = await FSE.exists(filePath);
ACTIONS.info(`desktopFile cwd '${process.cwd()}', file ${fileExists ? 'exists' : 'does not exist'}`);
const desktopFile = normalize(await FSE.readFile(filePath, 'utf-8'));
let result = '';
for (const line of desktopFile.split('\n')) {
Expand All @@ -364,7 +366,12 @@ export async function createDesktopFile(languageFiles: Map<string, Map<string, s
result += `${translation[0]}[${language[0]}]=${translation[1]}\n`;
}
}
await FSE.writeFile(filePath, result);
try {
await FSE.writeFile(filePath, result);
} catch (_e) {
let e = _e as Error;
ACTIONS.info(`desktopFile write failed - ${e.message}`);
}
}

/**
Expand Down Expand Up @@ -411,47 +418,64 @@ export async function createLocaleFile(languageList: Map<string, string>, langua
* @param submodules A list of submodules.
*/
function pushChanges(detachedSubmodules: string[], submodules: string[]): void {
if (process.env.CROWDIN_SYNC_SKIP_PUSH) {
return;
}
exec(`git config --global user.name '${STRINGS.git.committer.name}'`);
exec(`git config --global user.email '${STRINGS.git.committer.email}'`);
for (const submodule of submodules) {
process.chdir(`plugins/${submodule}`);
if (exec('git status --porcelain').length === 0) {
ACTIONS.info("WIZARDCM DEBUG - Running PushChanges.");
try {
if (process.env.CROWDIN_SYNC_SKIP_PUSH) {
return;
}
exec(`git config --global user.name '${STRINGS.git.committer.name}'`);
exec(`git config --global user.email '${STRINGS.git.committer.email}'`);
for (const submodule of submodules) {
process.chdir(`plugins/${submodule}`);
if (exec('git status --porcelain').trim().length === 0) {
process.chdir('../..');
continue;
}
exec('git add data/locale/*-*.ini');
if (exec('git diff --staged').trim().length === 0) {
process.chdir('../..');
continue;
}
ACTIONS.info(`Pushing commit for submodule ${submodule}`);
exec(`git commit -m '${STRINGS.git.commitTitle}'`);
exec('git push');
process.chdir('../..');
continue;
}
exec('git add data/locale/*-*.ini');
for (const allowedPath of [
'AUTHORS',
'plugins/*/data/locale/*-*.ini',
'plugins/mac-virtualcam/src/obs-plugin/data/locale/*-*.ini',
'UI/data/locale.ini',
'UI/data/locale/*-*.ini',
'UI/cmake/linux/com.obsproject.Studio.desktop',
'UI/frontend-plugins/*/data/locale/*-*.ini'
]) {
ACTIONS.info(exec(`git add '${allowedPath}'`));
ACTIONS.info(`Seems git add worked for '${allowedPath}'`);
}
for (const submodule of submodules) {
exec(`git add plugins/${submodule}`);
}
for (const submodule of detachedSubmodules) {
ACTIONS.info(`${submodule} has commits not pushed to the main repository. Only pushing to submodule.`);
exec(`git checkout HEAD -- plugins/${submodule}`);
exec(`git submodule update --init plugins/${submodule}`);
}
if (exec('git status --porcelain').length === 0) {
ACTIONS.info('No changes in main repository. Skipping push.');
return;
}
ACTIONS.info(exec('git diff --staged'));
ACTIONS.info("Pushing commit for main repo");
exec(`git commit -m '${STRINGS.git.commitTitle}'`);
exec('git push');
process.chdir('../..');
}
for (const allowedPath of [
'AUTHORS',
'plugins/*/data/locale/*-*.ini',
'plugins/mac-virtualcam/src/obs-plugin/data/locale/*-*.ini',
'UI/data/locale.ini',
'UI/data/locale/*-*.ini',
'UI/cmake/linux/com.obsproject.Studio.desktop',
'UI/frontend-plugins/*/data/locale/*-*.ini'
]) {
exec(`git add '${allowedPath}'`);
}
for (const submodule of submodules) {
exec(`git add plugins/${submodule}`);
}
for (const submodule of detachedSubmodules) {
ACTIONS.info(`${submodule} has commits not pushed to the main repository. Only pushing to submodule.`);
exec(`git checkout HEAD -- plugins/${submodule}`);
exec(`git submodule update --init plugins/${submodule}`);
}
if (exec('git status --porcelain').length === 0) {
ACTIONS.info('No changes in main repository. Skipping push.');
return;
} catch (_e) {
let e = _e as Error;
ACTIONS.info(e.stack || 'No error stack');
ACTIONS.info(`WIZARDCM DEBUG - Failed PushChanges in cwd '${process.cwd()}'.`);
ACTIONS.info(`Desktop file exists - ${FSE.existsSync('UI/cmake/linux/com.obsproject.Studio.desktop') ? 'yes' : 'no?!'}`);
ACTIONS.setFailed(e);
}
exec(`git commit -m '${STRINGS.git.commitTitle}'`);
exec('git push');
}

(async () => {
Expand All @@ -467,8 +491,8 @@ function pushChanges(detachedSubmodules: string[], submodules: string[]): void {
generateAuthors(getGitContributors(), await getTranslators(results[0][3].targetLanguageIds)),
processBuild(results[0][2], await getSourceFiles(results[0][1]), results[0][1])
]);
createLocaleFile(results[1][1].languageList, results[0][3].languageCodeMap);
createDesktopFile(results[1][1].desktopFileTranslations);
await createLocaleFile(results[1][1].languageList, results[0][3].languageCodeMap);
await createDesktopFile(results[1][1].desktopFileTranslations);
pushChanges(results[0][0], submodules);
} catch (e) {
ACTIONS.setFailed(e as Error);
Expand Down

0 comments on commit 3ee277a

Please sign in to comment.