Skip to content

Commit ec5fda3

Browse files
fix: release setting
1 parent 9960473 commit ec5fda3

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

.github/workflows/released.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ jobs:
99
- name: Release GitHub Actions
1010
uses: technote-space/release-github-actions@pre
1111
with:
12-
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
1313
COMMIT_NAME: Technote
1414
COMMIT_EMAIL: [email protected]

src/utils/command.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const cloneForBranch = async (pushDir: string, branch: string, context: Context)
3232
signale.info(`Cloning the branch %s from the remote repo`, branch);
3333

3434
const url = getGitUrl(context);
35-
await execAsync(`git -C ${pushDir} clone --quiet --branch=${branch} --depth=1 ${url} .`, true);
35+
await execAsync(`git -C ${pushDir} clone --quiet --branch=${branch} --depth=1 ${url} .`, true, 'git clone', true);
3636
};
3737

3838
const config = async (pushDir: string) => {
@@ -55,14 +55,14 @@ const push = async (pushDir: string, branch: string, context: Context) => {
5555
signale.info('Pushing to %s@%s', getRepository(context), branch);
5656

5757
const url = getGitUrl(context);
58-
await execAsync(`git -C ${pushDir} push --quiet "${url}" "${branch}":"${branch}"`, true);
58+
await execAsync(`git -C ${pushDir} push --quiet "${url}" "${branch}":"${branch}"`, true, 'git push');
5959
};
6060

6161
const cloneForBuild = async (buildDir: string, context: Context) => {
6262
signale.info('Cloning the working commit from the remote repo for build');
6363

6464
const url = getGitUrl(context);
65-
await execAsync(`git -C ${buildDir} clone --depth=1 ${url} .`, true);
65+
await execAsync(`git -C ${buildDir} clone --depth=1 ${url} .`, true, 'git clone');
6666
await execAsync(`git -C ${buildDir} fetch origin ${context.ref}`);
6767
await execAsync(`git -C ${buildDir} checkout -qf ${context.sha}`);
6868
};
@@ -71,22 +71,21 @@ const runBuild = async (buildDir: string) => {
7171
signale.info('=== Running build for release ===');
7272
let commands = getBuildCommands();
7373
const buildCommand = detectBuildCommand(buildDir);
74-
const hasInstallCommand = commands.filter(command => command.includes('npm run install') || command.includes('yarn install'));
74+
const hasInstallCommand = commands.filter(command => command.includes('npm run install') || command.includes('yarn install')).length > 0;
7575
if (!hasInstallCommand) {
7676
commands.push('yarn install');
7777
}
7878
if (typeof buildCommand === 'string') {
79-
commands = commands.filter(command => buildCommand.startsWith(`npm run ${command}`) || buildCommand.startsWith(`yarn ${command}`));
79+
commands = commands.filter(command => !buildCommand.startsWith(`npm run ${command}`) && !buildCommand.startsWith(`yarn ${command}`));
8080
commands.push(`yarn ${buildCommand}`);
8181
}
8282
if (!hasInstallCommand) {
8383
commands.push('yarn install --production');
8484
}
8585

8686
const current = process.cwd();
87-
await execAsync(`cd ${buildDir}`);
8887
for (const command of commands) {
89-
await execAsync(command);
88+
await execAsync(`cd ${buildDir} && ${command}`);
9089
}
9190
await execAsync(`cd ${current}`);
9291
};
@@ -97,10 +96,18 @@ const copyFiles = async (buildDir: string, pushDir: string) => {
9796
await execAsync(`rsync -rl --exclude .git --delete "${buildDir}/" ${pushDir}`);
9897
};
9998

100-
const execAsync = (command: string, quiet: boolean = false) => new Promise<string>((resolve, reject) => {
99+
const execAsync = (command: string, quiet: boolean = false, altCommand: string | null = null, suppressError: boolean = false) => new Promise<string>((resolve, reject) => {
100+
if (quiet && 'string' === typeof altCommand) signale.info(`Run command: ${altCommand}`);
101101
if (!quiet) signale.info(`Run command: ${command}`);
102-
exec(command + (quiet ? ' > /dev/null 2>&1' : ''), (error, stdout) => {
103-
if (error) reject(new Error(`command ${command} exited with code ${error}.`));
104-
resolve(stdout);
102+
exec(command + (quiet ? ' > /dev/null 2>&1' : '') + (suppressError ? ' || :' : ''), (error, stdout) => {
103+
if (error) {
104+
if (quiet) {
105+
if ('string' === typeof altCommand) reject(new Error(`command [${altCommand}] exited with code ${error.code}.`));
106+
else reject(new Error(`command exited with code ${error.code}.`));
107+
} else reject(new Error(`command [${command}] exited with code ${error.code}.`));
108+
} else {
109+
if (!quiet) console.log(stdout);
110+
resolve(stdout);
111+
}
105112
});
106113
});

0 commit comments

Comments
 (0)