licensed 2.1.0 → 2.2.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
  SHA1:
3
- metadata.gz: c7f39c048283d853075674325f0d371edaf124a8
4
- data.tar.gz: 60530129f47ed34f51cac3152be83aab27e32a01
3
+ metadata.gz: ee8b9896bf3a7728b539c308822b7613b70ddc62
4
+ data.tar.gz: e3c4f581c2a1982b426a82dfd7c5217ca98d2838
5
5
  SHA512:
6
- metadata.gz: 2b2bc431aea2a64f3f12139d533914ad2de740cc5eb00310166dbfa6160fc5a6821d73faf214ceb49fcb6207d9c695561fc44a9ff21e146d88cc4f4eb7de0d38
7
- data.tar.gz: 53db8e3e0272e976428471bbe0f5a2c6e54cdb7743b2e309ac8b2d839a352073fb8a81026e8bc19838f155a09d0b2a74097736ee6e68bc4152eb2124177ceb7e
6
+ metadata.gz: 05bc23396c71a8d445412965cc9decf5abb6d5a6ebc450060e318266a3504368abb257649092ffe1eae615a93b6e69e24f9192a7ed475c39ff9e943332db2cb4
7
+ data.tar.gz: 2fa140721c4e3fbfe22fe91048c8cac718ae6e918efc675cb800ea606d260de6383d977fa13ce1cd309b81c36275245183bbbbeca0b1f2ccfb81c812fb0f06a8
data/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## 2.2.0 - 2019-05-11
10
+
11
+ ### Added
12
+ - Content hash versioning strategy for go and manifest sources (https://github.com/github/licensed/pull/164)
13
+
14
+ ### Fixed
15
+ - Python source handles urls and package names with "-" in requirements.txt (:tada: @krzysztof-pawlik-gat https://github.com/github/licensed/pull/165)
16
+
9
17
  ## 2.1.0 - 2019-04-16
10
18
 
11
19
  ### Added
@@ -154,4 +162,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
154
162
 
155
163
  Initial release :tada:
156
164
 
157
- [Unreleased]: https://github.com/github/licensed/compare/2.0.1...HEAD
165
+ [Unreleased]: https://github.com/github/licensed/compare/2.2.0...HEAD
data/docs/sources/go.md CHANGED
@@ -23,3 +23,20 @@ go:
23
23
  The setting supports absolute, relative and expandable (e.g. "~") paths. Relative paths are considered relative to the repository root.
24
24
 
25
25
  Non-empty `GOPATH` configuration settings will override the `GOPATH` environment variable while enumerating `go` dependencies. The `GOPATH` environment variable is restored once dependencies have been enumerated.
26
+
27
+ #### Versioning
28
+
29
+ The go source supports multiple versioning strategies to determine if cached dependency metadata is stale. A version strategy is chosen based on the availability of go module information along with the current app configuration.
30
+
31
+ 1. Go Module version - This strategy uses the version of the go module.
32
+ - :exclamation: This strategy will always be used if go module information is available because the version comes from an externally provided identifier. Locating the version of the source package used via this identifier will be easier than other strategies.
33
+ 2. Git commit SHA - This strategy uses the latest Git commit SHA available for the package's import path directory as the version. This is the default strategy used if a go module version isn't available and the setting is not configured.
34
+ - :warning: The latest Git commit won't capture any changes that are committed alongside a cached file update. Make sure to update cached files after all other changes are committed.
35
+
36
+ ```yaml
37
+ version_strategy: git # or leave this key unset
38
+ ```
39
+ 3. Contents hash - This strategy uses a hash of the files in the package's import path directory as the version.
40
+ ```yaml
41
+ version_strategy: contents
42
+ ```
@@ -145,3 +145,18 @@ manifest:
145
145
  licenses:
146
146
  package: path/to/LICENSE
147
147
  ```
148
+
149
+ ### License content versioning
150
+
151
+ The manifest source supports multiple versioning strategies to determine if cached dependency metadata is stale. A version strategy is chosen based on the current app configuration.
152
+
153
+ 1. Git commit SHA - This strategy uses the latest Git commit SHA available for the package's import path directory as the version. This is the default strategy used if not otherwise configured.
154
+ - :warning: The latest Git commit won't capture any changes that are committed alongside a cached file update. Make sure to update cached files after all other changes are committed.
155
+
156
+ ```yaml
157
+ version_strategy: git # or leave this key unset
158
+ ```
159
+ 2. Contents hash - This strategy uses a hash of the files in the package's import path directory as the version.
160
+ ```yaml
161
+ version_strategy: contents
162
+ ```
@@ -1,10 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
  require "json"
3
3
  require "pathname"
4
+ require "licensed/sources/helpers/content_versioning"
4
5
 
5
6
  module Licensed
6
7
  module Sources
7
8
  class Go < Source
9
+ include Licensed::Sources::ContentVersioning
10
+
8
11
  def enabled?
9
12
  Licensed::Shell.tool_available?("go") && go_source?
10
13
  end
@@ -102,7 +105,19 @@ module Licensed
102
105
  # find most recent git SHA for a package, or nil if SHA is
103
106
  # not available
104
107
  Dir.chdir package_directory do
105
- Licensed::Git.version(".")
108
+ contents_version *contents_version_arguments
109
+ end
110
+ end
111
+
112
+ # Determines the arguments to pass to contents_version based on which
113
+ # version strategy is selected
114
+ #
115
+ # Returns an array of arguments to pass to contents version
116
+ def contents_version_arguments
117
+ if version_strategy == Licensed::Sources::ContentVersioning::GIT
118
+ ["."]
119
+ else
120
+ Dir["*"]
106
121
  end
107
122
  end
108
123
 
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ruby-xxhash"
4
+
5
+ module Licensed
6
+ module Sources
7
+ module ContentVersioning
8
+ GIT = "git".freeze
9
+ CONTENTS = "contents".freeze
10
+
11
+ # Find the version for a list of paths using the version strategy
12
+ # specified for the source from the configuration
13
+ #
14
+ # paths - list of paths to find version
15
+ #
16
+ # Returns a version identifier for the given files
17
+ def contents_version(*paths)
18
+ case version_strategy
19
+ when CONTENTS
20
+ contents_hash(paths)
21
+ when GIT
22
+ git_version(paths)
23
+ end
24
+ end
25
+
26
+ # Returns the version strategy configured for the source
27
+ def version_strategy
28
+ # default to git for backwards compatible behavior
29
+ @version_strategy ||= begin
30
+ case config.fetch("version_strategy", nil)
31
+ when CONTENTS
32
+ CONTENTS
33
+ when GIT
34
+ GIT
35
+ else
36
+ Licensed::Git.available? ? GIT : CONTENTS
37
+ end
38
+ end
39
+ end
40
+
41
+ # Find the version for a list of paths using Git commit information
42
+ #
43
+ # paths - list of paths to find version
44
+ #
45
+ # Returns the most recent git SHA from the given paths
46
+ def git_version(paths)
47
+ return if paths.nil?
48
+
49
+ paths.map { |path| Licensed::Git.version(path) }
50
+ .reject { |sha| sha.to_s.empty? }
51
+ .max_by { |sha| Licensed::Git.commit_date(sha) }
52
+ end
53
+
54
+ # Find the version for a list of paths using their file contents
55
+ #
56
+ # paths - list of paths to find version
57
+ #
58
+ # Returns a hash of the path contents as an identifier for the group
59
+ def contents_hash(paths)
60
+ return if paths.nil?
61
+
62
+ paths = paths.compact.select { |path| File.file?(path) }
63
+ return if paths.empty?
64
+
65
+ paths.sort
66
+ .reduce(Digest::XXHash64.new, :file)
67
+ .digest
68
+ .to_s(16) # convert to hex
69
+ end
70
+ end
71
+ end
72
+ end
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
  require "pathname/common_prefix"
3
+ require "licensed/sources/helpers/content_versioning"
3
4
 
4
5
  module Licensed
5
6
  module Sources
6
7
  class Manifest < Source
8
+ include Licensed::Sources::ContentVersioning
9
+
7
10
  def enabled?
8
11
  File.exist?(manifest_path) || generate_manifest?
9
12
  end
@@ -12,7 +15,7 @@ module Licensed
12
15
  packages.map do |package_name, sources|
13
16
  Licensed::Sources::Manifest::Dependency.new(
14
17
  name: package_name,
15
- version: package_version(sources),
18
+ version: contents_version(*sources),
16
19
  path: configured_license_path(package_name) || sources_license_path(sources),
17
20
  sources: sources,
18
21
  metadata: {
@@ -23,15 +26,6 @@ module Licensed
23
26
  end
24
27
  end
25
28
 
26
- # Returns the latest git SHA available from `sources`
27
- def package_version(sources)
28
- return if sources.nil? || sources.empty?
29
-
30
- sources.map { |s| Licensed::Git.version(s) }
31
- .compact
32
- .max_by { |sha| Licensed::Git.commit_date(sha) }
33
- end
34
-
35
29
  # Returns the license path for a package specified in the configuration.
36
30
  def configured_license_path(package_name)
37
31
  license_path = @config.dig("manifest", "licenses", package_name)
@@ -6,7 +6,7 @@ module Licensed
6
6
  module Sources
7
7
  class Pip < Source
8
8
  VERSION_OPERATORS = %w(< > <= >= == !=).freeze
9
- PACKAGE_REGEX = /^(\w+)(#{VERSION_OPERATORS.join("|")})?/
9
+ PACKAGE_REGEX = /^([\w-]+)(#{VERSION_OPERATORS.join("|")})?/
10
10
 
11
11
  def enabled?
12
12
  return unless virtual_env_pip && Licensed::Shell.tool_available?(virtual_env_pip)
@@ -16,7 +16,7 @@ module Licensed
16
16
  def enumerate_dependencies
17
17
  packages_from_requirements_txt.map do |package_name|
18
18
  package = package_info(package_name)
19
- location = File.join(package["Location"], package["Name"] + "-" + package["Version"] + ".dist-info")
19
+ location = File.join(package["Location"], package["Name"].gsub("-", "_") + "-" + package["Version"] + ".dist-info")
20
20
  Dependency.new(
21
21
  name: package["Name"],
22
22
  version: package["Version"],
@@ -35,6 +35,7 @@ module Licensed
35
35
  def packages_from_requirements_txt
36
36
  File.read(@config.pwd.join("requirements.txt"))
37
37
  .lines
38
+ .reject { |line| line.include?("://") }
38
39
  .map { |line| line.strip.match(PACKAGE_REGEX) { |match| match.captures.first } }
39
40
  .compact
40
41
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  module Licensed
3
- VERSION = "2.1.0".freeze
3
+ VERSION = "2.2.0".freeze
4
4
 
5
5
  def self.previous_major_versions
6
6
  major_version = Gem::Version.new(Licensed::VERSION).segments.first
data/licensed.gemspec CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "pathname-common_prefix", "~> 0.0.1"
29
29
  spec.add_dependency "tomlrb", "~> 1.2"
30
30
  spec.add_dependency "bundler", ">= 1.10"
31
+ spec.add_dependency "ruby-xxHash", "~> 0.4"
31
32
 
32
33
  spec.add_development_dependency "rake", "~> 10.0"
33
34
  spec.add_development_dependency "minitest", "~> 5.8"
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: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-17 00:00:00.000000000 Z
11
+ date: 2019-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: licensee
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.10'
83
+ - !ruby/object:Gem::Dependency
84
+ name: ruby-xxHash
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.4'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.4'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: rake
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -236,6 +250,7 @@ files:
236
250
  - lib/licensed/sources/git_submodule.rb
237
251
  - lib/licensed/sources/go.rb
238
252
  - lib/licensed/sources/gradle.rb
253
+ - lib/licensed/sources/helpers/content_versioning.rb
239
254
  - lib/licensed/sources/manifest.rb
240
255
  - lib/licensed/sources/npm.rb
241
256
  - lib/licensed/sources/pip.rb