retag 0.1.5 → 0.1.9

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: c3eecc35217225b65ef71c75cc8cf5c5ee199291eadcc61b97a58b4899ab4ae3
4
- data.tar.gz: 372810234ee2c03c9829ff86e11ee2b8942831d1fbc18c0ab9e19e34bd5985c3
3
+ metadata.gz: f11b13578478be3507e9a47f1a011f12cd5ba25a751b3fc84304685c1203f8b0
4
+ data.tar.gz: f48c1d71d7376ce8aaee00c3f5f8191c0dcc040f660fce1edb73f3c1a3fe6495
5
5
  SHA512:
6
- metadata.gz: 3bd613b85fee317a71a86fa8fff244826e06ca3d02be87e5ac3297ad418c569e895a9ba6e09349e121b749ca7e4f44b00c245b684867f3f8a8925071f8f36a97
7
- data.tar.gz: c12042f6c60820062ab9761ab749ebe904ad843af76f1ef06a9666e9b0c851b436499ca8f3ad787a6961546a022a74c5cd06717eb0012296f9320b906cc42bb9
6
+ metadata.gz: 1e11360d25de512b9d78feb6fdb0ae3157a05cb75ab02abdb064b5d4616cef46714782b787134ea3a15d529094b22bd5f785b38a82f3af0245bb47438d13ac86
7
+ data.tar.gz: e505928a71af0331668c835e7c14d7d1b4c9b32a6b9f2072cb1b3e6b75550ac70af526c325027824741ff9e97024bf3555e3a0ad1af1a4e94037b954a84437d7
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- retag (0.1.4)
4
+ retag (0.1.9)
5
5
  activesupport (~> 6.0)
6
6
  colorize
7
7
  gitlab
data/bin/retag CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'yaml'
4
+ require 'erb'
4
5
  require 'thor'
5
6
  require 'colorize'
6
7
  require 'retag'
@@ -40,8 +41,31 @@ class RepoCommand < Thor
40
41
  # Success: there is no such tag
41
42
  end if opts['force']
42
43
 
44
+ $logger.info ">>> Repo #{project}"
45
+ $logger.info " From ".ljust(5) + "[#{options['ref'].colorize(:yellow)}]".ljust(35)
46
+ $logger.info " To ".ljust(5) + "[#{tag.colorize(:yellow)}]".ljust(35)
47
+
43
48
  puts Gitlab.client.create_tag(project, tag, options['ref'], options['message']).inspect
44
49
  end
50
+
51
+ desc "release <project> <tag>", "Create tag in Gitlab project"
52
+ long_desc <<-LONGDESC
53
+ LONGDESC
54
+
55
+ option :ref, default: ENV.fetch("#{ENV_PREFIX}_RELEASE_REF", 'master'),
56
+ required: true,
57
+ type: :string,
58
+ desc: "Gtilab refspec from which create tag"
59
+
60
+ option :description, default: nil,
61
+ type: :string,
62
+ desc: "description Markdown"
63
+ def release(project, tag)
64
+ $logger.info ">>> Repo #{project}"
65
+ $logger.info " From ".ljust(5) + "[#{options['ref'].colorize(:yellow)}]".ljust(35)
66
+ $logger.info " To ".ljust(5) + "[#{tag.colorize(:yellow)}]".ljust(35)
67
+ Gitlab.client.create_project_release(project, name: tag, tag_name: tag, description: options['description']&.strip, ref: options['ref'])
68
+ end
45
69
  end
46
70
 
47
71
  class DockerCommand < Thor
@@ -73,7 +97,11 @@ class DockerCommand < Thor
73
97
  tag = opts['suffix'].present? ? "#{tag}-#{opts['suffix']}" : tag
74
98
 
75
99
  image = ::Retag::Image.new(img, tag)
76
- image.retag!(opts['tag'])
100
+
101
+ $logger.info ">>> Image #{img.image}"
102
+ $logger.info " From ".ljust(5) + "[#{image.tag.colorize(:yellow)}]: ".ljust(35) + image.full
103
+ newimg = image.retag!(opts['tag'])
104
+ $logger.info " To ".ljust(5) + "[#{newimg.tag.colorize(:yellow)}]: ".ljust(35) + newimg.full
77
105
  end
78
106
 
79
107
  end
@@ -92,18 +120,23 @@ class ReleaseCommand < Thor
92
120
  required: false,
93
121
  desc: "Env: #{ENV_PREFIX}_RELEASE_NAME. Name of the current release"
94
122
 
123
+ option :manifest, default: './manifest.md',
124
+ required: false,
125
+ type: :string,
126
+ desc: "Output file for Markdown manifest of the release"
127
+
95
128
  def release(*_args)
96
129
  opts = options.to_h.dup
97
130
  $logger.level = :debug if opts['verbose']
98
131
 
99
- config = YAML.load_file(File.expand_path(opts['config']))
132
+ config = YAML.load(ERB.new(File.read(File.expand_path(opts['config']))).result)
100
133
  config['release'] = opts['name'] || config['release']
