@modea/modea-increment-version

Increments version and build numbers in specified files

Usage no npm install needed!

<script type="module">
  import modeaModeaIncrementVersion from 'https://cdn.skypack.dev/@modea/modea-increment-version';
</script>

README

Modea Increment Version Library

A npm package that increments build and version numbers.

What it does

Increments version and build numbers in specified files.

Optionally it can also follow git flow on a bitbucket repo.

For example: you have just finished a new feature and pushed that onto your dev branch. If you run this script, it can create a new branch, increment build and version numbers and then PR that branch onto master and dev and merge those PR's if no conflicts arise.

Install

npm install @modea/modea-increment-version

If using nvm, run the following

nvm install 10.16.3
nvm use 10.16.3

Usage

Once installed create a file at the base of your repo with the file name .incrementrc

In that file enter a valid json list of files you want changed and where, and optionally git information if you want the script to push to git

You can then run

increment [major | minor | patch | build]

Where major increments the first version number, minor the second, and patch the third

so

increment -t patch

on version 1.9.3 build 27 would increment to 1.9.4 and 28

increment -t build

on version 1.9.3 build 27 would increment to 1.9.3 and 28

File Object:

{
 "colloquialName": "the colloquial name for this file",
 "path": "path from repo root of the file you want changed",
 "changes": [
   {
     "type": "wether this is a [build] number or [version] code",
     "startIdentifier": "the text right before the build or version code that uniquely identifies it",
     "endIdentifier": "the text right after"
   }
 ]
}

Git Object

{
  "branchName": "the name of the branch you want to push the changes to. You can include version and build numbers in this by writting {{fileColloquialName.[version | build]}}",
  "pr": {
    "createUrl": "url to curl to for creating a PR",
    "mergeUrl": "url to curl to for merging a PR",
    "branches": A list of branches you want to PR onto [
      {
        "name": "branch name",
        "mergeStrategy": "which merge strategy to use for merging the PR"
      },
    ]
  },
  "user": {
    "name": "git username to use in curl request",
    "password": "git password to use in curl request"
  }}

Example

Sample .incrementrc file for changing version and build number in build.gradle for android and version and build number in info.plist for ios

{
 "files": [
   {
     "colloquialName": "android",
     "path": "android/app/build.gradle",
     "changes": [
       {
         "type": "version",
         "startIdentifier": "versionName \"",
         "endIdentifier": "\n"
       },
       {
         "type": "build",
         "startIdentifier": "versionCode ",
         "endIdentifier": "\n"
       }
     ]
   },
   {
     "colloquialName": "ios",
     "path": "ios/App/App/Info.plist",
     "changes": [
       {
         "type": "version",
         "startIdentifier": "<key>CFBundleShortVersionString</key>\n\t<string>",
         "endIdentifier": "</string>"
       },
       {
         "type": "build",
         "startIdentifier": "<key>CFBundleVersion</key>\n\t<string>",
         "endIdentifier": "</string>"
       }
     ]
   }
 ],
  "git": {
    "branchName": "release/v{{ios.version}}",
    "pr": {
      "createUrl": "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pullrequests",
      "mergeUrl": "https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/pullrequests/$PR_ID/merge",
      "branches": [
        {
          "name": "development",
          "mergeStrategy": "squash"
        },
        {
          "name": "master",
          "mergeStrategy": "squash"
        }
      ]
    },
    "user": {
      "name": "modea-integrator",
      "password": "$MODEA_INTEGRATOR_SECRET"
    }}
}


What the build.gradle file looks like:

...
        minSdkVersion 21
        targetSdkVersion 29
        versionCode 1568
        versionName '10.4.3'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
...

What the info.plist file looks like:

...
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.9.3</string>
    <key>CFBundleURLTypes</key>
...
    </array>
    <key>CFBundleVersion</key>
    <string>27</string>
    <key>FIREBASE_ANALYTICS_COLLECTION_ENABLED</key>
...

bitbucket-pipelines.yml

  custom:
    increment-patch-version:
      - step:
          image: node:10
          script:
            - increment patch
    increment-minor-version:
      - step:
          image: node:10
          script:
            - increment minor
    increment-major-version:
      - step:
          image: node:10
          script:
            - increment major

Future Work

  • Command line options for

    • path to config file
    • changing only specified files out of the ones in the config file
    • turning git on or off
  • git changes

    • Use with github ci as well as bitbucket pipeline
    • custom commit messages
    • tagging support
    • just pushing straight back to specified branch (no PR's)