incr 0.7.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: beae18538716cd3443ecea4076ee9d05c0192c97cbbcf92e8c2b9e775b70bbf9
4
- data.tar.gz: 8e02e3fe88c0b370bc48091efb75f15e0e288e8f11635bf7c036bc0d7b06ea81
3
+ metadata.gz: e95e6dda3b7379ca152abf66e47ff235ceb4ad4955acdf65dd635e9d0d3153dc
4
+ data.tar.gz: a86b07882030147b13ab42468628b736aed39f2b2f7b0bd3e6e5bd3e016c98c7
5
5
  SHA512:
6
- metadata.gz: 75ebb280db2da0b09bcbb9f0e73fb806f05386af61ac2d76b8c907a256576e024b99b97844ffbf5a5d42a68857f647f071a92b587bd8cc43815e86e461a53fd0
7
- data.tar.gz: f1a1d70c6159aafbec950b02220a4af567675d8c270c7dfc973c2a1a6da498af6e2163ce40d1607452b2f712205b4eaa1bb058f893489b80821d8ff85d34a7b5
6
+ metadata.gz: 3baa71dfd348aaaec137dc6f979fc90a014bcba728f354a3a56bde4314b1a59fe9c2d756b184776f63031268e7d4073cebe754fa789f1261bef51c3ef5096aea
7
+ data.tar.gz: ad9654640846bfac5788f58b0873a9a4e9ae1616b51c43aee1b2e03dff9a83dce51ce2ea136402693efa1795708c4422568e3ab05bc110be9a264908b02d35b0
@@ -0,0 +1,25 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+ branches:
9
+ - '**'
10
+
11
+ permissions:
12
+ contents: read
13
+
14
+ jobs:
15
+ ci:
16
+ runs-on: ubuntu-22.04
17
+
18
+ steps:
19
+ - uses: actions/checkout@v3
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: '2.7'
23
+ bundler-cache: true
24
+
25
+ - run: bundle exec rake
@@ -0,0 +1,39 @@
1
+ name: Publish RubyGem
2
+
3
+ on: workflow_dispatch
4
+
5
+ permissions:
6
+ contents: read
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-22.04
11
+
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ - uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: '2.7'
17
+ bundler-cache: true
18
+
19
+ - run: bundle exec rake
20
+
21
+ publish:
22
+ runs-on: ubuntu-22.04
23
+
24
+ steps:
25
+ - uses: actions/checkout@v3
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: '2.7'
29
+ bundler-cache: true
30
+
31
+ - run: |
32
+ mkdir -p $HOME/.gem
33
+ touch $HOME/.gem/credentials
34
+ chmod 0600 $HOME/.gem/credentials
35
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
36
+ gem build *.gemspec
37
+ gem push *.gem
38
+ env:
39
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ # To use the MeowCop gem.
2
+ inherit_gem:
3
+ meowcop:
4
+ - config/rubocop.yml
5
+
6
+ AllCops:
7
+ NewCops: disable
8
+ SuggestExtensions: false
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.7
data/Gemfile.lock CHANGED
@@ -1,23 +1,72 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- incr (0.7.1)
5
- git (= 1.3.0)
6
- gli (= 2.17.1)
4
+ incr (1.0.0)
5
+ git (= 1.12.0)
6
+ gli (= 2.21.0)
7
7
  sem_version (= 2.0.1)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
- git (1.3.0)
13
- gli (2.17.1)
12
+ addressable (2.8.1)
13
+ public_suffix (>= 2.0.2, < 6.0)
14
+ ast (2.4.2)
15
+ diff-lcs (1.5.0)
16
+ git (1.12.0)
17
+ addressable (~> 2.8)
18
+ rchardet (~> 1.8)
19
+ gli (2.21.0)
20
+ json (2.6.3)
21
+ meowcop (3.2.0)
22
+ rubocop (>= 1.13.0, < 2.0.0)
23
+ parallel (1.22.1)
24
+ parser (3.1.3.0)
25
+ ast (~> 2.4.1)
26
+ public_suffix (5.0.1)
27
+ rainbow (3.1.1)
28
+ rake (13.0.6)
29
+ rchardet (1.8.0)
30
+ regexp_parser (2.6.1)
31
+ rexml (3.2.5)
32
+ rspec (3.12.0)
33
+ rspec-core (~> 3.12.0)
34
+ rspec-expectations (~> 3.12.0)
35
+ rspec-mocks (~> 3.12.0)
36
+ rspec-core (3.12.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-expectations (3.12.1)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.12.0)
41
+ rspec-mocks (3.12.1)
42
+ diff-lcs (>= 1.2.0, < 2.0)
43
+ rspec-support (~> 3.12.0)
44
+ rspec-support (3.12.0)
45
+ rubocop (1.38.0)
46
+ json (~> 2.3)
47
+ parallel (~> 1.10)
48
+ parser (>= 3.1.2.1)
49
+ rainbow (>= 2.2.2, < 4.0)
50
+ regexp_parser (>= 1.8, < 3.0)
51
+ rexml (>= 3.2.5, < 4.0)
52
+ rubocop-ast (>= 1.23.0, < 2.0)
53
+ ruby-progressbar (~> 1.7)
54
+ unicode-display_width (>= 1.4.0, < 3.0)
55
+ rubocop-ast (1.24.1)
56
+ parser (>= 3.1.1.0)
57
+ ruby-progressbar (1.11.0)
14
58
  sem_version (2.0.1)