101
134
 
102
135
  release = config['release'].to_s
103
- suffix = config['suffix']
104
- branch = config['branch']
136
+ suffix = config['default-suffix']
137
+ branch = config['default-branch']
105
138
 
106
- services = config['services'].map do|(name, cfg)|
139
+ services = config['services'].map do|(name, cfg)|
107
140
  Retag::Service.new(name, cfg, release, suffix: cfg.fetch('suffix', suffix), branch: cfg.fetch('branch', branch)) unless name.start_with?('.')
108
141
  end.compact
109
142
 
@@ -111,6 +144,8 @@ class ReleaseCommand < Thor
111
144
 
112
145
  $logger.info "*** Starting '#{tag_message.colorize(mode: :bold)}'...".colorize(:cyan)
113
146
 
147
+ markdown = "## Services\n\n"
148
+
114
149
  services.each do |srv|
115
150
  $logger.tagged(srv.name.colorize(:yellow), "#{srv.revision.colorize(mode: :bold)}@#{srv.branch}") do
116
151
  $logger.info "#{'==>'.colorize(mode: :bold, color: :white)} Releasing service #{srv.name.colorize(mode: :bold)} from #{srv.repo.repo} at #{srv.branch.colorize(mode: :bold)}:".colorize(:green)
@@ -122,22 +157,28 @@ class ReleaseCommand < Thor
122
157
  $logger.info "From ".ljust(5) + "[#{img.tag.colorize(:yellow)}]: ".ljust(35) + img.full
123
158
  newimg = img.retag!(release)
124
159
  $logger.info "To ".ljust(5) + "[#{newimg.tag.colorize(:yellow)}]: ".ljust(35) + newimg.full
160
+
161
+ markdown += "* **Name**: `#{srv.name}`<br>**Version**: #{img.tag}<br>**Image**: #{newimg.full}\n"
125
162
  end
126
163
 
127
164
  $logger.info ">>> Repo #{srv.repo.repo}"
128
165
 
129
166
  $logger.shift do
130
167
  $logger.info "From ".ljust(5) + "[#{srv.revision.colorize(:yellow)}]: ".ljust(35) + "#{srv.repo.repo}~#{srv.revision}@#{srv.branch}"
131
- newimg = img.retag!(release)
168
+ srv.repo.tag!(release, message: tag_message)
132
169
  $logger.info "To ".ljust(5) + "[#{release.colorize(:yellow)}]: ".ljust(35) + "#{srv.repo.repo}~#{srv.revision}@#{release}"
133
170
  end
134
-
135
- srv.repo.tag!(release, message: tag_message)
171
+
136
172
  end
137
173
  end
138
174
  end
139
175
  end
140
176
 
177
+ File.write(opts['manifest'], markdown.strip)
178
+
179
+
180
+
181
+
141
182
  $logger.info "*** Completed '#{tag_message.colorize(mode: :bold)}'".colorize(:cyan)
142
183
 
143
184
  end
data/lib/retag/repo.rb CHANGED
@@ -31,13 +31,27 @@ module Retag
31
31
 
32
32
  def revision
33
33
  @revision ||= begin
34
- rev_name_pair = cmd!("git ls-remote #{repo} #{branch}", capture: true).split("\n").select{|line| line[/\/#{branch}$/] }.first
35
- raise "There is no #{branch} revision at #{repo}" if rev_name_pair.nil?
34
+ # "^{}" means the object could be a tag. https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitrevisions.html#_specifying_revisions
35
+ # Example:
36
+ # git ls-remote git@gir.example.com:repo.git | grep release-latest
37
+ # 174cf2b6685df563e59c5cd0d367996fcf24f0ae refs/tags/release-latest <-- annotated tag itself
38
+ # 47208e276cd277896887417a383e05973278438c refs/tags/release-latest^{} <-- WE NEED: original commit tag is references to
39
+ rev_name_pair = remote_refs(repo, branch+"^{}") # try to find commit tag is references to
40
+ rev_name_pair ||= remote_refs(repo, branch) # try to find simple branch or commit
41
+
42
+ raise "There is no '#{branch}' revision at #{repo}" if rev_name_pair.nil?
43
+
36
44
  rev, _name = rev_name_pair.split
37
45
  rev[0..7]
38
46
  end
39
47
  end
40
48
 
49
+ private
50
+
51
+ def remote_refs repo, branch
52
+ cmd!("git ls-remote #{repo} #{branch}", capture: true).split("\n").select{|line| line.strip.end_with?("/#{branch}") }.first
53
+ end
54
+
41
55
  end
42
56
  end
43
57
 
data/lib/retag/version.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Retag
4
4
 
5
- VERSION = '0.1.5'
5
+ VERSION = '0.1.9'
6
6
 
7
7
  end
8
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retag
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-21 00:00:00.000000000 Z
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler