Code Monkey home page Code Monkey logo

version-bumper's Introduction

Version Bumper

total runs runs per month repos

Github action that automatically bumps versions in selected files based on versioning scheme and rules.

Please create an issue if you have found a bug or wish for additional functionality.

Example Usage

With options file

name: Manage versions

on: [push]

jobs:
  bump:
    runs-on: ubuntu-latest
   
    steps:
      # Checkout action is required
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '12'
      - name: Bump Versions
        uses: michmich112/version-bumper@master
        with:
          options-file: './examples/example-options-full.json'
          github-token: ${{ secrets.GITHUB_TOKEN }}

Without options file

name: Manage versions

on: [push, pull_request]

jobs:
  bump:
    runs-on: ubuntu-latest
   
    steps:
      # Checkout action is required
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v1
        with:
          node-version: '12'
      - name: Bump Versions
        uses: michmich112/version-bumper@master
        with:
          scheme: semantic
          username: DoomGuy
          email: [email protected]
          version-file: "./package.json"
          files: >
            [
              "./package-lock.json"
            ] 
          rules: >
            [{
              "trigger":"commit",
              "branch": "staging",
              "suffix": "-beta",
              "bump":"build"
            },{
              "trigger": "pull-request",
              "destBranch": "main",
              "suffix": "-rc",
              "bump": "minor",
              "tag": true
            }, {
              "trigger":"commit",
              "branch":"release",
              "bump":"major",
              "tag": true,
              "reset":["minor","build"]
            }]'
          github-token: ${{ secrets.GITHUB_TOKEN }}

Configuration

Inputs/Parameters

Parameter Required
options-file false
username false
email false
github-token true
scheme true
custom-scheme false
skip false
version-file true
files true
rules true

options-file (Optional)

File path to the options file containing run options. The options file must be JSON.

Example usage:

options-file: './.github/version-bumper-options.json'

username (Optional)

Username of the account to perform the version bump commit. Overrides the default of VersionBumper.

Example usage:

usernmae: VersionBumper

email (Optional)

Email of the account to perform the version bump commit (if this email is linked to a github account, github will be able to identify the user an attribute the commit to them). Overrides the default.

Example usage:

github-token (Required)

Required github token used for committing version updates.

Example usage:

# Action workflow provides a secret with a pre-authenticated token
github-token: ${{ secrets.GITHUB_TOKEN }}

Note: The following inputs are only required if they are not present in the options file or if you have not specified an options file. Workflow inputs will be used over options in the options file.

scheme (Required)

Versioning scheme to use. Predefined schemes are:

Scheme Definition
semantic major.minor[.build]
org_semantic major.minor.build

Submit an issue to request additional predefined schemes.

You can define a custom scheme by using the custom scheme.

custom-scheme (Optional)

Custom scheme to use. Required if scheme is custom.

Schemes are defined with tags (e.g. major) separated by one or more separators: .,;:-_><.
Example: main.secondary->patch
You can make elements optional by wrapping them in brackets.
Example: main.secondary[->patch].
If we have main:1, secondary:0 ,patch:0 the resulting version printout will be 1.0.
If patch:1 the resulting version printout will be 1.0->1.

skip (Optional)

Adds [SKIP] prefix to the commit message to prevent CI/CD build.

version-file (Required)

File path where the current version can be found.

Example usages:

# First match will be used as the version. Both versions are equivalent
version-file: "./package.json"
version-file: "{'path':'./package.json'}"

# Will use the match found on line 3
# Fallback to initial match if no match is found on specified line
# must be in stringified JSON form
version-file: "{'path':'./package.json', 'line':3}"

files (Required)

Files where version should be updated. Must be a JSON stringified array. Searches for a match of the current version at at the specified line (if applicable). No need to add the version-file.
Example usages:

# First match will be used as the version except if line number is passed.
files: >
  [
    "./file1.json", 
    {"path":"./file2.txt"}, 
    {"path":"./file3.yaml", "line":5}
  ]

# No additional files
files: '[]'

rules (Required)

Version update rules: a JSON stringified array of bumping rules objects.
Rule type definition:

/**
 * Predefine a rule for bumping version numbers based on:
 * - trigger :
 *      - commit: new commit on branch,
 *      - pull request: new pull request on branch,
 * - branch : branch regex which should trigger the rule
 */
interface BumpRule {
    /**
     * Optional branch on which the rule should take effect
     * if no branch is passed the rule will take effect on every branch which triggers the workflow
     */
    branch?: string,

    /**
     * Optional destinatoin branch for which the rule should take effect
     * This is primarily used for pull_request triggers. On commit triggers destBranch is automtically equal to the branch parameter
     */
    destBranch?: string,

    /**
     * What items in the version number need to be bumped
     * precisely matches the tag items
     */
    bump?: string | string[],

    /**
     * Prefix to apply on the new version
     */
    prefix?: string,

    /**
     * Reset elements in the version number
     * E.g
     * With version desc = major.minor[.build] -> current: 1.2.3
     * set reset: ['build']
     * => 1.2.0
     */
    reset?: string | string[]
    
    /**
     * Indicate that this bump should add a tag to the commit with the new version number
     * If multiple rules match the current run, only one of them needs to allow the tag for it to take effect
     */
    tag?: boolean,

    /**
     * Action that triggers the bump to occur
     *    - commit: new commit on branch (includes the creation of a new branch),
     *    - pull request: new pull request on branch (only when pr is Opened),
     *    - manual: trigger the workflow manually using workflow_dispatch
     * Note: your workflow must accept the 'push' event for the commit trigger and 'pull_request' event for pull-request trigger
     * Note: your workflow must accept the 'workflow_dispatch' event to use the manual trigger
     */
    trigger: 'commit' | 'pull-request' | 'manual',

