licensed 3.2.2 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +52 -1
- data/Rakefile +5 -3
- data/docs/adding_a_new_source.md +32 -3
- data/docs/commands/README.md +1 -1
- data/docs/sources/cargo.md +19 -0
- data/docs/sources/yarn.md +5 -4
- data/lib/licensed/commands/cache.rb +4 -2
- data/lib/licensed/commands/command.rb +5 -2
- data/lib/licensed/reporters/status_reporter.rb +1 -1
- data/lib/licensed/sources/bundler/missing_specification.rb +10 -7
- data/lib/licensed/sources/cargo.rb +70 -0
- data/lib/licensed/sources/manifest.rb +17 -22
- data/lib/licensed/sources/npm.rb +17 -7
- data/lib/licensed/sources/nuget.rb +2 -2
- data/lib/licensed/sources/source.rb +22 -3
- data/lib/licensed/sources/yarn/berry.rb +79 -0
- data/lib/licensed/sources/yarn/v1.rb +146 -0
- data/lib/licensed/sources/yarn.rb +15 -130
- data/lib/licensed/sources.rb +1 -0
- data/lib/licensed/version.rb +1 -1
- data/licensed.gemspec +1 -1
- metadata +6 -32
- data/.github/dependabot.yml +0 -19
- data/.github/workflows/release.yml +0 -213
- data/.github/workflows/test.yml +0 -528
- data/.gitignore +0 -57
- data/.licensed.yml +0 -7
- data/.rubocop.yml +0 -8
- data/.ruby-version +0 -1
- data/docker/Dockerfile.build-linux +0 -15
- data/script/bootstrap +0 -6
- data/script/cibuild +0 -7
- data/script/console +0 -15
- data/script/package +0 -20
- data/script/packages/build +0 -95
- data/script/packages/linux +0 -57
- data/script/packages/mac +0 -41
- data/script/setup +0 -5
- data/script/source-setup/bower +0 -17
- data/script/source-setup/bundler +0 -20
- data/script/source-setup/cabal +0 -19
- data/script/source-setup/composer +0 -38
- data/script/source-setup/git_submodule +0 -39
- data/script/source-setup/go +0 -31
- data/script/source-setup/mix +0 -19
- data/script/source-setup/npm +0 -34
- data/script/source-setup/nuget +0 -17
- data/script/source-setup/pip +0 -29
- data/script/source-setup/pipenv +0 -21
- data/script/source-setup/swift +0 -22
- data/script/source-setup/yarn +0 -17
- data/script/test +0 -16
@@ -0,0 +1,146 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
module Licensed
|
5
|
+
module Sources
|
6
|
+
class Yarn::V1 < Source
|
7
|
+
include Licensed::Sources::Yarn
|
8
|
+
|
9
|
+
# `yarn licenses list --json` returns data in a table format with header
|
10
|
+
# ordering specified in the output. Look for these specific headers and use
|
11
|
+
# their indices to get data from the table body
|
12
|
+
YARN_NAME_HEAD = "Name".freeze
|
13
|
+
YARN_VERSION_HEAD = "Version".freeze
|
14
|
+
YARN_URL_HEAD = "URL".freeze
|
15
|
+
|
16
|
+
def self.version_requirement
|
17
|
+
Gem::Requirement.new("< 2.0")
|
18
|
+
end
|
19
|
+
|
20
|
+
def enumerate_dependencies
|
21
|
+
packages.map do |name, package|
|
22
|
+
Dependency.new(
|
23
|
+
name: name,
|
24
|
+
version: package["version"],
|
25
|
+
path: package["path"],
|
26
|
+
metadata: {
|
27
|
+
"type" => self.class.type,
|
28
|
+
"name" => package["name"],
|
29
|
+
"homepage" => dependency_urls[package["id"]]
|
30
|
+
}
|
31
|
+
)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Finds packages that the current project relies on
|
36
|
+
def packages
|
37
|
+
return [] if yarn_package_tree.nil?
|
38
|
+
all_dependencies = {}
|
39
|
+
recursive_dependencies(yarn_package_tree).each do |name, results|
|
40
|
+
results.uniq! { |package| package["version"] }
|
41
|
+
if results.size == 1
|
42
|
+
# if there is only one package for a name, reference it by name
|
43
|
+
all_dependencies[name] = results[0]
|
44
|
+
else
|
45
|
+
# if there is more than one package for a name, reference each by
|
46
|
+
# "<name>-<version>"
|
47
|
+
results.each do |package|
|
48
|
+
all_dependencies["#{name}-#{package["version"]}"] = package
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
all_dependencies
|
54
|
+
end
|
55
|
+
|
56
|
+
# Recursively parse dependency JSON data. Returns a hash mapping the
|
57
|
+
# package name to it's metadata
|
58
|
+
def recursive_dependencies(dependencies, result = {})
|
59
|
+
dependencies.each do |dependency|
|
60
|
+
# "shadow" indicate a dependency requirement only, not a
|
61
|
+
# resolved package identifier
|
62
|
+
next if dependency["shadow"]
|
63
|
+
name, _, version = dependency["name"].rpartition("@")
|
64
|
+
|
65
|
+
(result[name] ||= []) << {
|
66
|
+
"id" => dependency["name"],
|
67
|
+
"name" => name,
|
68
|
+
"version" => version,
|
69
|
+
"path" => dependency_paths[dependency["name"]]
|
70
|
+
}
|
71
|
+
recursive_dependencies(dependency["children"], result)
|
72
|
+
end
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
# Returns a hash that maps all dependency names to their location on disk
|
77
|
+
# by parsing every package.json file under node_modules.
|
78
|
+
def dependency_paths
|
79
|
+
@dependency_paths ||= Dir.glob(config.pwd.join("node_modules/**/package.json")).each_with_object({}) do |file, hsh|
|
80
|
+
dirname = File.dirname(file)
|
81
|
+
json = JSON.parse(File.read(file))
|
82
|
+
hsh["#{json["name"]}@#{json["version"]}"] = dirname
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Finds and returns the yarn package tree listing from `yarn list` output
|
87
|
+
def yarn_package_tree
|
88
|
+
return @yarn_package_tree if defined?(@yarn_package_tree)
|
89
|
+
@yarn_package_tree = begin
|
90
|
+
# parse all lines of output to json and find one that is "type": "tree"
|
91
|
+
tree = yarn_list_command.lines
|
92
|
+
.map(&:strip)
|
93
|
+
.map(&JSON.method(:parse))
|
94
|
+
.find { |json| json["type"] == "tree" }
|
95
|
+
tree&.dig("data", "trees")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Returns a mapping of unique dependency identifiers to urls
|
100
|
+
def dependency_urls
|
101
|
+
@dependency_urls ||= begin
|
102
|
+
table = yarn_licenses_command.lines
|
103
|
+
.map(&:strip)
|
104
|
+
.map(&JSON.method(:parse))
|
105
|
+
.find { |json| json["type"] == "table" }
|
106
|
+
return {} if table.nil?
|
107
|
+
|
108
|
+
head = table.dig("data", "head")
|
109
|
+
return {} if head.nil?
|
110
|
+
|
111
|
+
name_index = head.index YARN_NAME_HEAD
|
112
|
+
version_index = head.index YARN_VERSION_HEAD
|
113
|
+
url_index = head.index YARN_URL_HEAD
|
114
|
+
return {} if name_index.nil? || version_index.nil? || url_index.nil?
|
115
|
+
|
116
|
+
body = table.dig("data", "body")
|
117
|
+
return {} if body.nil?
|
118
|
+
|
119
|
+
body.each_with_object({}) do |row, hsh|
|
120
|
+
id = "#{row[name_index]}@#{row[version_index]}"
|
121
|
+
hsh[id] = row[url_index]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
# Returns the output from running `yarn list` to get project dependencies
|
127
|
+
def yarn_list_command
|
128
|
+
args = %w(--json -s --no-progress)
|
129
|
+
args << "--production" unless include_non_production?
|
130
|
+
Licensed::Shell.execute("yarn", "list", *args, allow_failure: true)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Returns the output from running `yarn licenses list` to get project urls
|
134
|
+
def yarn_licenses_command
|
135
|
+
args = %w(--json -s --no-progress)
|
136
|
+
args << "--production" unless include_non_production?
|
137
|
+
Licensed::Shell.execute("yarn", "licenses", "list", *args, allow_failure: true)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Returns whether to include non production dependencies based on the licensed configuration settings
|
141
|
+
def include_non_production?
|
142
|
+
config.dig("yarn", "production_only") == false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
@@ -1,146 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require "json"
|
3
2
|
|
4
3
|
module Licensed
|
5
4
|
module Sources
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
YARN_NAME_HEAD = "Name".freeze
|
11
|
-
YARN_VERSION_HEAD = "Version".freeze
|
12
|
-
YARN_URL_HEAD = "URL".freeze
|
13
|
-
|
14
|
-
def enabled?
|
15
|
-
return unless Licensed::Shell.tool_available?("yarn")
|
16
|
-
|
17
|
-
config.pwd.join("package.json").exist? && config.pwd.join("yarn.lock").exist?
|
18
|
-
end
|
19
|
-
|
20
|
-
def enumerate_dependencies
|
21
|
-
packages.map do |name, package|
|
22
|
-
Dependency.new(
|
23
|
-
name: name,
|
24
|
-
version: package["version"],
|
25
|
-
path: package["path"],
|
26
|
-
metadata: {
|
27
|
-
"type" => Yarn.type,
|
28
|
-
"name" => package["name"],
|
29
|
-
"homepage" => dependency_urls[package["id"]]
|
30
|
-
}
|
31
|
-
)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Finds packages that the current project relies on
|
36
|
-
def packages
|
37
|
-
return [] if yarn_package_tree.nil?
|
38
|
-
all_dependencies = {}
|
39
|
-
recursive_dependencies(yarn_package_tree).each do |name, results|
|
40
|
-
results.uniq! { |package| package["version"] }
|
41
|
-
if results.size == 1
|
42
|
-
# if there is only one package for a name, reference it by name
|
43
|
-
all_dependencies[name] = results[0]
|
44
|
-
else
|
45
|
-
# if there is more than one package for a name, reference each by
|
46
|
-
# "<name>-<version>"
|
47
|
-
results.each do |package|
|
48
|
-
all_dependencies["#{name}-#{package["version"]}"] = package
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
all_dependencies
|
54
|
-
end
|
55
|
-
|
56
|
-
# Recursively parse dependency JSON data. Returns a hash mapping the
|
57
|
-
# package name to it's metadata
|
58
|
-
def recursive_dependencies(dependencies, result = {})
|
59
|
-
dependencies.each do |dependency|
|
60
|
-
# "shadow" indicate a dependency requirement only, not a
|
61
|
-
# resolved package identifier
|
62
|
-
next if dependency["shadow"]
|
63
|
-
name, _, version = dependency["name"].rpartition("@")
|
64
|
-
|
65
|
-
(result[name] ||= []) << {
|
66
|
-
"id" => dependency["name"],
|
67
|
-
"name" => name,
|
68
|
-
"version" => version,
|
69
|
-
"path" => dependency_paths[dependency["name"]]
|
70
|
-
}
|
71
|
-
recursive_dependencies(dependency["children"], result)
|
5
|
+
module Yarn
|
6
|
+
module ClassMethods
|
7
|
+
def type
|
8
|
+
"yarn"
|
72
9
|
end
|
73
|
-
result
|
74
10
|
end
|
75
11
|
|
76
|
-
|
77
|
-
|
78
|
-
def dependency_paths
|
79
|
-
@dependency_paths ||= Dir.glob(config.pwd.join("node_modules/**/package.json")).each_with_object({}) do |file, hsh|
|
80
|
-
dirname = File.dirname(file)
|
81
|
-
json = JSON.parse(File.read(file))
|
82
|
-
hsh["#{json["name"]}@#{json["version"]}"] = dirname
|
83
|
-
end
|
12
|
+
def self.included(klass)
|
13
|
+
klass.extend ClassMethods
|
84
14
|
end
|
85
15
|
|
86
|
-
|
87
|
-
|
88
|
-
return
|
89
|
-
@yarn_package_tree = begin
|
90
|
-
# parse all lines of output to json and find one that is "type": "tree"
|
91
|
-
tree = yarn_list_command.lines
|
92
|
-
.map(&:strip)
|
93
|
-
.map(&JSON.method(:parse))
|
94
|
-
.find { |json| json["type"] == "tree" }
|
95
|
-
tree&.dig("data", "trees")
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
# Returns a mapping of unique dependency identifiers to urls
|
100
|
-
def dependency_urls
|
101
|
-
@dependency_urls ||= begin
|
102
|
-
table = yarn_licenses_command.lines
|
103
|
-
.map(&:strip)
|
104
|
-
.map(&JSON.method(:parse))
|
105
|
-
.find { |json| json["type"] == "table" }
|
106
|
-
return [] if table.nil?
|
107
|
-
|
108
|
-
head = table.dig("data", "head")
|
109
|
-
return [] if head.nil?
|
110
|
-
|
111
|
-
name_index = head.index YARN_NAME_HEAD
|
112
|
-
version_index = head.index YARN_VERSION_HEAD
|
113
|
-
url_index = head.index YARN_URL_HEAD
|
114
|
-
return [] if name_index.nil? || version_index.nil? || url_index.nil?
|
115
|
-
|
116
|
-
body = table.dig("data", "body")
|
117
|
-
return [] if body.nil?
|
118
|
-
|
119
|
-
body.each_with_object({}) do |row, hsh|
|
120
|
-
id = "#{row[name_index]}@#{row[version_index]}"
|
121
|
-
hsh[id] = row[url_index]
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
# Returns the output from running `yarn list` to get project dependencies
|
127
|
-
def yarn_list_command
|
128
|
-
args = %w(--json -s --no-progress)
|
129
|
-
args << "--production" unless include_non_production?
|
130
|
-
Licensed::Shell.execute("yarn", "list", *args, allow_failure: true)
|
131
|
-
end
|
16
|
+
def enabled?
|
17
|
+
return unless Licensed::Shell.tool_available?("yarn")
|
18
|
+
return unless self.class.version_requirement.satisfied_by?(yarn_version)
|
132
19
|
|
133
|
-
|
134
|
-
def yarn_licenses_command
|
135
|
-
args = %w(--json -s --no-progress)
|
136
|
-
args << "--production" unless include_non_production?
|
137
|
-
Licensed::Shell.execute("yarn", "licenses", "list", *args, allow_failure: true)
|
20
|
+
config.pwd.join("package.json").exist? && config.pwd.join("yarn.lock").exist?
|
138
21
|
end
|
139
22
|
|
140
|
-
|
141
|
-
|
142
|
-
config.dig("yarn", "production_only") == false
|
23
|
+
def yarn_version
|
24
|
+
Gem::Version.new(Licensed::Shell.execute("yarn", "-v"))
|
143
25
|
end
|
144
26
|
end
|
145
27
|
end
|
146
28
|
end
|
29
|
+
|
30
|
+
require "licensed/sources/yarn/v1"
|
31
|
+
require "licensed/sources/yarn/berry"
|
data/lib/licensed/sources.rb
CHANGED
@@ -5,6 +5,7 @@ module Licensed
|
|
5
5
|
require "licensed/sources/bower"
|
6
6
|
require "licensed/sources/bundler"
|
7
7
|
require "licensed/sources/cabal"
|
8
|
+
require "licensed/sources/cargo"
|
8
9
|
require "licensed/sources/composer"
|
9
10
|
require "licensed/sources/dep"
|
10
11
|
require "licensed/sources/git_submodule"
|
data/lib/licensed/version.rb
CHANGED
data/licensed.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.homepage = "https://github.com/github/licensed"
|
17
17
|
spec.license = "MIT"
|
18
18
|
|
19
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test/|script/|docker/|\..+)}) }
|
20
20
|
spec.bindir = "exe"
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: licensed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GitHub
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: licensee
|
@@ -238,13 +238,6 @@ executables:
|
|
238
238
|
extensions: []
|
239
239
|
extra_rdoc_files: []
|
240
240
|
files:
|
241
|
-
- ".github/dependabot.yml"
|
242
|
-
- ".github/workflows/release.yml"
|
243
|
-
- ".github/workflows/test.yml"
|
244
|
-
- ".gitignore"
|
245
|
-
- ".licensed.yml"
|
246
|
-
- ".rubocop.yml"
|
247
|
-
- ".ruby-version"
|
248
241
|
- CHANGELOG.md
|
249
242
|
- CODE_OF_CONDUCT.md
|
250
243
|
- CONTRIBUTING.md
|
@@ -252,7 +245,6 @@ files:
|
|
252
245
|
- LICENSE
|
253
246
|
- README.md
|
254
247
|
- Rakefile
|
255
|
-
- docker/Dockerfile.build-linux
|
256
248
|
- docs/adding_a_new_source.md
|
257
249
|
- docs/commands/README.md
|
258
250
|
- docs/commands/cache.md
|
@@ -280,6 +272,7 @@ files:
|
|
280
272
|
- docs/sources/bower.md
|
281
273
|
- docs/sources/bundler.md
|
282
274
|
- docs/sources/cabal.md
|
275
|
+
- docs/sources/cargo.md
|
283
276
|
- docs/sources/composer.md
|
284
277
|
- docs/sources/dep.md
|
285
278
|
- docs/sources/git_submodule.md
|
@@ -326,6 +319,7 @@ files:
|
|
326
319
|
- lib/licensed/sources/bundler/definition.rb
|
327
320
|
- lib/licensed/sources/bundler/missing_specification.rb
|
328
321
|
- lib/licensed/sources/cabal.rb
|
322
|
+
- lib/licensed/sources/cargo.rb
|
329
323
|
- lib/licensed/sources/composer.rb
|
330
324
|
- lib/licensed/sources/dep.rb
|
331
325
|
- lib/licensed/sources/git_submodule.rb
|
@@ -341,31 +335,11 @@ files:
|
|
341
335
|
- lib/licensed/sources/source.rb
|
342
336
|
- lib/licensed/sources/swift.rb
|
343
337
|
- lib/licensed/sources/yarn.rb
|
338
|
+
- lib/licensed/sources/yarn/berry.rb
|
339
|
+
- lib/licensed/sources/yarn/v1.rb
|
344
340
|
- lib/licensed/ui/shell.rb
|
345
341
|
- lib/licensed/version.rb
|
346
342
|
- licensed.gemspec
|
347
|
-
- script/bootstrap
|
348
|
-
- script/cibuild
|
349
|
-
- script/console
|
350
|
-
- script/package
|
351
|
-
- script/packages/build
|
352
|
-
- script/packages/linux
|
353
|
-
- script/packages/mac
|
354
|
-
- script/setup
|
355
|
-
- script/source-setup/bower
|
356
|
-
- script/source-setup/bundler
|
357
|
-
- script/source-setup/cabal
|
358
|
-
- script/source-setup/composer
|
359
|
-
- script/source-setup/git_submodule
|
360
|
-
- script/source-setup/go
|
361
|
-
- script/source-setup/mix
|
362
|
-
- script/source-setup/npm
|
363
|
-
- script/source-setup/nuget
|
364
|
-
- script/source-setup/pip
|
365
|
-
- script/source-setup/pipenv
|
366
|
-
- script/source-setup/swift
|
367
|
-
- script/source-setup/yarn
|
368
|
-
- script/test
|
369
343
|
homepage: https://github.com/github/licensed
|
370
344
|
licenses:
|
371
345
|
- MIT
|
data/.github/dependabot.yml
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# To get started with Dependabot version updates, you'll need to specify which
|
2
|
-
# package ecosystems to update and where the package manifests are located.
|
3
|
-
# Please see the documentation for all configuration options:
|
4
|
-
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
5
|
-
|
6
|
-
version: 2
|
7
|
-
updates:
|
8
|
-
- package-ecosystem: github-actions
|
9
|
-
directory: /
|
10
|
-
schedule:
|
11
|
-
interval: daily
|
12
|
-
- package-ecosystem: bundler
|
13
|
-
directory: /
|
14
|
-
schedule:
|
15
|
-
interval: weekly
|
16
|
-
- package-ecosystem: docker
|
17
|
-
directory: docker
|
18
|
-
schedule:
|
19
|
-
interval: weekly
|
@@ -1,213 +0,0 @@
|
|
1
|
-
name: Build and publish release assets
|
2
|
-
|
3
|
-
on:
|
4
|
-
release:
|
5
|
-
types: [created]
|
6
|
-
workflow_dispatch:
|
7
|
-
inputs:
|
8
|
-
version:
|
9
|
-
description: 'Commit-like version of github/licensed to build package at'
|
10
|
-
required: true
|
11
|
-
release_tag:
|
12
|
-
description: 'Release tag to upload built packages to'
|
13
|
-
required: false
|
14
|
-
|
15
|
-
jobs:
|
16
|
-
vars:
|
17
|
-
name: "Gather values for remainder of steps"
|
18
|
-
runs-on: ubuntu-latest
|
19
|
-
outputs:
|
20
|
-
version: ${{ steps.get_version.outputs.result }}
|
21
|
-
upload_url: ${{ steps.get_url.outputs.result }}
|
22
|
-
ref: ${{ steps.get_ref.outputs.result }}
|
23
|
-
steps:
|
24
|
-
- id: get_version
|
25
|
-
name: Get package version
|
26
|
-
uses: actions/github-script@v4.1
|
27
|
-
with:
|
28
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
29
|
-
result-encoding: string
|
30
|
-
script: |
|
31
|
-
let version = "${{ github.event.release.tag_name }}"
|
32
|
-
if (!version) {
|
33
|
-
version = "${{ github.event.inputs.version }}"
|
34
|
-
}
|
35
|
-
|
36
|
-
if (!version) {
|
37
|
-
throw new Error("unable to find package build version")
|
38
|
-
}
|
39
|
-
|
40
|
-
return version
|
41
|
-
|
42
|
-
- id: get_url
|
43
|
-
name: Get release upload url
|
44
|
-
uses: actions/github-script@v4.1
|
45
|
-
with:
|
46
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
47
|
-
result-encoding: string
|
48
|
-
script: |
|
49
|
-
let uploadUrl = "${{ github.event.release.upload_url}}"
|
50
|
-
const tag = "${{ github.event.inputs.release_tag }}"
|
51
|
-
if (!uploadUrl && tag) {
|
52
|
-
const { data: release } = await github.repos.getReleaseByTag({
|
53
|
-
...context.repo,
|
54
|
-
tag
|
55
|
-
})
|
56
|
-
|
57
|
-
if (!release.upload_url) {
|
58
|
-
throw new Error("unable to find a release upload url")
|
59
|
-
}
|
60
|
-
|
61
|
-
uploadUrl = release.upload_url
|
62
|
-
}
|
63
|
-
|
64
|
-
return uploadUrl
|
65
|
-
|
66
|
-
- id: get_ref
|
67
|
-
name: Get checkout ref for custom build scripts
|
68
|
-
uses: actions/github-script@v4.1
|
69
|
-
with:
|
70
|
-
github-token: ${{ secrets.GITHUB_TOKEN }}
|
71
|
-
result-encoding: string
|
72
|
-
script: |
|
73
|
-
let ref = "${{ github.event.release.tag_name }}"
|
74
|
-
if (!ref) {
|
75
|
-
ref = "${{ github.event.ref }}".replace(/refs\/[^\/]+\//, '')
|
76
|
-
}
|
77
|
-
|
78
|
-
if (!ref) {
|
79
|
-
throw new Error("unable to find a ref for action")
|
80
|
-
}
|
81
|
-
|
82
|
-
return ref
|
83
|
-
|
84
|
-
package_linux:
|
85
|
-
needs: vars
|
86
|
-
runs-on: ubuntu-18.04
|
87
|
-
steps:
|
88
|
-
- uses: actions/checkout@v2
|
89
|
-
with:
|
90
|
-
# checkout at the ref for the action, separate from the target build version
|
91
|
-
# this allows running build scripts independent of the target version
|
92
|
-
ref: ${{needs.vars.outputs.ref}}
|
93
|
-
fetch-depth: 0
|
94
|
-
|
95
|
-
- name: Set up Ruby 2.6
|
96
|
-
uses: ruby/setup-ruby@v1
|
97
|
-
with:
|
98
|
-
ruby-version: 2.6
|
99
|
-
|
100
|
-
- name: Build package
|
101
|
-
run: script/packages/linux
|
102
|
-
env:
|
103
|
-
VERSION: ${{needs.vars.outputs.version}}
|
104
|
-
|
105
|
-
- uses: actions/upload-artifact@v2
|
106
|
-
with:
|
107
|
-
name: ${{needs.vars.outputs.version}}-linux
|
108
|
-
path: pkg/${{needs.vars.outputs.version}}/licensed-${{needs.vars.outputs.version}}-linux-x64.tar.gz
|
109
|
-
|
110
|
-
package_mac:
|
111
|
-
needs: vars
|
112
|
-
runs-on: macOS-latest
|
113
|
-
steps:
|
114
|
-
- uses: actions/checkout@v2
|
115
|
-
with:
|
116
|
-
# checkout at the ref for the action, separate from the target build version
|
117
|
-
# this allows running build scripts independent of the target version
|
118
|
-
ref: ${{needs.vars.outputs.ref}}
|
119
|
-
fetch-depth: 0
|
120
|
-
|
121
|
-
- name: Set up Ruby 2.6
|
122
|
-
uses: ruby/setup-ruby@v1
|
123
|
-
with:
|
124
|
-
ruby-version: 2.6
|
125
|
-
|
126
|
-
- name: Build package
|
127
|
-
run: script/packages/mac
|
128
|
-
env:
|
129
|
-
VERSION: ${{needs.vars.outputs.version}}
|
130
|
-
|
131
|
-
- uses: actions/upload-artifact@v2
|
132
|
-
with:
|
133
|
-
name: ${{needs.vars.outputs.version}}-darwin
|
134
|
-
path: pkg/${{needs.vars.outputs.version}}/licensed-${{needs.vars.outputs.version}}-darwin-x64.tar.gz
|
135
|
-
|
136
|
-
build_gem:
|
137
|
-
needs: vars
|
138
|
-
runs-on: ubuntu-latest
|
139
|
-
steps:
|
140
|
-
- uses: actions/checkout@v2
|
141
|
-
with:
|
142
|
-
# building a gem doesn't use a different ref from the version input
|
143
|
-
ref: ${{needs.vars.outputs.version}}
|
144
|
-
|
145
|
-
- name: Set up Ruby 2.6
|
146
|
-
uses: ruby/setup-ruby@v1
|
147
|
-
with:
|
148
|
-
ruby-version: 2.6
|
149
|
-
|
150
|
-
- name: Build gem
|
151
|
-
run: gem build licensed.gemspec -o licensed-${{needs.vars.outputs.version}}.gem
|
152
|
-
|
153
|
-
- uses: actions/upload-artifact@v2
|
154
|
-
with:
|
155
|
-
name: ${{needs.vars.outputs.version}}-gem
|
156
|
-
path: licensed-${{needs.vars.outputs.version}}.gem
|
157
|
-
|
158
|
-
upload_packages:
|
159
|
-
if: ${{ needs.vars.outputs.upload_url != '' }}
|
160
|
-
runs-on: ubuntu-latest
|
161
|
-
needs: [vars, package_linux, package_mac, build_gem]
|
162
|
-
|
163
|
-
steps:
|
164
|
-
- name: Set up Ruby 2.6
|
165
|
-
uses: ruby/setup-ruby@v1
|
166
|
-
with:
|
167
|
-
ruby-version: 2.6
|
168
|
-
|
169
|
-
- name: Download linux package
|
170
|
-
uses: actions/download-artifact@v2
|
171
|
-
with:
|
172
|
-
name: ${{needs.vars.outputs.version}}-linux
|
173
|
-
|
174
|
-
- name: Download macOS package
|
175
|
-
uses: actions/download-artifact@v2
|
176
|
-
with:
|
177
|
-
name: ${{needs.vars.outputs.version}}-darwin
|
178
|
-
|
179
|
-
- name: Download gem
|
180
|
-
uses: actions/download-artifact@v2
|
181
|
-
with:
|
182
|
-
name: ${{needs.vars.outputs.version}}-gem
|
183
|
-
|
184
|
-
- name: Publish linux package
|
185
|
-
uses: actions/upload-release-asset@v1
|
186
|
-
env:
|
187
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
188
|
-
with:
|
189
|
-
upload_url: ${{ needs.vars.outputs.upload_url }}
|
190
|
-
asset_path: ./licensed-${{needs.vars.outputs.version}}-linux-x64.tar.gz
|
191
|
-
asset_name: licensed-${{needs.vars.outputs.version}}-linux-x64.tar.gz
|
192
|
-
asset_content_type: application/gzip
|
193
|
-
|
194
|
-
- name: Publish mac package
|
195
|
-
uses: actions/upload-release-asset@v1
|
196
|
-
env:
|
197
|
-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
198
|
-
with:
|
199
|
-
upload_url: ${{ needs.vars.outputs.upload_url }}
|
200
|
-
asset_path: ./licensed-${{needs.vars.outputs.version}}-darwin-x64.tar.gz
|
201
|
-
asset_name: licensed-${{needs.vars.outputs.version}}-darwin-x64.tar.gz
|
202
|
-
asset_content_type: application/gzip
|
203
|
-
|
204
|
-
- name: Publish gem to RubyGems
|
205
|
-
run: |
|
206
|
-
mkdir -p $HOME/.gem
|
207
|
-
touch $HOME/.gem/credentials
|
208
|
-
chmod 0600 $HOME/.gem/credentials
|
209
|
-
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
210
|
-
gem push $GEM
|
211
|
-
env:
|
212
|
-
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
213
|
-
GEM: licensed-${{needs.vars.outputs.version}}.gem
|