فهرست منبع

Merge pull request #4241 from weseek/support/add-bump-versions

support: Add bump-versions script
Yuki Takei 4 سال پیش
والد
کامیت
c16f5d4dc9

+ 6 - 1
.github/release-drafter.yml

@@ -13,7 +13,6 @@ categories:
       - 'bug'
       - 'bug'
   - title: '🧰 Maintenance'
   - title: '🧰 Maintenance'
     labels:
     labels:
-      - 'chore'
       - 'support'
       - 'support'
       - 'dependencies'
       - 'dependencies'
 category-template: '### $TITLE'
 category-template: '### $TITLE'
@@ -33,6 +32,12 @@ autolabeler:
   - label: 'support'
   - label: 'support'
     branch:
     branch:
       - '/support\/.+/'
       - '/support\/.+/'
+    title:
+      - '/chore/i'
+      - '/ci/i'
+      - '/docs/i'
+      - '/test/i'
+
 exclude-labels:
 exclude-labels:
   - 'exclude from changelog'
   - 'exclude from changelog'
 template: |
 template: |

+ 0 - 21
.github/workflows/auto-labeling.yml

@@ -1,21 +0,0 @@
-name: Auto Labeling
-
-on:
-  pull_request:
-    branches:
-      - master
-    # Only following types are handled by the action, but one can default to all as well
-    types: [opened, reopened, synchronize]
-
-jobs:
-
-  # Refs: https://github.com/release-drafter/release-drafter
-  auto-labeling:
-    runs-on: ubuntu-latest
-
-    steps:
-      - uses: release-drafter/release-drafter@v5
-        with:
-          disable-releaser: true
-        env:
-          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}    

+ 42 - 0
.github/workflows/pr-to-master.yml

@@ -0,0 +1,42 @@
+name: PR to master
+
+on:
+  pull_request:
+    branches:
+      - master
+    # Only following types are handled by the action, but one can default to all as well
+    types: [opened, reopened, edited, synchronize]
+
+jobs:
+
+  # Refs: https://github.com/release-drafter/release-drafter
+  auto-labeling:
+    runs-on: ubuntu-latest
+
+    if: github.event.pull_request.merged == true
+
+    steps:
+      - uses: release-drafter/release-drafter@v5
+        with:
+          disable-releaser: true
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+
+  check-title:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: amannn/action-semantic-pull-request@v3.4.2
+        with:
+          types: |
+            feat
+            imprv
+            fix
+            support
+            chore
+            ci
+            docs
+            test
+          requireScope: false
+          validateSingleCommit: true
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

+ 4 - 0
bin/bump-versions/README.md

