包详细信息

@cmflow/cli

camfou19.6kMIT2.0.5

An awesome Git Flow

自述文件

@clubmed/cli aka ClubMed Flow


npm version semantic-release code style: prettier

npm i -g @cmflow/cli

CmFlow release using Semantic Release

Installation

CmFlow is compatible with semantic-release 📦🚀. You can use CmFlow release to deploy your projects based on CmFlow convention.

Add the cmflow to your project:

npm i --save-dev @cmflow/cli

Edit your package.json and add the following configuration:

{
  "flow": {
    "branch": {
      "develop": "master",
      "production": "master"
    }
  }
}

Then create release.config.js with this configuration:

import { defineConfig } from '@cmflow/cli'

export default defineConfig({
  verifyConditions: ['@cmflow/cli/semantic/core/verify-conditions'],
  analyzeCommits: ['@cmflow/cli/semantic/core/analyze-commits'],
  verifyRelease: ['@cmflow/cli/semantic/core/verify-release'],
  generateNotes: [
    [
      "@cmflow/cli/semantic/conditional", // add this task to trigger build npm task
      {
        // when: (context) => context.branch.type === "release" //  default condition to run the task
        run: ["@semantic-release/core/release-notes-generator"]
      }
    ]
  ],
  prepare: [
    '@cmflow/cli/semantic/core/prepare/bump-version',
    [
      '@cmflow/cli/semantic/core/prepare/run', // add this task to trigger build npm task
      {
        command: 'build'
      }
    ],
    [
      '@cmflow/cli/semantic/core/prepare/run', // add this task to trigger build npm task
      {
        command: 'test_e2e'
      }
    ],
    [
      '@cmflow/cli/semantic/core/conditional', // add this task to trigger build npm task
      {
        // when: (context) => context.branch.type === "release" //  default condition to run the task
        run:  [
          '@cmflow/cli/semantic/core/prepare/commit'
        ]
      }
    ]
  ],
  publish: [
    [
      '@cmflow/cli/semantic/core/conditional',
      {
        // when: (context) => context.branch.type === "release" //  default condition to run the task
        run: [
          '@cmflow/cli/semantic/core/sync-repository',
          '@semantic-release/github'
        ] // only run if the conditional rule is true
      }
    ],
    [
      '@cmflow/cli/semantic/core/exit', // run process.exit(0) if the branch is not a release branch - legacy: maybe not necessary now all task are conditional
      {
        when: (context) => context.nextRelease.channel === 'prerelease'
      }
    ]
  ],
  success: [
    [
      '@cmflow/cli/semantic/core/conditional',
      {
        // when: (context) => context.branch.type === "release" //  default condition to run the task
        run: '@semantic-release/github' // only run if the conditional rule is true
      }
    ]
  ],
  fail: [
    [
      "@cmflow/cli/semantic/core/conditional",
      {
        // when: (context) => context.branch.type === "release" //  default condition to run the task
        run: '@semantic-release/github' // only run if the conditional rule is true
      }
    ]
  ],
  npmPublish: false
})

Then edit your package.json add the following tasks on script property:

{
  "script": {
    "release": "cmrelease",
    "release_dry_run": "cmrelease --dry-run"
  }
}

Now, CmFlow and semantic release are correctly installed on your project.

Condition step (publish, success, fail)

CMFlow provide a @cmflow/cli/semantic/core/conditional task to run one task or many task only if a condition is true. The condition is a function that takes the semantic context as parameter and return a boolean.

You can customize the condition to run the task by adding a when property to the configuration object.

export default defineConfig({
  publish: [
    '@cmflow/cli/semantic/core/conditional',
    {
      when: (context) => context.branch.type === 'release', //  default condition to run the task
      run: ['@semantic-release/github', '@semantic-release/github'] // only run if the conditional rule is true
    }
  ]
})

Build and E2E Test

CmFlow release are able to run build and test_e2e task during the prepare step. It's useful when you want to deploy a docker image on docker hub with the right revision number in the package.json. The only requirement, is to have a build and test_e2e tasks in you npm scripts.

Example:

{
  "scripts": {
    "build": "docker-compose build",
    "test_e2e": "docker-compose up -d && sleep 10 && npm run test_cucumber && docker-compose stop"
  }
}

Then:

export default defineConfig({
  prepare: [
    [
      '@cmflow/cli/semantic/core/run',
      {
        command: 'build'
      }
    ],
    [
      '@cmflow/cli/semantic/core/run',
      {
        command: 'test_e2e'
      }
    ]
  ]
})

Generate release.info file

CmFlow release generate a release.info file in the root of your project. This file contains the branch name.

import { defineConfig } from '@cmflow/cli'

export default defineConfig({
  prepare: [
    '@cmflow/cli/semantic/prepare/bump-version',
    [
      '@cmflow/cli/semantic/prepare/release-info',
      {
        path: './resources/release.info'
      }
    ]
  ]
})

Deploy on Docker Hub

Add the following configuration to your release.config.js:

import { defineConfig } from '@cmflow/cli'

export default defineConfig({
  publish: [
    '@cmflow/cli/semantic/docker/publish'
  ]
});

Publish & Clean docker tags

import { defineConfig } from '@cmflow/cli'

export default defineConfig({
  success: [
    '@cmflow/cli/semantic/docker/success'
  ]
})

Configure CI

CmFlow release can be used with Travis CI, Circle CI and GitLab. You have to create these environments variables to allow git release note deployment, commit push and docker image deployment.

Variable Description
PROJECT_NAME The project to publish artifact on docker
SCM_TOKEN A SCM Token (GH_TOKEN or GITLAB_TOKEN)
GH_TOKEN (deprecated) A GitHub token personal access token.
GIT_USER_EMAIL User mail to sign the commit produced by CmFlow release
GIT_USER_NAME User name to sign the commit produced by CmFlow release
DOCKER_HUB_ID The docker hub id
DOCKER_HUB_PWD The docker password account