How to use shipjs-lib - 10 common examples

To help you get started, we’ve selected a few shipjs-lib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github algolia / shipjs / packages / shipjs / src / step / release / createGitHubRelease.js View on Github external
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) {
github algolia / shipjs / packages / shipjs / src / step / release / gitPush.js View on Github external
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 });
    }
  });
github algolia / shipjs / packages / shipjs / src / step / release / __tests__ / runPublish.spec.js View on Github external
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.",
github algolia / shipjs / packages / shipjs / src / step / prepare / __tests__ / updateVersionMonorepo.spec.js View on Github external
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',
    });
github algolia / shipjs / packages / shipjs / src / helper / __tests__ / validateBeforePrepare.spec.js View on Github external
it('does not return error if current branch is correct', () => {
    getCurrentBranch.mockImplementation(() => 'master');
    const result = validate(defaultOpts);
    expect(result).toBe(true);
  });
github algolia / shipjs / packages / shipjs / src / step / prepare / __tests__ / validate.spec.js View on Github external
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);
  });
github algolia / shipjs / packages / shipjs / src / step / prepare / __tests__ / validate.spec.js View on Github external
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);
  });
github algolia / shipjs / packages / shipjs / src / step / prepare / __tests__ / updateVersionMonorepo.spec.js View on Github external
},
      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);
github algolia / shipjs / packages / shipjs / src / step / prepare / __tests__ / updateVersionMonorepo.spec.js View on Github external
]);
    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",
        },
      ]
    `);
github algolia / shipjs / packages / shipjs / src / step / prepare / getRevisionRange.js View on Github external
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`;