@@ -0,0 +1,4 @@
+bump-versions.js
+==============
+
+Custom cli for bumping package versions based on [algolia/shipjs@0.23.3](https://github.com/algolia/shipjs/tree/v0.23.3/packages/shipjs)

+ 16 - 0
bin/bump-versions/cli.js

@@ -0,0 +1,16 @@
+import { print, parseArgs } from 'shipjs/src/util';
+import bumpVersions from './flow/bump-versions';
+
+export async function cli(argv) {
+  const { fn, arg: argSpec } = bumpVersions;
+  try {
+    const opts = parseArgs(argSpec, argv);
+    await fn(opts);
+  } catch (error) {
+    if (error.code === 'ARG_UNKNOWN_OPTION') {
+      print(error);
+    } else {
+      throw error;
+    }
+  }
+}

+ 71 - 0
bin/bump-versions/flow/bump-versions.js

@@ -0,0 +1,71 @@
+import semver from 'semver';
+import { loadConfig, getCurrentVersion, getReleaseType } from 'shipjs-lib';
+
+import printDryRunBanner from 'shipjs/src/step/printDryRunBanner';
+import confirmNextVersion from 'shipjs/src/step/prepare/confirmNextVersion';
+import updateVersion from 'shipjs/src/step/prepare/updateVersion';
+import updateVersionMonorepo from 'shipjs/src/step/prepare/updateVersionMonorepo';
+import installDependencies from 'shipjs/src/step/prepare/installDependencies';
+
+import printHelp from '../step/printHelp';
+
+async function bumpVersions({
+  help = false,
+  dir = '.',
+  dryRun = false,
+  increment = 'patch',
+  preid = 'RC',
+}) {
+  if (help) {
+    printHelp();
+    return;
+  }
+  if (dryRun) {
+    printDryRunBanner();
+  }
+
+  const config = await loadConfig(dir, 'bump-versions.config');
+  
+  // get current version
+  const { monorepo } = config;
+  const currentVersion =
+    monorepo && monorepo.mainVersionFile
+      ? getCurrentVersion(dir, monorepo.mainVersionFile)
+      : getCurrentVersion(dir);
+  
+  // determine next version
+  let nextVersion = semver.inc(currentVersion, increment, preid); // set preid if type is 'prerelease'
+  nextVersion = await confirmNextVersion({
+    yes: true,
+    currentVersion,
+    nextVersion,
+    dryRun,
+  });
+  const releaseType = getReleaseType(nextVersion);
+
+  // update
+  const updateVersionFn = monorepo
+    ? updateVersionMonorepo
+    : updateVersion;
+  await updateVersionFn({ config, nextVersion, releaseType, dir, dryRun });
+  installDependencies({ config, dir, dryRun });
+}
+
+const arg = {
+  '--dir': String,
+  '--help': Boolean,
+  '--dry-run': Boolean,
+  '--increment': String,
+  '--preid': String,
+
+  // Aliases
+  '-d': '--dir',
+  '-h': '--help',
+  '-D': '--dry-run',
+  '-i': '--increment',
+};
+
+export default {
+  arg,
+  fn: bumpVersions,
+};

+ 12 - 0
bin/bump-versions/index.js

@@ -0,0 +1,12 @@
+#!/usr/bin/env node
+
+require = require('esm')(module);
+(async function() {
+  try {
+    process.env.SHIPJS = true;
+    await require('./cli').cli(process.argv);
+  } catch (e) {
+    console.error(e);
+    process.exit(1);
+  }
+})();

+ 55 - 0
bin/bump-versions/step/printHelp.js

@@ -0,0 +1,55 @@
+import runStep from 'shipjs/src/step/runStep';
+import { print } from 'shipjs/src/util';
+import { bold, underline } from 'shipjs/src/color';
+
+export default () =>
+  runStep({}, () => {
+    const indent = (line) => `\t${line}`;
+
+    const help = `--help`;
+    const dir = `--dir ${underline('PATH')}`;
+    const increment = `--increment ${underline('LEVEL')}`;
+    const preId = `--preid ${underline('IDENTIFIER')}`;
+    const dryRun = `--dry-run`;
+    const all = [help, dir, increment, preId, dryRun]
+      .map((x) => `[${x}]`)
+      .join(' ');
+
+    const messages = [
+      bold('NAME'),
+      indent('bump-versions - Bump versions of packages.'),
+      '',
+      bold('USAGE'),
+      indent(`node ./bin/github-actions/bump-versions ${all}`),
+      '',
+      bold('OPTIONS'),
+      indent(`-h, ${help}`),
+      indent('  Print this help'),
+      '',
+      indent(`-d, ${dir}`),
+      indent(
+        `  Specify the ${underline(
+          'PATH'
+        )} of the repository (default: the current directory).`
+      ),
+      '',
+      indent(`-i, ${increment}`),
+      indent(
+        `  Specify the ${underline(
+          'LEVEL'
+        )} for semver.inc() to increment a version (default: 'patch').`
+      ),
+      '',
+      indent(`${preId}`),
+      indent(
+        `  Specify the ${underline(
+          'IDENTIFIER'
+        )} for semver.inc() with 'prerelease' type (default: 'RC').`
+      ),
+      '',
+      indent(`-D, ${dryRun}`),
+      indent('  Displays the steps without actually doing them.'),
+      '',
+    ];
+    print(messages.join('\n'));
+  });

+ 7 - 1
bump-versions.config.js

@@ -1,6 +1,12 @@
 module.exports = {
 module.exports = {
   monorepo: {
   monorepo: {
     mainVersionFile: 'package.json',
     mainVersionFile: 'package.json',
-    packagesToBump: ['packages/app', 'packages/common'],
+    packagesToBump: [
+      'packages/app',
+      'packages/core',
+      'packages/slack',
+      'packages/ui',
+      'packages/plugin-*',
+    ],
   },
   },
 };
 };