    /**
     * Suffix to apply on the new version
     */
    suffix?: string,
}

Example usage:

# for semantic versioning i.e. scheme = major.minor[.build]
# {"trigger":"commit","bump":"build"} -> bump the build tag on every commit on any branch
# {"trigger": "commit", "branch": "master", "bump":"minor", "reset":"build"} -> bump minor and reset build on every commit to master
# {"trigger":"commit","branch":"release","bump":"major", "reset":["minor","build"]} -> bump major on any commit to branch "release" and reset minor and build
rules: >
  [{
    "trigger":"commit",
    "bump":"build"
  }, {
    "trigger": "commit", 
    "branch": "master",
    "bump":"minor", 
    "reset":"build"
  }, {
    "trigger":"commit",
    "branch":"release",
    "bump":"major",
    "reset":["minor","build"]
  }]

Options

You can find an example options file here The options file has the following available options:

interface BumperOptionsFile {
    
    // the scheme chosen, 
    // use 'custom' to use a custom scheme
    scheme: string,  
    
    // use for custom scheme definitions
    schemeDefinition?: string,

    // Add the [SKIP] prefix to skip build
    skip?: boolean,
    
    // path file containing the current version
    // may include line if other possible matches
    versionFile: string | {path: string, line:number},

    // Array of paths to files containing the version to update
    // may include line if other possible matches
    files: ( string | {path: string, line:number} )[],

    // Array of rule objects
    rules: BumpRule[]
}

interface BumpRule {

    /**
     * Optional branch on which the rule should take effect
     */
    branch?: string,

    /**
     * Optional destinatoin branch for which the rule should take effect
     * This is primarily used for pull_request triggers. On commit triggers destBranch is automtically equal to the branch parameter
     */
    destBranch?: stirng,

    /**
     * What items in the version number need to be bumped
     */
    bump?: string | string[],
  
    /**
     * Prefix to apply on the new version
     */
    prefix?: string,

    /**
     * Reset elements in the version number
     * E.g
     * With version desc = major.minor[.build] -> current: 1.2.3
     * set reset: ['build']
     * => 1.2.0
     */
    reset?: string | string[],
  
    /**
     * Suffix to apply on the new version
     */
    suffix?: string,

    /**
     * Indicate that this bump should add a tag to the commit with the new version number
     * If multiple rules match the current run, only one of them needs to allow the tag for it to take effect
     */
    tag?: boolean,

    /**
     * Action that triggers the bump to occur
     */
    trigger: 'commit' | 'pull-request' | 'manual',

}

Contributors

Thank you to

for their help and contributions to the project!

Notes

This action uses the gh-action-stats package to track usage. See the data collected at gh-action-stats-js.

version-bumper's People

Contributors

dependabot[bot] avatar margani avatar markiannucci avatar michmich112 avatar migueltarga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

version-bumper's Issues

Add ability to make a version number the commit hash

Options:

{
  "scheme": "custom",
  "schemeDefinition": "major.minor.build[-commithash]"
  "rules": [
     {
       "trigger": "commit",
       "branch":"develop" 
       "bump": "commithash",
       "type": "hash", // type hash sets the value to the complete commit hash
     }, {
       "trigger":"commit",
       "branch": "beta" 
       "bump": "commit-hash",
       "type": "minhash", // minified hash
     }, {
       "trigger": "commit",
       "branch": "master",
       "bump": "build",
       "reset": "commithash",
    // no need for "type" as default type is number
     }
  ]
}
       
}

Example: if merge commit has hash: 7da9a258c94f9b8aca53feddbc216f1391a87ff5 and short-hash 7da9a25 we could get 1.12.2-7da9a25 as a version on the beta branch

Cannot bump on branches with a '/' in them

E.g branch: ft-v4/version-testing

{"scheme":"custom","schemeDefinition":"major.minor.build","versionFile":{"path":"./packages/controllers/package.json"},"files":[{"path":"./packages/controllers/package.json"}],"rules":[{"trigger":"commit","branch":"ft-v4/version-testing","bump":"build"}]}
/[0-9]+\.[0-9]+\.[0-9]+/
Match found line 3 -> 1.0.4
Trigger -> push
/[0-9]+\.[0-9]+\.[0-9]+/
Match found line 3 -> 1.0.4
State -> {"curVersion":"1.0.4","newVersion":"1.0.4","schemeRegExp":{},"schemeDefinition":"major.minor.build","tag":false,"trigger":"commit","branch":"version-testing","files":[{"path":"./packages/controllers/package.json"}]}
/usr/bin/git checkout version-testing
error: pathspec 'version-testing' did not match any file(s) known to git
Error: The process '/usr/bin/git' failed with exit code 1

Allow custom placement of prefix/suffix within scheme definition

Description of issue:
The recommended versioning semantic for pre-release npm packages is to have the -preid.version at the end of a version scheme.

Example:
1.2.0-alpha.0 or 1.2.0-rc.0

Currently, this is not possible using the prefix or suffix options in the versioning rules, since the suffix is added at the very end of the version.

Version bumper errors and doesn't bump the version on a feature branch when using the pull-request trigger

I configured my github actions workflow file with the following settings:

  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

I noticed when the action runs with the rules configured to bump the version on pull-request, I get the following error in the action:

/usr/bin/git checkout PushToChromeStore
error: pathspec 'PushToChromeStore' did not match any file(s) known to git
Error: The process '/usr/bin/git' failed with exit code 1

I'm not sure why it is having problems checking out the branch.

Remove node modules from repo

See if github has updated their actions so i can push code without having to put all the node_modules or build everytime

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.