File: Rakefile

package info (click to toggle)
ruby-mime-types-data 3.2024.0206-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,652 kB
  • sloc: ruby: 9; makefile: 7
file content (170 lines) | stat: -rw-r--r-- 4,776 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# frozen_string_literal: true

require "rubygems"
require "hoe"
require "rake/clean"

Hoe.plugin :doofus
Hoe.plugin :gemspec2
Hoe.plugin :git2
Hoe.plugin :rubygems

Hoe.spec "mime-types-data" do
  developer("Austin Ziegler", "halostatue@gmail.com")

  self.history_file = "History.md"
  self.readme_file = "README.md"

  license "MIT"

  require_ruby_version ">= 2.0"

  spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" }

  extra_dev_deps << ["hoe", "~> 4.0"]
  extra_dev_deps << ["hoe-doofus", "~> 1.0"]
  extra_dev_deps << ["hoe-gemspec2", "~> 1.1"]
  extra_dev_deps << ["hoe-git2", "~> 1.7"]
  extra_dev_deps << ["hoe-rubygems", "~> 1.0"]
  extra_dev_deps << ["mime-types", ">= 3.4.0", "< 4"]
  extra_dev_deps << ["nokogiri", "~> 1.6"]
  extra_dev_deps << ["psych", "~> 3.0"]
  extra_dev_deps << ["rake", ">= 10.0", "< 14"]
  extra_dev_deps << ["standard", "~> 1.0"]
end

$LOAD_PATH.unshift "lib"
$LOAD_PATH.unshift "support"

def new_version
  version =
    IO.read("lib/mime/types/data.rb").scan(/VERSION = ['"](\d\.\d{4}\.\d{4}(?:\.\d+)?)['"]/).flatten.first

  major = Gem::Version.new(version).canonical_segments.first
  minor = Date.today.strftime("%Y.%m%d")

  "#{major}.#{minor}"
end

def release_header
  "#{new_version} / #{Date.today.strftime("%Y-%m-%d")}"
end

namespace :mime do
  desc "Download the current MIME type registrations from IANA."
  task :iana, [:destination] do |_, args|
    require "iana_registry"
    IANARegistry.download(to: args.destination)
  end

  desc "Download the current MIME type configuration from Apache."
  task :apache, [:destination] do |_, args|
    require "apache_mime_types"
    ApacheMIMETypes.download(to: args.destination)
  end
end

namespace :release do
  task __pull: %w[mime:apache mime:iana convert]
  task __prepare: %w[update:version update:history git:manifest]
  task :__commit do
    history = IO.read("History.md")
    message = history.scan(%r{## (#{release_header}.+?)## \d\.\d{4}\.\d{4} /}m).flatten.first

    IO.popen("git commit -a -F -", "w") { |commit|
      commit.puts message
    }
  end

  desc "Prepare a new release for use with GitHub Actions"
  task :gha do
    require "prepare_release"

    pr = PrepareRelease.new
    pr.download_and_convert
    pr.write_updated_version
    pr.write_updated_history
    pr.rake_git_manifest
    pr.rake_gemspec
    pr.as_gha_vars
  end

  desc "Prepare a new automatic release"
  task automatic: :__pull do
    if system("git diff --quiet --exit-code") == false
      Rake::Task["release:__prepare"].invoke
      Rake::Task["gemspec"].invoke
      Rake::Task["release:__commit"].invoke
    else
      warn "No changes detected."
    end
  end
end

namespace :convert do
  namespace :yaml do
    desc "Convert from YAML to JSON"
    task :json, [:source, :destination, :multiple_files] do |_, args|
      require "convert"
      Convert.from_yaml_to_json(from: args.source, to: args.destination, multiple_files: args.multiple_files)
    end

    desc "Convert from YAML to Columnar"
    task :columnar, [:source, :destination] do |_, args|
      require "convert/columnar"
      Convert::Columnar.from_yaml_to_columnar(from: args.source, to: args.destination)
    end

    desc "Convert from YAML to mini_mime db format"
    task :mini_mime, [:source, :destination] do |_, args|
      require "convert/mini_mime_db"
      Convert::MiniMimeDb.from_yaml_to_mini_mime(from: args.source, to: args.destination)
    end
  end

  namespace :json do
    desc "Convert from JSON to YAML"
    task :yaml, [:source, :destination, :multiple_files] do |_, args|
      require "convert"
      Convert.from_json_to_yaml(from: args.source, to: args.destination, multiple_files: args.multiple_files)
    end
  end
end

namespace :update do
  desc "Update the release version"
  task :version do
    file = IO.read("lib/mime/types/data.rb")
    updated = file.sub(/VERSION = ['"][.0-9]+['"]/, %(VERSION = "#{new_version}"))

    IO.write("lib/mime/types/data.rb", updated)
  end

  desc "Update the history file with automatic release notes"
  task :history do
    history = IO.read("History.md")

    if !/^## #{release_header}$/.match?(history)
      note = <<-NOTE
<!-- automatic-release -->

## #{release_header}

- Updated the Apache and IANA media registry entries as of release date.
      NOTE

      updated = history.sub("<!-- automatic-release -->\n", note)

      IO.write("History.md", updated)
    end
  end
end

desc "Default conversion from YAML to JSON and Columnar"
task convert: ["convert:yaml:json", "convert:yaml:columnar", "convert:yaml:mini_mime"]

Rake::Task["gem"].prerequisites.unshift("convert")
Rake::Task["gem"].prerequisites.unshift("git:manifest")
Rake::Task["gem"].prerequisites.unshift("gemspec")

# vim: syntax=ruby