Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assetsToUpload,
dir,
version,
tagName,
});
if (dryRun) {
print('Creating a release with the following:');
print(` - content: ${content}`);
if (assetPaths.length > 0) {
print(` - assets: ${assetPaths.join(' ')}`);
}
return;
}
const { owner, name: repo } = getRepoInfo(remote, dir);
const octokit = new Octokit({
auth: `token ${process.env.GITHUB_TOKEN}`,
});
const {
data: { upload_url }, // eslint-disable-line camelcase
} = await octokit.repos.createRelease({
owner,
repo,
tag_name: tagName, // eslint-disable-line camelcase
name: tagName,
body: content,
});
if (assetPaths.length > 0) {
runStep({ title: 'Pushing to the remote.' }, () => {
const currentBranch = getCurrentBranch(dir);
const { mergeStrategy, remote } = config;
const destinationBranch = getBranchNameToMergeBack({
currentBranch,
mergeStrategy,
});
if (currentBranch === destinationBranch) {
gitPush({ remote, refs: [currentBranch, tagName], dir, dryRun });
} else {
// currentBranch: 'master'
// destinationBranch: 'develop'
// flow: develop -> master -> (here) develop
run({ command: `git checkout ${destinationBranch}`, dir, dryRun });
run({ command: `git merge ${currentBranch}`, dir, dryRun });
gitPush({ remote, refs: [currentBranch, tagName], dir, dryRun });
}
});
it('works with monorepo', () => {
const output = [];
mockPrint(print, output);
expandPackageList.mockImplementationOnce(() => [
'/package-a',
'/package-b',
]);
runPublish({
isYarn: true,
config: {
publishCommand: ({ defaultCommand }) => defaultCommand,
monorepo: {},
},
releaseTag: 'latest',
dir: '.',
dryRun: false,
});
expect(output).toMatchInlineSnapshot(`
Array [
"› Publishing.",
it('works', () => {
expandPackageList.mockImplementationOnce(() => [
'packages/a',
'packages/b',
]);
const versionUpdated = jest.fn();
updateVersionMonorepo({
config: {
versionUpdated,
monorepo: {
packagesToBump: ['packages/*'],
mainVersionFile: 'lerna.json',
},
},
dir: '.',
nextVersion: '1.2.3',
releaseType: 'patch',
});
it('does not return error if current branch is correct', () => {
getCurrentBranch.mockImplementation(() => 'master');
const result = validate(defaultOpts);
expect(result).toBe(true);
});
it('works', () => {
validateBeforePrepare.mockImplementation(() => true);
const version = '1.2.3';
const branch = 'legacy';
getCurrentVersion.mockImplementation(() => version);
getCurrentBranch.mockImplementation(() => branch);
const { currentVersion, baseBranch } = validate({
config: {
getTagName: () => 'v1.2.3',
mergeStrategy: {
toSameBranch: ['master'],
toReleaseBranch: {
legacy: 'v1',
},
},
},
});
expect(currentVersion).toEqual(version);
expect(baseBranch).toEqual(branch);
expect(exitProcess).toHaveBeenCalledTimes(0);
});
it('works', () => {
validateBeforePrepare.mockImplementation(() => true);
const version = '1.2.3';
const branch = 'legacy';
getCurrentVersion.mockImplementation(() => version);
getCurrentBranch.mockImplementation(() => branch);
const { currentVersion, baseBranch } = validate({
config: {
getTagName: () => 'v1.2.3',
mergeStrategy: {
toSameBranch: ['master'],
toReleaseBranch: {
legacy: 'v1',
},
},
},
});
expect(currentVersion).toEqual(version);
expect(baseBranch).toEqual(branch);
expect(exitProcess).toHaveBeenCalledTimes(0);
});
},
dir: '.',
nextVersion: '1.2.3',
releaseType: 'patch',
});
expect(updateVersion).toHaveBeenCalledTimes(3);
expect(updateVersion.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"dir": ".",
"fileName": "lerna.json",
"nextVersion": "1.2.3",
},
]
`);
expect(updateVersion.mock.calls[1]).toMatchInlineSnapshot(`
Array [
Object {
"dir": "packages/a",
"nextVersion": "1.2.3",
},
]
`);
expect(updateVersion.mock.calls[2]).toMatchInlineSnapshot(`
Array [
Object {
"dir": "packages/b",
"nextVersion": "1.2.3",
},
]
`);
expect(versionUpdated).toHaveBeenCalledTimes(1);
]);
const versionUpdated = jest.fn();
updateVersionMonorepo({
config: {
versionUpdated,
monorepo: {
packagesToBump: ['packages/*'],
mainVersionFile: 'lerna.json',
},
},
dir: '.',
nextVersion: '1.2.3',
releaseType: 'patch',
});
expect(updateVersion).toHaveBeenCalledTimes(3);
expect(updateVersion.mock.calls[0]).toMatchInlineSnapshot(`
Array [
Object {
"dir": ".",
"fileName": "lerna.json",
"nextVersion": "1.2.3",
},
]
`);
expect(updateVersion.mock.calls[1]).toMatchInlineSnapshot(`
Array [
Object {
"dir": "packages/a",
"nextVersion": "1.2.3",
},
]
`);
const tagNotExistingMessage = `Git tag 'v${currentVersion}' doesn't exist.`;
if (yes) {
print(error(tagNotExistingMessage));
print(
info(
'Ship.js cannot figure out since which commit you want to release.'
)
);
print(info('Try again with the following option added:'));
print(info(' --commit-from SHA'));
exitProcess(1);
}
print(warning(tagNotExistingMessage));
const commits = silentExec(`git log --pretty=format:"%h%d %s"`, {
dir,
})
.toString()
.split('\n');
const { answer } = await inquirer.prompt([
{
type: 'list',
pageSize: 10,
name: 'answer',
message: 'Since which commit do you want to release?',
choices: commits.map((commit, index) => `${index + 1}) ${commit}`),
},
]);
const [, commit] = answer.split(' ');
revisionRange = `${commit}..HEAD`;