gem-licenses 0.2.2 → 0.3.0
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 +4 -4
- data/.github/workflows/lint.yml +31 -0
- data/.github/workflows/release.yml +27 -0
- data/.github/workflows/test.yml +39 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +90 -4
- data/.rubocop_todo.yml +83 -24
- data/.spellcheck.txt +44 -0
- data/CHANGELOG.md +14 -2
- data/CONTRIBUTING.md +10 -13
- data/Gemfile +10 -1
- data/README.md +34 -21
- data/RELEASING.md +20 -48
- data/Rakefile +22 -3
- data/exe/gem-licenses +8 -0
- data/gem-licenses.gemspec +4 -2
- data/lib/gem/licenses.rb +2 -2
- data/lib/gem/specification.rb +18 -15
- data/lib/gem-licenses/cli.rb +97 -0
- data/lib/gem-licenses/copyrights.rb +48 -0
- data/lib/gem-licenses/install_tasks.rb +2 -0
- data/lib/gem-licenses/railtie.rb +12 -0
- data/lib/gem-licenses/report.rb +46 -0
- data/lib/gem-licenses/version.rb +1 -1
- data/lib/gem-licenses.rb +1 -0
- data/lib/gem_licenses.rb +2 -0
- data/script/release.rb +18 -0
- data/spec/fixtures/gems/copyrights/LICENSE +7 -0
- data/spec/fixtures/gems/copyrights/README.md +17 -0
- data/spec/fixtures/gems/empty_reference_before_license/README +6 -0
- data/spec/fixtures/gems/licensed_under_the_apache_license/README.md +4 -0
- data/spec/fixtures/gems/mit_license_in_license_md/LICENSE.md +3 -0
- data/spec/fixtures/gems/same_terms_of_ruby/README +4 -0
- data/spec/gem/licenses_spec.rb +7 -1
- data/spec/gem/specification_spec.rb +49 -1
- data/spec/gem_licenses/cli_spec.rb +120 -0
- data/spec/gem_licenses/install_tasks_spec.rb +55 -0
- data/spec/release/release_spec.rb +74 -0
- data/spec/tasks/licenses_rake_spec.rb +101 -0
- data/tasks/licenses.rake +23 -27
- metadata +55 -12
- data/.travis.yml +0 -9
data/RELEASING.md
CHANGED
|
@@ -1,67 +1,39 @@
|
|
|
1
1
|
# Releasing Gem-Licenses
|
|
2
2
|
|
|
3
|
-
There
|
|
3
|
+
There are no hard rules about when to release gem-licenses. Release bug fixes frequently, features not so frequently, and breaking API changes rarely.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Releases use [ruby-gem-release](https://github.com/dblock/ruby-gem-release) 0.9.0 through a manually dispatched [Release workflow](.github/workflows/release.yml). Keep the `ruby-gem-release` gem in [Gemfile](Gemfile) and the reusable workflow in `release.yml` pinned to the same version. The workflow publishes through RubyGems Trusted Publishing, so no RubyGems API key or one-time password is needed. It only runs from `master` in `dblock/gem-licenses`. The local Bundler `rake release`, `release:rubygem_push`, and `release:source_control_push` tasks are disabled.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## One-Time Setup
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
bundle install
|
|
11
|
-
rake
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/gem-licenses) for all supported platforms.
|
|
15
|
-
|
|
16
|
-
Increment the version, modify [lib/gem-licenses/version.rb](lib/gem-licenses/version.rb).
|
|
17
|
-
|
|
18
|
-
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.2.1` to `0.2.2`).
|
|
19
|
-
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.2.1` to `0.3.0`).
|
|
20
|
-
|
|
21
|
-
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
### 0.2.2 (7/10/2015)
|
|
25
|
-
```
|
|
9
|
+
Before the first automated release, a maintainer must:
|
|
26
10
|
|
|
27
|
-
|
|
11
|
+
1. Create the GitHub environment `release` in `dblock/gem-licenses`, for example with `gh api --method PUT repos/dblock/gem-licenses/environments/release`, and restrict its deployment branches to `master`. Add required reviewers to require maintainer approval before publication.
|
|
12
|
+
2. On the gem's [trusted publishers page](https://rubygems.org/gems/gem-licenses/trusted_publishers), add a GitHub Actions publisher with repository owner `dblock`, repository `gem-licenses`, workflow filename `release.yml`, environment `release`, and the separate workflow repository owner `dblock` and repository `ruby-gem-release`.
|
|
13
|
+
3. Allow GitHub Actions to push release commits and `v*` tags to `master`. See the upstream [setup and permissions guidance](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/RELEASING.md#one-time-setup).
|
|
28
14
|
|
|
29
|
-
|
|
15
|
+
Verify the setup without publishing with a [dry run](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#dry-run), which never edits files, builds, pushes, or publishes:
|
|
30
16
|
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
git commit -m "Preparing for release, 0.2.2."
|
|
34
|
-
git push origin master
|
|
17
|
+
```sh
|
|
18
|
+
gh workflow run release.yml --repo dblock/gem-licenses --ref master -f dry-run=true
|
|
35
19
|
```
|
|
36
20
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
$ rake release
|
|
21
|
+
## Prepare
|
|
41
22
|
|
|
42
|
-
gem-licenses
|
|
43
|
-
Tagged v0.2.2.
|
|
44
|
-
Pushed git commits and tags.
|
|
45
|
-
Pushed gem-licenses 0.2.2 to rubygems.org.
|
|
46
|
-
```
|
|
23
|
+
Start with a clean, up-to-date `master` and verify that the latest [CI checks](https://github.com/dblock/gem-licenses/actions) pass on all supported Ruby versions. Follow semantic versioning: patch for fixes, minor for backward-compatible features, major for breaking changes. Check `VERSION` in [lib/gem-licenses/version.rb](lib/gem-licenses/version.rb) and the matching `(Next)` heading in [CHANGELOG.md](CHANGELOG.md), and change both in a pull request if needed, or pass a `version` override when dispatching.
|
|
47
24
|
|
|
48
|
-
|
|
25
|
+
The workflow dates the `(Next)` heading using `M/D/YYYY`, matching earlier releases, and removes the `* Your contribution here.` placeholder; a section without notes cannot be released.
|
|
49
26
|
|
|
50
|
-
|
|
27
|
+
Release automation requires MRI Ruby 3.3 or newer; the release dependency and tasks are skipped on older Ruby versions and JRuby. Release specs in [spec/release](spec/release) run the actual release tasks against a local fixture with the [ruby-gem-release RSpec helpers](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/testing.md), without contacting RubyGems or GitHub.
|
|
51
28
|
|
|
52
|
-
|
|
53
|
-
Next Release
|
|
54
|
-
============
|
|
29
|
+
## Publish
|
|
55
30
|
|
|
56
|
-
|
|
31
|
+
```sh
|
|
32
|
+
gh workflow run release.yml --repo dblock/gem-licenses --ref master
|
|
57
33
|
```
|
|
58
34
|
|
|
59
|
-
|
|
35
|
+
Pass `-f version=x.y.z` to release a different version. Dispatching starts a real release; do not merge into `master` while it runs. The workflow prepares the release commit, runs lint and specs on Ruby 3.3, builds the gem, preserves recovery artifacts, publishes to RubyGems, pushes the release commit and `v` tag, and creates a GitHub Release with the changelog notes and the gem attached. It then increments the patch version, adds a new `(Next)` section, and pushes the next development commit. Verify the published version on [RubyGems](https://rubygems.org/gems/gem-licenses), the tag, the [GitHub Release](https://github.com/dblock/gem-licenses/releases), and the next development commit.
|
|
60
36
|
|
|
61
|
-
|
|
37
|
+
## Recover a Partial Release
|
|
62
38
|
|
|
63
|
-
|
|
64
|
-
git add CHANGELOG.md lib/gem-licenses/version.rb
|
|
65
|
-
git commit -m "Preparing for next development iteration, 0.2.3."
|
|
66
|
-
git push origin master
|
|
67
|
-
```
|
|
39
|
+
Inspect the failed run, RubyGems, remote commits and tags, and the GitHub Release before retrying. Publication may have succeeded even if a later step failed. Never move a published tag or republish a version with different contents. Use the run's retained recovery artifacts and the upstream [recovery instructions](https://github.com/dblock/ruby-gem-release/blob/v0.9.0/docs/actions/release.md#recovery-artifacts).
|
data/Rakefile
CHANGED
|
@@ -8,14 +8,33 @@ require 'rspec/core/rake_task'
|
|
|
8
8
|
|
|
9
9
|
RSpec::Core::RakeTask.new(:spec)
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
lint = RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
|
|
12
|
+
Gem.loaded_specs.key?('rubocop')
|
|
13
|
+
if lint
|
|
14
|
+
require 'rubocop/rake_task'
|
|
15
|
+
RuboCop::RakeTask.new(:rubocop)
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
desc 'Lint Ruby, Markdown, YAML, and spelling'
|
|
18
|
+
task lint: :rubocop
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
task default: lint ? %i[rubocop spec] : %i[spec]
|
|
15
22
|
|
|
16
23
|
require 'rake'
|
|
17
24
|
|
|
18
25
|
Bundler::GemHelper.install_tasks
|
|
19
26
|
|
|
27
|
+
if RUBY_ENGINE == 'ruby' && Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.3') &&
|
|
28
|
+
Gem.loaded_specs.key?('ruby-gem-release')
|
|
29
|
+
require_relative 'script/release'
|
|
30
|
+
GemLicensesRelease.workflow.install_tasks
|
|
31
|
+
|
|
32
|
+
%w[release release:rubygem_push release:source_control_push].each do |name|
|
|
33
|
+
Rake::Task[name].clear
|
|
34
|
+
desc 'Disabled; releases run through GitHub Actions, see RELEASING.md'
|
|
35
|
+
task(name) { abort "#{name} is disabled; releases run through GitHub Actions, see RELEASING.md" }
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
20
39
|
require 'gem_licenses'
|
|
21
40
|
Gem::GemLicenses.install_tasks
|
data/exe/gem-licenses
ADDED
data/gem-licenses.gemspec
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
require 'gem-licenses/version'
|
|
1
|
+
require_relative 'lib/gem-licenses/version'
|
|
3
2
|
|
|
4
3
|
Gem::Specification.new do |s|
|
|
5
4
|
s.name = 'gem-licenses'
|
|
@@ -11,6 +10,9 @@ Gem::Specification.new do |s|
|
|
|
11
10
|
s.files = `git ls-files`.split("\n")
|
|
12
11
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
13
12
|
s.require_paths = ['lib']
|
|
13
|
+
s.bindir = 'exe'
|
|
14
|
+
s.executables = ['gem-licenses']
|
|
15
|
+
s.add_dependency 'csv'
|
|
14
16
|
s.homepage = 'http://github.com/dblock/gem-licenses'
|
|
15
17
|
s.licenses = ['MIT']
|
|
16
18
|
s.summary = 'Attempts to figure out what licenses various gems use.'
|
data/lib/gem/licenses.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
module Gem
|
|
2
|
-
def self.licenses
|
|
2
|
+
def self.licenses(specs = Gem.loaded_specs.values)
|
|
3
3
|
licenses = {}
|
|
4
4
|
config_path = File.expand_path('../../licenses/config.yml', __FILE__)
|
|
5
5
|
config = YAML.safe_load(File.read(config_path))
|
|
6
|
-
|
|
6
|
+
specs.each do |spec|
|
|
7
7
|
spec.licenses.map(&:downcase).each do |license|
|
|
8
8
|
license_name = config[license] || license
|
|
9
9
|
licenses[license_name] ||= []
|
data/lib/gem/specification.rb
CHANGED
|
@@ -3,16 +3,18 @@ module Gem
|
|
|
3
3
|
alias __licenses licenses
|
|
4
4
|
|
|
5
5
|
LICENSE_REFERENCES = [
|
|
6
|
-
/released under the (?<l>[\s\w]
|
|
7
|
-
/same license as (?<l>[\s\w]
|
|
8
|
-
|
|
9
|
-
/^(?<l>[\w]
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/^
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
/license
|
|
6
|
+
/released under the (?<l>[\s\w]+) license/i,
|
|
7
|
+
/same license as (?<l>[\s\w]+)/i,
|
|
8
|
+
/same terms of (?<l>[\s\w]+)/i,
|
|
9
|
+
/^(?<l>[\s\w]+) License, see/i,
|
|
10
|
+
/^(?<l>[\w]+) license$/i,
|
|
11
|
+
/\(the (?<l>[\s\w]+) license\)/i,
|
|
12
|
+
/^license: (?<l>[\s\w]+)/i,
|
|
13
|
+
/^released under the (?<l>[\s\w]+) license/i,
|
|
14
|
+
/licensed under the (?<l>[\s\w]+) license/i,
|
|
15
|
+
/license: (?<l>[\s\w]+)$/i,
|
|
16
|
+
/^same as (?<l>[\s\w]+)/i,
|
|
17
|
+
/license of (?<l>[\s\w]+)/i
|
|
16
18
|
].freeze
|
|
17
19
|
|
|
18
20
|
def licenses
|
|
@@ -35,8 +37,8 @@ module Gem
|
|
|
35
37
|
end
|
|
36
38
|
licenses << 'unknown' if licenses.empty?
|
|
37
39
|
licenses
|
|
38
|
-
rescue Errno::ENOENT
|
|
39
|
-
|
|
40
|
+
rescue Errno::ENOENT => e
|
|
41
|
+
warn "gem-licenses: #{e.message}."
|
|
40
42
|
[]
|
|
41
43
|
end
|
|
42
44
|
|
|
@@ -66,15 +68,16 @@ module Gem
|
|
|
66
68
|
file_handle = File.new(path, 'r')
|
|
67
69
|
begin
|
|
68
70
|
while (line = file_handle.gets)
|
|
69
|
-
|
|
71
|
+
# Markdown headings, such as `# MIT License` in LICENSE.md
|
|
72
|
+
line = line.strip.sub(/\A#+\s*/, '')
|
|
70
73
|
# positive matches
|
|
71
74
|
LICENSE_REFERENCES.each do |r|
|
|
72
75
|
res = r.match(line)
|
|
73
76
|
return [res['l']] if res
|
|
74
77
|
end
|
|
75
78
|
end
|
|
76
|
-
rescue StandardError
|
|
77
|
-
|
|
79
|
+
rescue StandardError => e
|
|
80
|
+
warn "gem-licenses: cannot read #{path}: #{e.message}."
|
|
78
81
|
ensure
|
|
79
82
|
file_handle.close
|
|
80
83
|
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
|
|
5
|
+
module Gem
|
|
6
|
+
module GemLicenses
|
|
7
|
+
# The gem-licenses command, which reports the licenses of the gems in a project's bundle.
|
|
8
|
+
class CLI
|
|
9
|
+
class Error < StandardError; end
|
|
10
|
+
|
|
11
|
+
BANNER = <<~TEXT
|
|
12
|
+
Usage: gem-licenses [options]
|
|
13
|
+
|
|
14
|
+
Lists the licenses of the gems in a project's bundle.
|
|
15
|
+
|
|
16
|
+
TEXT
|
|
17
|
+
|
|
18
|
+
OPTIONS = [
|
|
19
|
+
[:gemfile, '--gemfile PATH', 'Gemfile of the project, default: BUNDLE_GEMFILE or ./Gemfile.'],
|
|
20
|
+
[:csv, '--csv FILE', 'Write gems and licenses to a CSV file instead of listing them.'],
|
|
21
|
+
[:strict, '--strict', 'Exit with status 1 when a gem has no guessable license.'],
|
|
22
|
+
[:version, '-v', '--version', 'Show the version.'],
|
|
23
|
+
[:help, '-h', '--help', 'Show this help.']
|
|
24
|
+
].freeze
|
|
25
|
+
|
|
26
|
+
def self.start(argv = ARGV)
|
|
27
|
+
exit new.run(argv)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def initialize(out: $stdout, err: $stderr)
|
|
31
|
+
@out = out
|
|
32
|
+
@err = err
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def run(argv)
|
|
36
|
+
options = parse(argv.dup)
|
|
37
|
+
return info(options) if options[:help] || options[:version]
|
|
38
|
+
|
|
39
|
+
report(options, bundle_specs(options[:gemfile]))
|
|
40
|
+
rescue OptionParser::ParseError, Error => e
|
|
41
|
+
@err.puts "gem-licenses: #{e.message.chomp('.')}.", 'Run gem-licenses --help for usage.'
|
|
42
|
+
2
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def parse(argv)
|
|
48
|
+
options = {}
|
|
49
|
+
@parser = OptionParser.new do |opts|
|
|
50
|
+
opts.banner = BANNER
|
|
51
|
+
OPTIONS.each { |key, *args| opts.on(*args) { |value| options[key] = value } }
|
|
52
|
+
end
|
|
53
|
+
@parser.parse!(argv)
|
|
54
|
+
raise Error, "unexpected argument: #{argv.first}" unless argv.empty?
|
|
55
|
+
|
|
56
|
+
options
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def info(options)
|
|
60
|
+
@out.puts options[:help] ? @parser.help : "gem-licenses #{VERSION}"
|
|
61
|
+
0
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def report(options, specs)
|
|
65
|
+
licenses = Gem.licenses(specs)
|
|
66
|
+
if options[:csv]
|
|
67
|
+
Report.csv(licenses, File.expand_path(options[:csv]), @out)
|
|
68
|
+
else
|
|
69
|
+
Report.text(licenses, @out)
|
|
70
|
+
end
|
|
71
|
+
options[:strict] && licenses.key?('unknown') ? 1 : 0
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Reports only the gems in the project's bundle, not every gem loaded in this process. Under bundle exec,
|
|
75
|
+
# Bundler has already set up the project's bundle; otherwise, set up the project's Gemfile.
|
|
76
|
+
def bundle_specs(gemfile)
|
|
77
|
+
setup_bundle(gemfile) unless gemfile.nil? && bundled?
|
|
78
|
+
Bundler.load.specs.to_a
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def setup_bundle(gemfile)
|
|
82
|
+
gemfile = File.expand_path(gemfile || ENV.fetch('BUNDLE_GEMFILE', 'Gemfile'))
|
|
83
|
+
raise Error, "no Gemfile at #{gemfile}" unless File.file?(gemfile)
|
|
84
|
+
|
|
85
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
|
86
|
+
require 'bundler'
|
|
87
|
+
Bundler.setup
|
|
88
|
+
rescue Bundler::BundlerError => e
|
|
89
|
+
raise Error, "could not load #{gemfile}: #{e.message}"
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def bundled?
|
|
93
|
+
defined?(Bundler) && ENV.key?('BUNDLE_GEMFILE')
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Gem
|
|
4
|
+
module GemLicenses
|
|
5
|
+
# Collects copyright lines from a gem's license, notice, and readme files; included into Gem::Specification.
|
|
6
|
+
module Copyrights
|
|
7
|
+
COPYRIGHT_FILES = /license|licence|copying|copyright|notice|readme/i.freeze
|
|
8
|
+
|
|
9
|
+
# A copyright line starts with "Copyright" or "©", optionally surrounded by "(c)" or "©", and names
|
|
10
|
+
# its holder; prose such as "Copyright notice" and template placeholders such as "[year]" are skipped.
|
|
11
|
+
COPYRIGHT_REFERENCE = /
|
|
12
|
+
\A(?:\(c\)\s*)?(?:copyright|©)(?>(?:\s*(?:\(c\)|©))?)\s+
|
|
13
|
+
(?!(?:notices?|owners?|holders?|licen[cs]es?|of|on|and|statements?|laws?)\b|[\[{<])
|
|
14
|
+
(?<c>\S.*)
|
|
15
|
+
/ix.freeze
|
|
16
|
+
|
|
17
|
+
def copyrights
|
|
18
|
+
copyrights = []
|
|
19
|
+
Dir.children(full_gem_path).sort.each do |filename|
|
|
20
|
+
path = File.join(full_gem_path, filename)
|
|
21
|
+
next unless File.file?(path) && File.basename(filename, File.extname(filename)).match?(COPYRIGHT_FILES)
|
|
22
|
+
|
|
23
|
+
copyrights.concat(copyrights_from_file(path))
|
|
24
|
+
end
|
|
25
|
+
copyrights.uniq
|
|
26
|
+
rescue Errno::ENOENT => e
|
|
27
|
+
warn "gem-licenses: #{e.message}."
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def copyrights_from_file(path)
|
|
34
|
+
File.foreach(path).filter_map do |line|
|
|
35
|
+
match = COPYRIGHT_REFERENCE.match(line.strip.sub(/\A#+\s*/, ''))
|
|
36
|
+
match['c'].strip if match
|
|
37
|
+
end
|
|
38
|
+
rescue StandardError => e
|
|
39
|
+
warn "gem-licenses: cannot read #{path}: #{e.message}."
|
|
40
|
+
[]
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Specification
|
|
46
|
+
include GemLicenses::Copyrights
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
|
|
5
|
+
module Gem
|
|
6
|
+
module GemLicenses
|
|
7
|
+
# Formats Gem.licenses as text or CSV for the Rake tasks and the command-line interface.
|
|
8
|
+
module Report
|
|
9
|
+
CSV_HEADERS = %w[name version homepage summary license].freeze
|
|
10
|
+
|
|
11
|
+
def self.text(licenses, out = $stdout)
|
|
12
|
+
licenses.sort_by { |license, gems| [-gems.count, license] }.each do |license, gems|
|
|
13
|
+
out.puts license.to_s, '=' * license.length
|
|
14
|
+
gems.sort_by(&:name).each { |gem| out.puts describe(gem), gem.full_gem_path }
|
|
15
|
+
out.puts ''
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.csv(licenses, filename, out = $stdout)
|
|
20
|
+
out.puts "Writing #{filename} ..."
|
|
21
|
+
rows = csv_rows(licenses)
|
|
22
|
+
CSV.open(filename, 'w') { |csv| ([CSV_HEADERS] + rows).each { |row| csv << row } }
|
|
23
|
+
names = licenses.keys.sort.join(', ')
|
|
24
|
+
out.puts "Written #{licenses.keys.count} license(s) for #{rows.count} project(s): #{names}"
|
|
25
|
+
unknown(licenses, out)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.unknown(licenses, out = $stdout)
|
|
29
|
+
return unless licenses.key?('unknown')
|
|
30
|
+
|
|
31
|
+
out.puts "IMPORTANT: You have #{licenses['unknown'].count} projects without a guessable license!"
|
|
32
|
+
licenses['unknown'].sort_by(&:name).each { |gem| out.puts " #{gem.name}: #{gem.full_gem_path}" }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.describe(gem)
|
|
36
|
+
"* #{gem.name} #{gem.version} (#{gem.homepage}) - #{gem.summary.to_s.strip}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.csv_rows(licenses)
|
|
40
|
+
licenses.sort.flat_map do |license, gems|
|
|
41
|
+
gems.sort_by(&:name).map { |gem| [gem.name, gem.version, gem.homepage, gem.summary.to_s.strip, license] }
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
data/lib/gem-licenses/version.rb
CHANGED
data/lib/gem-licenses.rb
CHANGED
data/lib/gem_licenses.rb
CHANGED
data/script/release.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'ruby-gem-release/changelog'
|
|
4
|
+
require 'ruby-gem-release/workflow/ruby_gem'
|
|
5
|
+
|
|
6
|
+
# Builds the ruby-gem-release workflow used by the Rakefile, the Release GitHub Actions workflow, and spec/release.
|
|
7
|
+
module GemLicensesRelease
|
|
8
|
+
def self.workflow(**options)
|
|
9
|
+
RubyGemRelease::Workflow::RubyGem.new(
|
|
10
|
+
version: RubyGemRelease::Version::RubyConstant.new(path: 'lib/gem-licenses/version.rb', constant: 'VERSION'),
|
|
11
|
+
changelog: RubyGemRelease::Changelog::Intridea.new(
|
|
12
|
+
placeholder: '* Your contribution here.',
|
|
13
|
+
date_format: '%-m/%-d/%Y'
|
|
14
|
+
),
|
|
15
|
+
**options
|
|
16
|
+
)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Jane Doe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software.
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Example
|
|
2
|
+
|
|
3
|
+
Copyright notice
|
|
4
|
+
|
|
5
|
+
(c) You must retain all copyright notices.
|
|
6
|
+
|
|
7
|
+
Copyright (c) <year> <copyright holders>
|
|
8
|
+
|
|
9
|
+
Copyright [yyyy] [name of copyright owner]
|
|
10
|
+
|
|
11
|
+
Copyright (c) 2019 Jane Doe
|
|
12
|
+
|
|
13
|
+
© 2020 Example Corp
|
|
14
|
+
|
|
15
|
+
## Copyright 2021 John Roe
|
|
16
|
+
|
|
17
|
+
(c) Copyright 2022 Richard Roe
|
data/spec/gem/licenses_spec.rb
CHANGED
|
@@ -15,6 +15,12 @@ describe Gem do
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
it 'normalizes known license names' do
|
|
18
|
-
|
|
18
|
+
gpl_spec = Gem::Specification.new do |spec|
|
|
19
|
+
spec.name = 'gpl-gem'
|
|
20
|
+
spec.version = '1.0.0'
|
|
21
|
+
spec.licenses = ['GPL-2']
|
|
22
|
+
end
|
|
23
|
+
allow(Gem).to receive(:loaded_specs).and_return('gpl-gem' => gpl_spec)
|
|
24
|
+
expect(subject['GPLv2']).to eq [gpl_spec]
|
|
19
25
|
end
|
|
20
26
|
end
|
|
@@ -22,13 +22,61 @@ describe Gem::Specification do
|
|
|
22
22
|
expect(spec.guess_licenses).to eq(['BSD'])
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
it 'matches "licensed under the ___ license"' do
|
|
26
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('licensed_under_the_apache_license'))
|
|
27
|
+
expect(spec.guess_licenses).to eq(['Apache'])
|
|
28
|
+
end
|
|
29
|
+
|
|
25
30
|
it 'matches "same license as ___"' do
|
|
26
31
|
allow(spec).to receive(:full_gem_path).and_return(gem_dir('same_license_as_ruby'))
|
|
27
32
|
expect(spec.guess_licenses).to eq(['Ruby'])
|
|
28
33
|
end
|
|
29
34
|
|
|
35
|
+
it 'matches "same terms of ___"' do
|
|
36
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('same_terms_of_ruby'))
|
|
37
|
+
expect(spec.guess_licenses).to eq(['Ruby'])
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it 'finds the license in LICENSE.md' do
|
|
41
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('mit_license_in_license_md'))
|
|
42
|
+
expect(spec.guess_licenses).to eq(['MIT'])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'skips references without a license name' do
|
|
46
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('empty_reference_before_license'))
|
|
47
|
+
expect(spec.guess_licenses).to eq(['MIT'])
|
|
48
|
+
end
|
|
49
|
+
|
|
30
50
|
it 'gracefully recovers from unparseable files' do
|
|
31
51
|
allow(spec).to receive(:full_gem_path).and_return(gem_dir('nonstandard_characters'))
|
|
32
|
-
expect(spec.guess_licenses).to eq(['unknown'])
|
|
52
|
+
expect { expect(spec.guess_licenses).to eq(['unknown']) }.to output(
|
|
53
|
+
%r{\Agem-licenses: cannot read .*/nonstandard_characters/README.md: invalid byte sequence in UTF-8\.\n\z}
|
|
54
|
+
).to_stderr
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
describe '#copyrights' do
|
|
58
|
+
it 'collects copyright lines from license and readme files' do
|
|
59
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('copyrights'))
|
|
60
|
+
expect(spec.copyrights).to eq(['2019 Jane Doe', '2020 Example Corp', '2021 John Roe', '2022 Richard Roe'])
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'returns no copyrights without license or readme files' do
|
|
64
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('released_under_the_bsd_license'))
|
|
65
|
+
expect(spec.copyrights).to eq([])
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it 'warns about a missing gem directory' do
|
|
69
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('missing'))
|
|
70
|
+
expect { expect(spec.copyrights).to eq([]) }.to output(
|
|
71
|
+
/\Agem-licenses: No such file or directory .*missing\.\n\z/
|
|
72
|
+
).to_stderr
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it 'warns about a missing gem directory' do
|
|
77
|
+
allow(spec).to receive(:full_gem_path).and_return(gem_dir('missing'))
|
|
78
|
+
expect { expect(spec.guess_licenses).to eq([]) }.to output(
|
|
79
|
+
/\Agem-licenses: No such file or directory .*missing\.\n\z/
|
|
80
|
+
).to_stderr
|
|
33
81
|
end
|
|
34
82
|
end
|