59
+ unicode-display_width (2.3.0)
15
60
 
16
61
  PLATFORMS
17
62
  ruby
18
63
 
19
64
  DEPENDENCIES
20
65
  incr!
66
+ meowcop (= 3.2.0)
67
+ rake (= 13.0.6)
68
+ rspec (= 3.12.0)
69
+ rubocop (= 1.38.0)
21
70
 
22
71
  BUNDLED WITH
23
- 1.16.6
72
+ 2.2.32
data/README.md CHANGED
@@ -1,13 +1,11 @@
1
1
  <p align="center">
2
2
  <a href="https://github.com/jcouture/incr">
3
- <img src="https://i.imgur.com/cHimJRm.png" alt="incr" />
3
+ <img src="https://user-images.githubusercontent.com/5007/160249855-dc0eb32f-f77d-4c5a-a995-93ac46408a68.png" alt="incr" />
4
4
  </a>
5
5
  <br />
6
- Incr is a tool to help you easily increment the version number of your NPM or Mix packages.
6
+ incr is a tool to help you easily increment the version number of your NPM or Mix packages.
7
7
  <br /><br />
8
8
  <a href="https://rubygems.org/gems/incr"><img src="http://img.shields.io/gem/v/incr.svg" /></a>
9
-
10
- <a href="https://travis-ci.org/jcouture/incr"><img src="http://img.shields.io/travis/jcouture/incr.svg" /></a>
11
9
  </p>
12
10
 
13
11
  ## What does `incr` do?
@@ -19,7 +17,7 @@ The process is detailed as follow:
19
17
  * Increment the specified segment. If you increment the minor segment, the patch segment is set to 0 and the same goes for the major segment, the minor and patch segments are set to 0.
20
18
  * Write the newly incremented version number in the relevant file(s).
21
19
  * Create a new `git commit` with the relevant file with the version number as the default message (e.g.: 0.2.1).
22
- * Create a new `git tag` pointing to the new `git commit` with the version number prefixed by a 'v' as the name (e.g.: v0.2.1).
20
+ * Create a new annotated `git tag` pointing to the new `git commit` with the version number prefixed by a 'v' as the name (e.g.: v0.2.1).
23
21
  * 💥
24
22
 
25
23
  ## Installation
@@ -31,31 +29,38 @@ The process is detailed as follow:
31
29
  ```
32
30
 
33
31
  ## Usage
32
+
34
33
  To increment the patch segment of your NPM package version number:
34
+
35
35
  ```shell
36
36
  ~> incr npm patch
37
37
  ```
38
38
 
39
39
  To increment the minor segment of your Mix package version number:
40
+
40
41
  ```shell
41
42
  ~> incr mix minor
42
43
  ```
43
44
 
44
45
  ### Arguments
46
+
45
47
  Here are some arguments that can be used with `incr`:
48
+
46
49
  - `-d` : Directory where to search for the version files (default: `.`)
47
50
  - `-t` : Tag name pattern, where `%s` will be replaced with the new version (default: `v%s`)
48
51
  - `--[no-]commit` : Commit changes. (default: enabled)
49
52
  - `--[no-]tag` : Create a git tag. (default: enabled)
50
53
 
51
54
  Example:
55
+
52
56
  ```shell
