Fix crowdin's branch selection for non-tty environment, add support for CI-provided branch name [skip ci]

Show crowdin's error at any depth

Show branch name on i18n:push

Unpack git .pack objects to fix automatic branch detect (seems like a workaround for a workaround 🙃)

Detect git branch from CI if available.
Replace git-repo-info with git-rev-sync (maintained)

Fix accidentally removed git installation for Yarn job
This commit is contained in:
ErickSkrauch 2020-07-22 18:11:44 +03:00
parent d84497ac28
commit 930a272cd0
4 changed files with 53 additions and 11 deletions

View File

@ -7,6 +7,8 @@ variables:
YARN_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/yarn"
CYPRESS_CACHE_FOLDER: "$CI_PROJECT_DIR/cache/cypress"
GIT_DEPTH: 10
stages:
- prepare
- test

View File

@ -4,6 +4,7 @@
import chalk from 'chalk';
import fs from 'fs';
import path from 'path';
import util from 'util';
import axios from 'axios';
import JSON5 from 'json5';
@ -13,7 +14,7 @@ import ch from 'chalk';
import iso639 from 'iso-639-1';
import { prompt, DistinctQuestion } from 'inquirer';
import getRepoInfo from 'git-repo-info';
import git from 'git-rev-sync';
import { crowdin as config } from './../../config';
@ -183,8 +184,22 @@ async function ensureDirectory(dirPath: string, branchId?: number): Promise<numb
}, Promise.resolve<number>(null));
}
function getGitBranch(): string {
if (process.env.CI_COMMIT_BRANCH) {
return process.env.CI_COMMIT_BRANCH;
}
const branch = git.branch();
if (branch.startsWith('Detached')) {
throw new Error(`Cannot automatically detect git branch. Received "${branch}"`);
}
return branch;
}
async function pull(): Promise<void> {
const { branch: branchName } = getRepoInfo();
const branchName = getGitBranch();
const isMasterBranch = branchName === 'master';
let branchId: number | undefined;
@ -299,7 +314,7 @@ async function push(): Promise<void> {
},
];
const { branch: branchName } = getRepoInfo();
const branchName = getGitBranch();
const isMasterBranch = branchName === 'master';
if (!isMasterBranch) {
@ -307,12 +322,12 @@ async function push(): Promise<void> {
name: 'publishInBranch',
type: 'confirm',
default: true,
message: `Should be strings published in its own branch [${chalk.green(getRepoInfo().branch)}]?`,
message: `Should be strings published in its own branch [${chalk.green(branchName)}]?`,
});
}
let disapproveTranslates = true;
let publishInBranch = isMasterBranch;
let publishInBranch = !isMasterBranch;
try {
const answers = await prompt(questions);
disapproveTranslates = answers[0]; // eslint-disable-line prefer-destructuring
@ -400,6 +415,7 @@ async function push(): Promise<void> {
console.error(`Unknown action ${action}`);
}
} catch (exception) {
console.error(exception);
console.error(util.inspect(exception, { depth: null }));
process.exit(1);
}
})();

View File

@ -14,7 +14,7 @@
"@crowdin/crowdin-api-client": "^1.8.0",
"axios": "^0.19.2",
"chalk": "^4.0.0",
"git-repo-info": "^2.1.1",
"git-rev-sync": "^2.0.0",
"glob": "^7.1.6",
"inquirer": "7.0.6",
"iso-639-1": "^2.1.3",
@ -22,6 +22,7 @@
"progress": "^2.0.3"
},
"devDependencies": {
"@types/git-rev-sync": "^2.0.0",
"@types/inquirer": "^6.5.0",
"@types/json5": "^0.0.30",
"@types/progress": "^2.0.3",

View File

@ -3411,6 +3411,11 @@
dependencies:
"@types/node" "*"
"@types/git-rev-sync@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@types/git-rev-sync/-/git-rev-sync-2.0.0.tgz#9de6e18cb01e65f769de77175bbe93254664023e"
integrity sha512-qGYApbb0m8Ofy3pwYks+kYVIZQAN/cqNucJGbl5O5GpLw9JSzp74rkTWDhPv3brrJfJb5/ixtimLJpo4tfh2QA==
"@types/glob@^7.1.1":
version "7.1.1"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575"
@ -8467,10 +8472,14 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"
git-repo-info@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/git-repo-info/-/git-repo-info-2.1.1.tgz#220ffed8cbae74ef8a80e3052f2ccb5179aed058"
integrity sha512-8aCohiDo4jwjOwma4FmYFd3i97urZulL8XL24nIPxuE+GZnfsAyy/g2Shqx6OjUiFKUXZM+Yy+KHnOmmA3FVcg==
git-rev-sync@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/git-rev-sync/-/git-rev-sync-2.0.0.tgz#82fb77d9281efe7e7947569380dda4d1c19f4cb3"
integrity sha512-vnHFv2eocTmt/wHqZm3ksxtVshK4vptT0cEoumk6hAYRFx3do6Qo7xHBTBCv29+r3ZZCQOQ1i328MUCsYF7AUw==
dependencies:
escape-string-regexp "1.0.5"
graceful-fs "4.1.15"
shelljs "0.7.7"
glob-base@^0.3.0:
version "0.3.0"
@ -8636,6 +8645,11 @@ good-listener@^1.2.2:
dependencies:
delegate "^3.1.2"
graceful-fs@4.1.15:
version "4.1.15"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.15.tgz#ffb703e1066e8a0eeaa4c8b80ba9253eeefbfb00"
integrity sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==
graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.2.4:
version "4.2.4"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb"
@ -14598,6 +14612,15 @@ shell-quote@1.7.2:
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.7.2.tgz#67a7d02c76c9da24f99d20808fcaded0e0e04be2"
integrity sha512-mRz/m/JVscCrkMyPqHc/bczi3OQHkLTqXHEFu0zDhK/qfv3UcOA4SVmRCLmos4bhjr9ekVQubj/R7waKapmiQg==
shelljs@0.7.7:
version "0.7.7"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1"
integrity sha1-svXHfvlxSPS09uImguELuoZnz/E=
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"
shelljs@^0.8.3:
version "0.8.3"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.3.tgz#a7f3319520ebf09ee81275b2368adb286659b097"