plusbump 2.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ec8ef91d65437db4805a4a786e477a761163c07b1e564c02a2238ff9bf74e240
4
+ data.tar.gz: 24ec388c3fba89941f132e740217238c098e239e0447acafc897d413801b2e08
5
+ SHA512:
6
+ metadata.gz: d3f01a1020c8b8b7dc83b34bb53fd5e23e043fbcd630a55f233b1cba2102ab2508c8f2a95a0a2cbfc3e6d8e2a8e38ee8600f242a97fd7cef69051fcad54adf5f
7
+ data.tar.gz: c35ef1df7ecc41f79330f88d6cdfc00f7e5e0b8e716c19e30b4fea2147209da7300f136ce7e243458147c502cef564789097a0eba73258d4e0e8ddf818f73bb3
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Dockerfile ADDED
@@ -0,0 +1,18 @@
1
+ FROM ruby:2.5
2
+ RUN ruby --version
3
+ RUN apt-get update && \
4
+ apt-get install cmake -y
5
+ WORKDIR /tmp
6
+ RUN gem install docopt
7
+ RUN gem install rugged
8
+
9
+ RUN git clone https://github.com/Praqma/PlusBump.git -b rebirth .
10
+ RUN gem build plusbump.gemspec
11
+ RUN gem install plusbump-2.0.pre.alpha.gem
12
+
13
+ RUN mkdir -p /repo
14
+ WORKDIR /repo
15
+ VOLUME /repo
16
+
17
+ ENTRYPOINT ["plusbump"]
18
+ CMD ["--help"]
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in plusbump.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Praqma
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ ---
2
+ maintainer: jkrag
3
+ ---
4
+ # Automatic version bumping
5
+
6
+ ### Initial "requirement" description
7
+
8
+ Look at all commits between <ref> and HEAD.
9
+
10
+ Look for commit-message mentions of +major or +minor (unless different patterns where specified ). +patch is implicit as the default if none of the others where specified.
11
+
12
+ If a version string was specified, bump the provided semver string correctly.
13
+ I.e. increase the highest bumped level, and reset those below to 0.
14
+
15
+ Currently, the bump leaves any part of semver after `-` intact (e.g. 1.3.14-alpha3+as34df32), but I reserve the right to change my mind on this :-D
16
+
17
+ If no version string was specified bump the version 0.0.0, i.e. return either 1.0.0, 0.1.0 or 0.0.1
18
+
19
+ ### Other features
20
+ The tool already supports a few more features:
21
+
22
+ ### Helping users
23
+ If you decide to require bumps on every commit (e.g. instead of assuming +patch as default), then it can be very helpful to users set up a push hook (pre-receive on Git) that rejects commits without a bump.
24
+
25
+ I have successfully done this on BitBucket using the "Jira Hooks for BitBucket" plugin (that we were using anyway), and used the following regex:
26
+ ```
27
+ (^|(.|\n)*\s)\+(major|minor|patch)($|\s(.|\n)*)
28
+ ```
29
+
30
+ This RegEx should also be quite usable in other plugins or handwritten hooks as it does not require multiline or other switches to be supported.
31
+ It allows the `+bump` message to appear anywhere in the commit message as long as it is not adjacent to other text. (i.e. `my+patch` and `+patching` will be rejected.
32
+
33
+
34
+ ## CodeScene analysis
35
+ [![](https://codescene.io/projects/2928/status.svg) Get more details at **codescene.io**.](https://codescene.io/projects/2928/jobs/latest-successful/results)
36
+ =======
37
+ ### Developer guide
38
+
39
+ #### How to test
40
+
41
+ Simply run `rake` for the simple test without output, and `rake doc` for the more verbose output. Test are located in the `spec` folder.
42
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
8
+ desc "Verbose test output"
9
+ task :doc do
10
+ puts `rspec --format doc`
11
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "plusbump"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/plusbump ADDED
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ #encoding: utf-8
3
+ require 'docopt'
4
+ require 'plusbump'
5
+
6
+ doc = <<DOCOPT
7
+ Usage:
8
+ plusbump -h|--help
9
+ plusbump <ref> [options]
10
+ plusbump --latest=<tag-glob> [options]
11
+ plusbump --version
12
+
13
+ Arguments:
14
+ <ref> A git reference. If specified, PlusBump will search for bumps from HEAD back to this <ref> instead of searching for a tag.
15
+
16
+ Options:
17
+ -h --help Show this screen.
18
+
19
+ -l --latest=<tag-glob>
20
+
21
+ Specify a glob pattern to search for last matching tag instead of
22
+ providing a specific ref.
23
+ Will attempt to use everything after <tag-glob> as the version string
24
+ so be sure to provide _entire_ prefix.
25
+ E.g. use "R_" if your versions are "R_1.2.3"
26
+
27
+ --version Shows current version of PlusBump
28
+ --debug Debug flag
29
+
30
+ DOCOPT
31
+
32
+ # Note: If you are reading the above usage in the source code and not using --help,
33
+ # then ignore the double escapes in the usage examples.
34
+ # On the command line you have to write --majorpattern='\+major'
35
+ # The extra escape is to make it print that way in the usage message.
36
+
37
+ begin
38
+ # Parse Commandline Arguments
39
+ input = Docopt::docopt(doc, version: PlusBump::VERSION)
40
+ puts input if input['--debug']
41
+ rescue Docopt::Exit => e
42
+ puts e.message
43
+ exit
44
+ end
45
+
46
+ #TODO: input['--latest'].flatten[0]
47
+ puts PlusBump.bump(input['<ref>'], input['--latest'], debug: input['--debug'])
48
+
49
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ properties([parameters([booleanParam(defaultValue: false, description: '', name: 'isRelease')])])
2
+
3
+ node("dockerhost1") {
4
+
5
+ stage("checkout") {
6
+ checkout scm
7
+ }
8
+
9
+ stage("build") {
10
+ //Let's just use PAC container, it has ll the necessary tools installed
11
+ docker.image("praqma/pac").inside() {
12
+ sh 'bundler exec rake'
13
+ }
14
+ }
15
+
16
+ stage("changelog") {
17
+ pac()
18
+ }
19
+
20
+ stage("release") {
21
+ try {
22
+ if(params?.isRelease) {
23
+ echo "Building release"
24
+ } else {
25
+ echo "Not building release"
26
+ }
27
+
28
+ } finally {
29
+ echo "Done with release"
30
+ }
31
+ }
32
+
33
+ }
@@ -0,0 +1,29 @@
1
+ multibranchPipelineJob("PlusBump") {
2
+ factory {
3
+ workflowBranchProjectFactory {
4
+ scriptPath('jenkins-pipeline/Jenkinsfile')
5
+ }
6
+ }
7
+ branchSources {
8
+ git {
9
+ credentialsId("github")
10
+ remote("https://github.com/Praqma/PlusBump.git")
11
+ }
12
+ }
13
+
14
+ configure {
15
+ def traitBlock = it / 'sources' / 'data' / 'jenkins.branch.BranchSource' / 'source' / 'traits'
16
+ traitBlock << 'jenkins.plugins.git.traits.CloneOptionTrait' {
17
+ extension(class: 'hudson.plugins.git.extensions.impl.CloneOption') {
18
+ shallow(false)
19
+ noTag(false)
20
+ reference()
21
+ depth(0)
22
+ honorRefspec(false)
23
+ }
24
+ }
25
+
26
+ traitBlock << 'jenkins.plugins.git.traits.BranchDiscoveryTrait' { }
27
+ }
28
+
29
+ }
data/lib/plusbump.rb ADDED
@@ -0,0 +1,101 @@
1
+ require "plusbump/version"
2
+ require 'semver'
3
+ require 'rugged'
4
+
5
+ module PlusBump
6
+ def self.bump(ref, latest, debug: false)
7
+
8
+ # Defaults
9
+ major = /\+major/
10
+ minor = /\+minor/
11
+ patch = /\+patch/
12
+ base = '0.0.0'
13
+ prefix = ''
14
+
15
+ # Init Repo from current directory
16
+ repository = Rugged::Repository.new(Dir.pwd)
17
+ tagcollection = Rugged::TagCollection.new(repository)
18
+
19
+
20
+ w = Rugged::Walker.new(repository)
21
+ # Initialise the walker to start at current HEAD
22
+ head = repository.lookup(repository.head.target.oid)
23
+ w.push(head)
24
+
25
+ if latest.nil?
26
+ tail = repository.rev_parse(ref)
27
+ w.hide(tail)
28
+ else
29
+ candidates = []
30
+ puts "Searching for at tag that matches the glob pattern: " + latest if debug
31
+ tagcollection.each(latest+'*') do |tag|
32
+ unless repository.merge_base(tag.target, head).nil?
33
+ puts "Found matching tag on correct branch: " + tag.name if debug
34
+ candidates << tag
35
+ end
36
+ end
37
+
38
+ if candidates.empty?
39
+ puts "No matching tag found for "+latest
40
+ else
41
+ candidates.sort! {|a,b| a.target.time <=> b.target.time }
42
+ latest_match = candidates.last
43
+ puts "Newest matching tag: #{latest_match.name}" if debug
44
+ puts "Newest matching tag sha: #{latest_match.target.oid}" if debug
45
+ #set target of matching commit as the tail of our walker
46
+ w.hide(latest_match.target)
47
+ #unless input['<semver_version_string>']
48
+ base = latest_match.name.sub(latest,'')
49
+ puts "latest: #{latest}" if debug
50
+ puts "match.Name: #{latest_match.name}" if debug
51
+ puts "Base: #{base}" if debug
52
+ #end
53
+
54
+ end
55
+ end
56
+
57
+ # Handle X.Y.Z-SPECIAL by saving SPECIAL part for later
58
+ split = base.split('-')
59
+ v_number = split[0].split('.')
60
+ special = ''
61
+
62
+ #TODO: Above could probably be re-written to use the semver gem for parsing.
63
+
64
+ major_bump = false
65
+ minor_bump = false
66
+ patch_bump = false
67
+
68
+ #walk through all commits looking for version bump requests
69
+ w.each do |commit|
70
+ puts "Commit: " + commit.oid if debug
71
+ if major =~ commit.message
72
+ puts "bumps major" if debug
73
+ major_bump = true
74
+ elsif minor =~ commit.message
75
+ puts "bump minor" if debug
76
+ minor_bump = true
77
+ else
78
+ patch_bump = true
79
+ end
80
+ end
81
+
82
+ result = SemVer.new(v_number[0].to_i, v_number[1].to_i, v_number[2].to_i, special)
83
+
84
+ if major_bump
85
+ result.major += 1
86
+ result.minor = 0
87
+ result.patch = 0
88
+ elsif minor_bump
89
+ result.minor += 1
90
+ result.patch = 0
91
+ elsif patch_bump
92
+ result.patch += 1
93
+ else
94
+ puts "No version increment"
95
+ end
96
+
97
+ final_res = prefix + (result.format "%M.%m.%p%s")
98
+
99
+ return final_res
100
+ end
101
+ end
@@ -0,0 +1,3 @@
1
+ module PlusBump
2
+ VERSION = "2.0.0.beta"
3
+ end
data/plusbump.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'plusbump/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "plusbump"
8
+ spec.version = PlusBump::VERSION
9
+ spec.authors = ["Jan Krag", "Mads Nielsen"]
10
+ spec.email = ["jak@praqma.net", "man@praqma.net"]
11
+
12
+ spec.summary = %q{PlusBump ruby gem}
13
+ spec.description = %q{Use this gem to automate the automation of version bumping in git}
14
+ spec.homepage = "https://github.com/Praqma/PlusBump"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ spec.bindir = "bin"
22
+ spec.executables << 'plusbump'
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.14"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.7"
28
+ spec.add_runtime_dependency 'docopt', "~> 0.6.1"
29
+ spec.add_runtime_dependency 'rugged', "~> 0.26"
30
+ spec.add_runtime_dependency 'semver', "~> 1.0"
31
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plusbump
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.beta
5
+ platform: ruby
6
+ authors:
7
+ - Jan Krag
8
+ - Mads Nielsen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2018-10-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.14'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '1.14'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '3.7'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '3.7'
56
+ - !ruby/object:Gem::Dependency
57
+ name: docopt
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.6.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.6.1
70
+ - !ruby/object:Gem::Dependency
71
+ name: rugged
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '0.26'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '0.26'
84
+ - !ruby/object:Gem::Dependency
85
+ name: semver
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.0'
98
+ description: Use this gem to automate the automation of version bumping in git
99
+ email:
100
+ - jak@praqma.net
101
+ - man@praqma.net
102
+ executables:
103
+ - plusbump
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".rspec"
108
+ - Dockerfile
109
+ - Gemfile
110
+ - LICENSE
111
+ - README.md
112
+ - Rakefile
113
+ - bin/console
114
+ - bin/plusbump
115
+ - bin/setup
116
+ - jenkins-pipeline/Jenkinsfile
117
+ - jenkins-pipeline/pipeline.groovy
118
+ - lib/plusbump.rb
119
+ - lib/plusbump/version.rb
120
+ - plusbump.gemspec
121
+ homepage: https://github.com/Praqma/PlusBump
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">"
137
+ - !ruby/object:Gem::Version
138
+ version: 1.3.1
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.7.7
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: PlusBump ruby gem
145
+ test_files: []