53
- ~> incr --no-tag -d ./subprojects/web/ -t MyCustomTagPrefix/%s npm patch
57
+ ~> incr --no-tag -d ./subprojects/web/ -t my-custom-tag-prefix/%s npm patch
54
58
  ```
55
59
 
56
60
  This will :
61
+
57
62
  - Search for `package.json` and `package-lock.json` files inside `./subprojects/web/` and update the patch version
58
- - Commit the changes under the message `MyCustomTagPrefix/2.3.4`
63
+ - Commit the changes under the message `my-custom-tag-prefix/2.3.4`
59
64
  - Not create a tag with the new version
60
65
 
61
66
  ## Contributing
@@ -65,5 +70,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jcoutu
65
70
  ## License
66
71
 
67
72
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
68
-
69
- The incr shield logo is based on [this icon](https://thenounproject.com/term/increment/621415/) by [blackspike](https://thenounproject.com/blackspike/), from the Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
4
+
5
+ RuboCop::RakeTask.new(:rubocop)
6
+
7
+ RSpec::Core::RakeTask.new(:test)
8
+
9
+ task default: %i(rubocop test)
data/bin/incr CHANGED
@@ -10,15 +10,15 @@ include GLI::App
10
10
  program_desc('Tasteful utility to increment the version number and create a corresponding git tag.')
11
11
  version(Incr::VERSION)
12
12
 
13
- flag [:d, :versionFileDirectory], :default_value => '.', :desc => 'Directory where to search for version file'
14
- flag [:t, :tagNamePattern], :default_value => 'v%s', :desc => 'Pattern for the tag name'
13
+ flag([:d, :version_file_dir], default_value: '.', desc: 'Directory where to search for version file')
14
+ flag([:t, :tag_name_pattern], default_value: 'v%s', desc: 'Pattern for the tag name')
15
15
 
16
- switch :commit, :default_value => true, :desc => 'Commit changes'
17
- switch :tag, :default_value => true, :desc => 'Create a git tag'
16
+ switch(:commit, default_value: true, desc: 'Commit changes')
17
+ switch(:tag, default_value: true, desc: 'Create a git tag')
18
18
 
19
19
  pre do |global, command, options, args|
20
20
  if args.length != 1 || !['major', 'minor', 'patch'].any? {|segment| args.include?(segment)}
21
- STDERR.puts('Expecting a single argument: major, minor or patch.')
21
+ warn('expecting a single argument: major, minor or patch.')
22
22
  return false
23
23
  end
24
24
  true
data/incr.gemspec CHANGED
@@ -18,7 +18,14 @@ Gem::Specification.new do |spec|
18
18
  spec.executables << 'incr'
19
19
  spec.require_paths << 'lib'
20
20
 
21
- spec.add_runtime_dependency('gli', '2.17.1')
21
+ spec.required_ruby_version = '>= 2.7'
22
+
23
+ spec.add_runtime_dependency('gli', '2.21.0')
22
24
  spec.add_runtime_dependency('sem_version', '2.0.1')
23
- spec.add_runtime_dependency('git', '1.3.0')
25
+ spec.add_runtime_dependency('git', '1.12.0')
26
+
27
+ spec.add_development_dependency('rake', '13.0.6')
28
+ spec.add_development_dependency('rspec', '3.12.0')
29
+ spec.add_development_dependency('rubocop', '1.38.0')
30
+ spec.add_development_dependency('meowcop', '3.2.0')
24
31
  end
@@ -9,14 +9,20 @@ module Incr
9
9
 
10
10
  def initialize(args, global_options)
11
11
  @segment = args[0]
12
- @mix_file_filename = File.join('.', global_options[:versionFileDirectory], 'mix.exs')
13
- @tag_pattern = global_options[:tagNamePattern]
12
+ @mix_file_filename = File.join('.', global_options[:version_file_dir], 'mix.exs')
13
+ @tag_pattern = global_options[:tag_name_pattern]
14
14
  @commit = global_options[:commit]
15
15
  @tag = global_options[:tag]
16
+ @noop = global_options[:noop]
16
17
  end
17
18
 
18
19
  def execute
19
- file_content = parse_content(@mix_file_filename)
20
+ if !File.exist?(@mix_file_filename)
21
+ warn("'#{@mix_file_filename}': file not found.")
22
+ return
23
+ end
24
+
25
+ file_content = IO.read(@mix_file_filename)
20
26
  if file_content == nil
21
27
  return
22
28
  end
@@ -30,29 +36,22 @@ module Incr
30
36
 
31
37
  puts new_tag
32
38
 
33
- repository = Incr::Service::Repository.new('.')
34
- repository.add(@mix_file_filename)
35
- repository.commit(new_tag) if @commit
36
- repository.tag(new_tag) if @tag
39
+ if not @noop
40
+ repository = Incr::Service::Repository.new('.')
41
+ repository.add(@mix_file_filename)
42
+ repository.commit(new_tag) if @commit
43
+ repository.tag(new_tag) if @tag
44
+ end
37
45
  end
38
46
 
39
47
  private
40
48
 
41
- def parse_content(filename)
42
- if !File.exist?(filename)
43
- STDERR.puts("[Err] '#{filename}' not found.")
44
- return nil
45
- end
46
-
47
- IO.read(filename)
48
- end
49
-
50
49
  def replace_file_version(old_version, new_version)
51
50
  VERSION_REPLACEMENT_PATTERNS.each do |pattern|
52
51
  old_version_pattern = format(pattern, old_version.to_s)
53
52
  new_version_pattern = format(pattern, new_version.to_s)
54
53
 
55
- Incr::Service::FileHelper.replace_string_once(@mix_file_filename, old_version_pattern, new_version_pattern)
54
+ Incr::Service::FileHelper.replace(@mix_file_filename, old_version_pattern, new_version_pattern)
56
55
  end
57
56
  end
58
57
  end
@@ -16,15 +16,26 @@ module Incr
16
16
  def initialize(args, global_options)
17
17
  @segment = args[0]
18
18
 
19
- @package_json_filename = File.join('.', global_options[:versionFileDirectory], 'package.json')
20
- @package_json_lock_filename = File.join('.', global_options[:versionFileDirectory], 'package-lock.json')
21
- @tag_pattern = global_options[:tagNamePattern]
19
+ @package_json_filename = File.join('.', global_options[:version_file_dir], 'package.json')
20
+ @package_json_lock_filename = File.join('.', global_options[:version_file_dir], 'package-lock.json')
21
+ @tag_pattern = global_options[:tag_name_pattern]
22
22
  @commit = global_options[:commit]
23
23
  @tag = global_options[:tag]
24
+ @noop = global_options[:noop]
24
25
  end
25
26
 
26
27
  def execute
27
- package_json = parse_content(@package_json_filename)
28
+ if !File.exist?(@package_json_filename)
29
+ warn("'#{@package_json_filename}': file not found.")
30
+ return
31
+ end
32
+
33
+ if !File.exist?(@package_json_lock_filename)
34
+ warn("'#{@package_json_lock_filename}': file not found.")
35
+ return
36
+ end
37
+
38
+ package_json = JSON.parse(IO.read(@package_json_filename))
28
39
  if package_json == nil
29
40
  return
30
41
  end
@@ -40,28 +51,21 @@ module Incr
40
51
 
41
52
  puts new_tag
42
53
 
43
- repository = Incr::Service::Repository.new('.')
44
- repository.add(@package_json_filename)
45
- repository.add(@package_json_lock_filename)
46
- repository.commit(new_tag) if @commit
47
- repository.tag(new_tag) if @tag
54
+ if not @noop
55
+ repository = Incr::Service::Repository.new('.')
56
+ repository.add(@package_json_filename)
57
+ repository.add(@package_json_lock_filename)
58
+ repository.commit(new_tag) if @commit
59
+ repository.tag(new_tag) if @tag
60
+ end
48
61
  end
49
62
 
50
63
  private
51
64
 
52
- def parse_content(filename)
53
- if !File.exist?(filename)
54
- STDERR.puts("[Err] '#{filename}' not found.")
55
- return nil
56
- end
57
-
58
- JSON.parse(IO.read(filename))
59
- end
60
-
61
65
  def replace_file_version(filename, new_version)
62
66
  LOOKBEHIND_PATTERNS.each do |lookbehind_pattern|
63
67
  pattern = /#{lookbehind_pattern}#{VERSION_PATTERN}/
64
- Incr::Service::FileHelper.replace_regexp_once(filename, pattern, new_version)
68
+ Incr::Service::FileHelper.replace(filename, pattern, new_version)
65
69
  end
66
70
  end
67
71
  end
@@ -1,11 +1,7 @@
1
1
  module Incr
2
2
  module Service
3
3
  class FileHelper
4
- def self.replace_string_once(filename, old_text, new_text)
5
- replace_regexp_once(filename, /#{Regexp.escape(old_text)}/, new_text)
6
- end
7
-
8
- def self.replace_regexp_once(filename, pattern, replacement_text)
4
+ def self.replace(filename, pattern, replacement_text)
9
5
  old_content = File.read(filename)
10
6
  new_content = old_content.sub(pattern, replacement_text)
11
7
  File.open(filename, 'w') { |file| file << new_content }
@@ -16,7 +16,7 @@ module Incr
16
16
  end
17
17
 
18
18
  def tag(name)
19
- @git.add_tag(name)
19
+ @git.add_tag(name, annotate: true, message: name)
20
20
  end
21
21
  end
22
22
  end
data/lib/incr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Incr
2
- VERSION = '0.7.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -0,0 +1,30 @@
1
+ defmodule Foobar.MixProject do
2
+ use Mix.Project
3
+
4
+ @version "1.0.0"
5
+
6
+ def project do
7
+ [
8
+ app: :foobar,
9
+ version: @version,
10
+ elixir: "~> 1.13",
11
+ start_permanent: Mix.env() == :prod,
12
+ deps: deps()
13
+ ]
14
+ end
15
+
16
+ # Run "mix help compile.app" to learn about applications.
17
+ def application do
18
+ [
19
+ extra_applications: [:logger]
20
+ ]
21
+ end
22
+
23
+ # Run "mix help deps" to learn about dependencies.
24
+ defp deps do
25
+ [
26
+ # {:dep_from_hexpm, "~> 0.3.0"},
27
+ # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
28
+ ]
29
+ end
30
+ end
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "foobar",
3
+ "version": "7.0.0",
4
+ "lockfileVersion": 1,
5
+ "requires": true,
6
+ "dependencies": {
7
+ "is-number": {
8
+ "version": "7.0.0",
9
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
10
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "foobar",
3
+ "version": "7.0.0",
4
+ "dependencies": {
5
+ "is-number": "^7.0.0"
6
+ }
7
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "foobar",
3
+ "version": "7.0.0",
4
+ "lockfileVersion": 2,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "foobar",
9
+ "version": "7.0.0",
10
+ "dependencies": {
11
+ "is-number": "^7.0.0"
12
+ }
13
+ },
14
+ "node_modules/is-number": {
15
+ "version": "7.0.0",
16
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
17
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
18
+ "engines": {
19
+ "node": ">=0.12.0"
20
+ }
21
+ }
22
+ },
23
+ "dependencies": {
24
+ "is-number": {
25
+ "version": "7.0.0",
26
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
27
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "foobar",
3
+ "version": "7.0.0",
4
+ "dependencies": {
5
+ "is-number": "^7.0.0"
6
+ }
7
+ }
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe Incr::Command::Mix do
4
+ let(:args) do
5
+ ['major']
6
+ end
7
+
8
+ describe '#execute' do
9
+ context 'with a normal mix file' do
10
+ before(:each) do
11
+ @tmpdir = Dir.mktmpdir('incr', '.')
12
+ end
13
+
14
+ let(:global_options) do
15
+ {
16
+ commit: false,
17
+ tag: false,
18
+ noop: true,
19
+ version_file_dir: @tmpdir,
20
+ tag_name_pattern: 'v%s'
21
+ }
22
+ end
23
+
24
+ let(:mix_filename) { "#{File.dirname(__FILE__)}/../../fixtures/mix/mix.exs" }
25
+ it 'should increase the version number' do
26
+ copy_files(@tmpdir, mix_filename)
27
+
28
+ expected = %+defmodule Foobar.MixProject do
29
+ use Mix.Project
30
+
31
+ @version "2.0.0"
32
+
33
+ def project do
34
+ [
35
+ app: :foobar,
36
+ version: @version,
37
+ elixir: "~> 1.13",
38
+ start_permanent: Mix.env() == :prod,
39
+ deps: deps()
40
+ ]
41
+ end
42
+
43
+ # Run "mix help compile.app" to learn about applications.
44
+ def application do
45
+ [
46
+ extra_applications: [:logger]
47
+ ]
48
+ end
49
+
50
+ # Run "mix help deps" to learn about dependencies.
51
+ defp deps do
52
+ [
53
+ # {:dep_from_hexpm, "~> 0.3.0"},
54
+ # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
55
+ ]
56
+ end
57
+ end
58
+ +
59
+ mix = Incr::Command::Mix.new(args, global_options)
60
+ expect{ mix.execute() }.to output("v2.0.0\n").to_stdout
61
+
62
+ result = read_file(File.join(@tmpdir, 'mix.exs'))
63
+ expect(result).to eql(expected)
64
+ end
65
+
66
+ after(:each) do
67
+ FileUtils.remove_entry_secure(@tmpdir)
68
+ end
69
+ end
70
+
71
+ context 'without expected files' do
72
+ before(:each) do
73
+ @tmpdir = Dir.mktmpdir('incr', '.')
74
+ end
75
+
76
+ let(:global_options) do
77
+ {
78
+ commit: false,
79
+ tag: false,
80
+ noop: true,
81
+ version_file_dir: @tmpdir,
82
+ tag_name_pattern: 'v%s'
83
+ }
84
+ end
85
+
86
+ it 'should return an error' do
87
+ mix = Incr::Command::Mix.new(args, global_options)
88
+ expected = "'#{File.join('.', @tmpdir, 'mix.exs')}': file not found.\n"
89
+ expect { mix.execute() }.to output(expected).to_stderr
90
+ end
91
+
92
+ after(:each) do
93
+ FileUtils.remove_entry_secure(@tmpdir)
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,197 @@
1
+ require 'spec_helper'
2
+
3
+ describe Incr::Command::Npm do
4
+ let(:args) do
5
+ ['major']
6
+ end
7
+
8
+ describe '#execute' do
9
+ context 'with NPM v6 files' do
10
+ before(:each) do
11
+ @tmpdir = Dir.mktmpdir('incr', '.')
12
+ end
13
+
14
+ let(:global_options) do
15
+ {
16
+ commit: false,
17
+ tag: false,
18
+ noop: true,
19
+ version_file_dir: @tmpdir,
20
+ tag_name_pattern: 'v%s'
21
+ }
22
+ end
23
+
24
+ let(:npmv6_package_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv6/package.json" }
25
+ let(:npmv6_package_lock_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv6/package-lock.json" }
26
+
27
+ it 'should increase the version number' do
28
+ copy_files(@tmpdir, npmv6_package_filename, npmv6_package_lock_filename)
29
+
30
+ expected = %({
31
+ "name": "foobar",
32
+ "version": "8.0.0",
33
+ "dependencies": {
34
+ "is-number": "^7.0.0"
35
+ }
36
+ }
37
+ )
38
+ lockfile_expected = %({
39
+ "name": "foobar",
40
+ "version": "8.0.0",
41
+ "lockfileVersion": 1,
42
+ "requires": true,
43
+ "dependencies": {
44
+ "is-number": {
45
+ "version": "7.0.0",
46
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
47
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
48
+ }
49
+ }
50
+ }
51
+ )
52
+ npm = Incr::Command::Npm.new(args, global_options)
53
+ expect{ npm.execute() }.to output("v8.0.0\n").to_stdout
54
+
55
+ result = read_file(File.join(@tmpdir, 'package.json'))
56
+ expect(result).to eql(expected)
57
+
58
+ lockfile_result = read_file(File.join(@tmpdir, 'package-lock.json'))
59
+ expect(lockfile_expected).to eql(lockfile_result)
60
+ end
61
+
62
+ after(:each) do
63
+ FileUtils.remove_entry_secure(@tmpdir)
64
+ end
65
+ end
66
+
67
+ context 'with NPM v7 files' do
68
+ before(:each) do
69
+ @tmpdir = Dir.mktmpdir('incr', '.')
70
+ end
71
+
72
+ let(:global_options) do
73
+ {
74
+ commit: false,
75
+ tag: false,
76
+ noop: true,
77
+ version_file_dir: @tmpdir,
78
+ tag_name_pattern: 'v%s'
79
+ }
80
+ end
81
+
82
+ let(:npmv7_package_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv7/package.json" }
83
+ let(:npmv7_package_lock_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv7/package-lock.json" }
84
+
85
+ it 'should increase the version number' do
86
+ copy_files(@tmpdir, npmv7_package_filename, npmv7_package_lock_filename)
87
+
88
+ expected = %({
89
+ "name": "foobar",
90
+ "version": "8.0.0",
91
+ "dependencies": {
92
+ "is-number": "^7.0.0"
93
+ }
94
+ }
95
+ )
96
+ lockfile_expected = %({
97
+ "name": "foobar",
98
+ "version": "8.0.0",
99
+ "lockfileVersion": 2,
100
+ "requires": true,
101
+ "packages": {
102
+ "": {
103
+ "name": "foobar",
104
+ "version": "8.0.0",
105
+ "dependencies": {
106
+ "is-number": "^7.0.0"
107
+ }
108
+ },
109
+ "node_modules/is-number": {
110
+ "version": "7.0.0",
111
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
112
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==",
113
+ "engines": {
114
+ "node": ">=0.12.0"
115
+ }
116
+ }
117
+ },
118
+ "dependencies": {
119
+ "is-number": {
120
+ "version": "7.0.0",
121
+ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz",
122
+ "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng=="
123
+ }
124
+ }
125
+ }
126
+ )
127
+ npm = Incr::Command::Npm.new(args, global_options)
128
+ expect{ npm.execute() }.to output("v8.0.0\n").to_stdout
129
+
130
+ result = read_file(File.join(@tmpdir, 'package.json'))
131
+ expect(result).to eql(expected)
132
+
133
+ lockfile_result = read_file(File.join(@tmpdir, 'package-lock.json'))
134
+ expect(lockfile_expected).to eql(lockfile_result)
135
+ end
136
+
137
+ after(:each) do
138
+ FileUtils.remove_entry_secure(@tmpdir)
139
+ end
140
+ end
141
+
142
+ context 'without expected files' do
143
+ before(:each) do
144
+ @tmpdir = Dir.mktmpdir('incr', '.')
145
+ end
146
+
147
+ let(:global_options) do
148
+ {
149
+ commit: false,
150
+ tag: false,
151
+ noop: true,
152
+ version_file_dir: @tmpdir,
153
+ tag_name_pattern: 'v%s'
154
+ }
155
+ end
156
+
157
+ it 'should return an error' do
158
+ npm = Incr::Command::Npm.new(args, global_options)
159
+ expected = "'#{File.join('.', @tmpdir, 'package.json')}': file not found.\n"
160
+ expect { npm.execute() }.to output(expected).to_stderr
161
+ end
162
+
163
+ after(:each) do
164
+ FileUtils.remove_entry_secure(@tmpdir)
165
+ end
166
+ end
167
+
168
+ context 'without expected lock file' do
169
+ before(:each) do
170
+ @tmpdir = Dir.mktmpdir('incr', '.')
171
+ end
172
+
173
+ let(:global_options) do
174
+ {
175
+ commit: false,
176
+ tag: false,
177
+ noop: true,
178
+ version_file_dir: @tmpdir,
179
+ tag_name_pattern: 'v%s'
180
+ }
181
+ end
182
+
183
+ let(:npmv6_package_filename) { "#{File.dirname(__FILE__)}/../../fixtures/npmv6/package.json" }
184
+
185
+ it 'should return an error ' do
186
+ copy_files(@tmpdir, npmv6_package_filename)
187
+ npm = Incr::Command::Npm.new(args, global_options)
188
+ expected = "'#{File.join('.', @tmpdir, 'package-lock.json')}': file not found.\n"
189
+ expect { npm.execute() }.to output(expected).to_stderr
190
+ end
191
+
192
+ after(:each) do
193
+ FileUtils.remove_entry_secure(@tmpdir)
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ SIMPLE_FILE_CONTENT = %(Hello, World!)
4
+
5
+ JSON_FILE_CONTENT = %({
6
+ "name": "incr",
7
+ "version": "7.0.0",
8
+ "dependencies": {
9
+ "is-number": "7.0.0"
10
+ }
11
+ })
12
+
13
+ describe Incr::Service::FileHelper do
14
+ describe '.replace' do
15
+ context 'with a simple text file' do
16
+ let(:filename) do
17
+ create_tempfile(SIMPLE_FILE_CONTENT)
18
+ end
19
+
20
+ it 'should replace specified regular expression' do
21
+ expected = "Buongiorno, World!"
22
+
23
+ Incr::Service::FileHelper.replace(filename, /^Hel{2}o/, 'Buongiorno')
24
+ result = read_file(filename)
25
+
26
+ expect(result).to eql(expected)
27
+ end
28
+ end
29
+
30
+ context 'with a JSON text file' do
31
+ let(:filename) do
32
+ create_tempfile(JSON_FILE_CONTENT)
33
+ end
34
+ end
35
+
36
+ context 'with a JSON file' do
37
+ let(:filename) do
38
+ create_tempfile(JSON_FILE_CONTENT)
39
+ end
40
+
41
+ it 'should replace specified regular expression, once' do
42
+ expected = %({
43
+ "name": "incr",
44
+ "version": "7.0.1",
45
+ "dependencies": {
46
+ "is-number": "7.0.0"
47
+ }
48
+ })
49
+
50
+ Incr::Service::FileHelper.replace(filename, /7.0.0/, '7.0.1')
51
+ result = read_file(filename)
52
+
53
+ expect(result).to eql(expected)
54
+ end
55
+ end
56
+
57
+ context 'with a non-existent text' do
58
+ let(:filename) do
59
+ create_tempfile(SIMPLE_FILE_CONTENT)
60
+ end
61
+
62
+ it 'should not do anything' do
63
+ expected = "Hello, World!"
64
+
65
+ Incr::Service::FileHelper.replace(filename, /7.0.0/, '7.0.1')
66
+ result = read_file(filename)
67
+
68
+ expect(result).to eql(expected)
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+
3
+ require 'sem_version'
4
+
5
+ describe Incr::Service::Version do
6
+ describe '.increment_segment' do
7
+ context 'with a SemVersion object' do
8
+ let(:version) { SemVersion.new('1.2.4') }
9
+
10
+ it 'should increment the major segment and reset the minor and patch segments' do
11
+ expected = '2.0.0'
12
+ result = Incr::Service::Version.increment_segment(version, 'major')
13
+
14
+ expect(result.to_s).to eql(expected)
15
+ end
16
+
17
+ it 'should increment the minor segment and reset the patch segment' do
18
+ expected = '1.3.0'
19
+ result = Incr::Service::Version.increment_segment(version, 'minor')
20
+
21
+ expect(result.to_s).to eql(expected)
22
+ end
23
+
24
+ it 'should increment the patch segment' do
25
+ expected = '1.2.5'
26
+ result = Incr::Service::Version.increment_segment(version, 'patch')
27
+
28
+ expect(result.to_s).to eql(expected)
29
+ end
30
+ end
31
+
32
+ context 'with a version string' do
33
+ let(:version) { '1.0.0' }
34
+
35
+ it 'should throw an error' do
36
+ expect {
37
+ Incr::Service::Version.increment_segment(version, 'patch')
38
+ }.to raise_error(NoMethodError)
39
+ end
40
+ end
41
+
42
+ context 'with an unknown segment' do
43
+ let(:version) { SemVersion.new('1.0.0') }
44
+
45
+ it 'should not do anything' do
46
+ expected = '1.0.0'
47
+ result = Incr::Service::Version.increment_segment(version, 'foobar')
48
+
49
+ expect(result.to_s).to eql(expected)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,122 @@
1
+ require 'incr'
2
+
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ def create_tempfile(content)
7
+ file = Tempfile.new('incr')
8
+ file << content
9
+ file.flush()
10
+ file.close()
11
+
12
+ file.path
13
+ end
14
+
15
+ def copy_files(dir, *filenames)
16
+ filenames.each do |filename|
17
+ FileUtils.cp(filename, dir)
18
+ end
19
+ end
20
+
21
+ def read_file(filename)
22
+ IO.read(filename)
23
+ end
24
+
25
+ # This file was generated by the `rspec --init` command. Conventionally, all
26
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
27
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
28
+ # this file to always be loaded, without a need to explicitly require it in any
29
+ # files.
30
+ #
31
+ # Given that it is always loaded, you are encouraged to keep this file as
32
+ # light-weight as possible. Requiring heavyweight dependencies from this file
33
+ # will add to the boot time of your test suite on EVERY test run, even for an
34
+ # individual file that may not need all of that loaded. Instead, consider making
35
+ # a separate helper file that requires the additional dependencies and performs
36
+ # the additional setup, and require it from the spec files that actually need
37
+ # it.
38
+ #
39
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
40
+ RSpec.configure do |config|
41
+ # rspec-expectations config goes here. You can use an alternate
42
+ # assertion/expectation library such as wrong or the stdlib/minitest
43
+ # assertions if you prefer.
44
+ config.expect_with :rspec do |expectations|
45
+ # This option will default to `true` in RSpec 4. It makes the `description`
46
+ # and `failure_message` of custom matchers include text for helper methods
47
+ # defined using `chain`, e.g.:
48
+ # be_bigger_than(2).and_smaller_than(4).description
49
+ # # => "be bigger than 2 and smaller than 4"
50
+ # ...rather than:
51
+ # # => "be bigger than 2"
52
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
53
+ end
54
+
55
+ # rspec-mocks config goes here. You can use an alternate test double
56
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
57
+ config.mock_with :rspec do |mocks|
58
+ # Prevents you from mocking or stubbing a method that does not exist on
59
+ # a real object. This is generally recommended, and will default to
60
+ # `true` in RSpec 4.
61
+ mocks.verify_partial_doubles = true
62
+ end
63
+
64
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
65
+ # have no way to turn it off -- the option exists only for backwards
66
+ # compatibility in RSpec 3). It causes shared context metadata to be
67
+ # inherited by the metadata hash of host groups and examples, rather than
68
+ # triggering implicit auto-inclusion in groups with matching metadata.
69
+ config.shared_context_metadata_behavior = :apply_to_host_groups
70
+
71
+ # The settings below are suggested to provide a good initial experience
72
+ # with RSpec, but feel free to customize to your heart's content.
73
+ =begin
74
+ # This allows you to limit a spec run to individual examples or groups
75
+ # you care about by tagging them with `:focus` metadata. When nothing
76
+ # is tagged with `:focus`, all examples get run. RSpec also provides
77
+ # aliases for `it`, `describe`, and `context` that include `:focus`
78
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
79
+ config.filter_run_when_matching :focus
80
+
81
+ # Allows RSpec to persist some state between runs in order to support
82
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
83
+ # you configure your source control system to ignore this file.
84
+ config.example_status_persistence_file_path = "spec/examples.txt"
85
+
86
+ # Limits the available syntax to the non-monkey patched syntax that is
87
+ # recommended. For more details, see:
88
+ # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
89
+ config.disable_monkey_patching!
90
+
91
+ # This setting enables warnings. It's recommended, but in some cases may
92
+ # be too noisy due to issues in dependencies.
93
+ config.warnings = true
94
+
95
+ # Many RSpec users commonly either run the entire suite or an individual
96
+ # file, and it's useful to allow more verbose output when running an
97
+ # individual spec file.
98
+ if config.files_to_run.one?
99
+ # Use the documentation formatter for detailed output,
100
+ # unless a formatter has already been configured
101
+ # (e.g. via a command-line flag).
102
+ config.default_formatter = "doc"
103
+ end
104
+
105
+ # Print the 10 slowest examples and example groups at the
106
+ # end of the spec run, to help surface which specs are running
107
+ # particularly slow.
108
+ config.profile_examples = 10
109
+
110
+ # Run specs in random order to surface order dependencies. If you find an
111
+ # order dependency and want to debug it, you can fix the order by providing
112
+ # the seed, which is printed after each run.
113
+ # --seed 1234
114
+ config.order = :random
115
+
116
+ # Seed global randomization in this process using the `--seed` CLI option.
117
+ # Setting this allows you to use `--seed` to deterministically reproduce
118
+ # test failures related to randomization by passing the same `--seed` value
119
+ # as the one that triggered the failure.
120
+ Kernel.srand config.seed
121
+ =end
122
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: incr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean-Philippe Couture
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-16 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.17.1
19
+ version: 2.21.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.17.1
26
+ version: 2.21.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sem_version
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,15 +44,71 @@ dependencies:
44
44
  requirements:
45
45
  - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.0
47
+ version: 1.12.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.0
55
- description:
54
+ version: 1.12.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 13.0.6
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 13.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.12.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.12.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.38.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 1.38.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: meowcop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 3.2.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 3.2.0
111
+ description:
56
112
  email:
57
113
  - jcouture@gmail.com
58
114
  executables:
@@ -60,12 +116,18 @@ executables:
60
116
  extensions: []
61
117
  extra_rdoc_files: []
62
118
  files:
119
+ - ".github/workflows/ci.yml"
120
+ - ".github/workflows/gem-push.yml"
63
121
  - ".gitignore"
122
+ - ".rspec"
123
+ - ".rubocop.yml"
124
+ - ".tool-versions"
64
125
  - CODE_OF_CONDUCT.md
65
126
  - Gemfile
66
127
  - Gemfile.lock
67
128
  - LICENSE.txt
68
129
  - README.md
130
+ - Rakefile
69
131
  - bin/incr
70
132
  - incr.gemspec
71
133
  - lib/incr.rb
@@ -75,11 +137,21 @@ files:
75
137
  - lib/incr/service/repository.rb
76
138
  - lib/incr/service/version.rb
77
139
  - lib/incr/version.rb
140
+ - spec/fixtures/mix/mix.exs
141
+ - spec/fixtures/npmv6/package-lock.json
142
+ - spec/fixtures/npmv6/package.json
143
+ - spec/fixtures/npmv7/package-lock.json
144
+ - spec/fixtures/npmv7/package.json
145
+ - spec/incr/command/mix_spec.rb
146
+ - spec/incr/command/npm_spec.rb
147
+ - spec/incr/service/file_helper_spec.rb
148
+ - spec/incr/service/version_spec.rb
149
+ - spec/spec_helper.rb
78
150
  homepage: https://github.com/jcouture/incr
79
151
  licenses:
80
152
  - MIT
81
153
  metadata: {}
82
- post_install_message:
154
+ post_install_message:
83
155
  rdoc_options: []
84
156
  require_paths:
85
157
  - lib
@@ -88,15 +160,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
88
160
  requirements:
89
161
  - - ">="
90
162
  - !ruby/object:Gem::Version
91
- version: '0'
163
+ version: '2.7'
92
164
  required_rubygems_version: !ruby/object:Gem::Requirement
93
165
  requirements:
94
166
  - - ">="
95
167
  - !ruby/object:Gem::Version
96
168
  version: '0'
97
169
  requirements: []
98
- rubygems_version: 3.3.3
99
- signing_key:
170
+ rubygems_version: 3.1.6
171
+ signing_key:
100
172
  specification_version: 4
101
173
  summary: Tasteful utility to increment the version number and create a corresponding
102
174
  git tag.