actions-updater 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/VERSION +1 -0
- data/bin/actions-updater +35 -0
- data/lib/action.rb +57 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 821d7ec0b1fbeec3f09f50c033b24ac1f3b252ddda31324e14556063c388a6c7
|
4
|
+
data.tar.gz: 63bda3da8ae237bb029caa895d864eaad3c1fe5be5b478bb7e97448aebe5773f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a54de5dcee46094b81b77619b86c304ea07a11dabe60b26072e4dc298b9c2e35148d5c316e7f64af5f37af57cb5d1fa9ed36f09bd2516b9e0217991d99ac0e71
|
7
|
+
data.tar.gz: 1896f326dc1f8142aad9c1ab9a0610cae407384aaec7a324cb85490a20ad748e8e86c320bf32ddeb728760ad7506c75d940bd4824542621e94d1ea77d3ee8dd5
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.4
|
data/bin/actions-updater
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'optparse'
|
5
|
+
require 'action'
|
6
|
+
|
7
|
+
OptionParser.new do |parser|
|
8
|
+
parser.version = File.read("#{__dir__}/../VERSION")
|
9
|
+
parser.banner += ' workflows ...'
|
10
|
+
parser.on('-n', '--newer', 'deal only with actions that have an update') do
|
11
|
+
@newer = true
|
12
|
+
end
|
13
|
+
parser.on('-w', '--write', 'write updates back to workflow files') do
|
14
|
+
@write = true
|
15
|
+
end
|
16
|
+
end.parse!
|
17
|
+
|
18
|
+
ARGV.each do |path|
|
19
|
+
puts "==> #{path}"
|
20
|
+
yaml = File.read(path)
|
21
|
+
actions = Action.array_from_yaml(yaml)
|
22
|
+
actions.each do |current_action|
|
23
|
+
new_action = current_action.clone
|
24
|
+
new_action.ref = current_action.latest_tag
|
25
|
+
|
26
|
+
next if current_action == new_action && @newer
|
27
|
+
|
28
|
+
puts "#{current_action} -> #{new_action}"
|
29
|
+
|
30
|
+
next unless @write
|
31
|
+
|
32
|
+
yaml.gsub!(/#{current_action}/, new_action.to_s)
|
33
|
+
File.open(path, 'w') { |f| f.puts yaml }
|
34
|
+
end
|
35
|
+
end
|
data/lib/action.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class Action
|
6
|
+
attr_accessor :user, :repo, :dir, :ref
|
7
|
+
attr_reader :url
|
8
|
+
|
9
|
+
USES_REGEX = %r{^(?<user>[^/]+)[/](?<repo>[^/]+)[/]?(?<dir>.+)?[@](?<ref>.+)$}.freeze
|
10
|
+
TAGS_REGEX = %r{refs/tags/(.*)$}.freeze
|
11
|
+
DOMAIN = 'https://github.com'
|
12
|
+
TAG_REJECT_REASONS = %w[
|
13
|
+
alpha
|
14
|
+
beta
|
15
|
+
rc
|
16
|
+
^{}
|
17
|
+
].freeze
|
18
|
+
|
19
|
+
def self.array_from_yaml(yaml)
|
20
|
+
hash = YAML.safe_load(yaml)
|
21
|
+
useses = hash['jobs'].values.map do |job|
|
22
|
+
job['steps'].map do |step|
|
23
|
+
step['uses']
|
24
|
+
end
|
25
|
+
end
|
26
|
+
useses.flatten.compact.uniq.map do |uses|
|
27
|
+
new(uses)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize(uses)
|
32
|
+
captures = uses.match(USES_REGEX).named_captures
|
33
|
+
@user = captures['user']
|
34
|
+
@repo = captures['repo']
|
35
|
+
@dir = captures['dir']
|
36
|
+
@ref = captures['ref']
|
37
|
+
@url = "#{DOMAIN}/#{@user}/#{@repo}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"#{@user}/#{@repo}#{@dir ? '/' : ''}#{@dir}#{@ref ? '@' : ''}#{@ref}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def ==(other)
|
45
|
+
to_s == other.to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def latest_tag
|
49
|
+
tags = `git ls-remote -t #{@url}`.scan(TAGS_REGEX).flatten
|
50
|
+
tags.reject! do |tag|
|
51
|
+
TAG_REJECT_REASONS.any? do |reason|
|
52
|
+
tag.include?(reason)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
tags.last
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: actions-updater
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dawid Dziurla
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables:
|
16
|
+
- actions-updater
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- VERSION
|
21
|
+
- bin/actions-updater
|
22
|
+
- lib/action.rb
|
23
|
+
homepage: https://github.com/dawidd6/actions-updater
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata: {}
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
requirements: []
|
42
|
+
rubygems_version: 3.0.6
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: Updater of used Github Actions in workflow files
|
46
|
+
test_files: []
|