Skip to content

Commit 60f2ab2

Browse files
committed
refactor runfiles
1 parent 752d7b9 commit 60f2ab2

File tree

7 files changed

+73
-74
lines changed

7 files changed

+73
-74
lines changed

runfile

Lines changed: 6 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,10 @@
1-
require "byebug"
2-
require 'bashly'
1+
require 'byebug'
2+
require 'bashly/version'
33
require_relative 'support/runfile/example'
44

5-
title "Bashly Developer Toolbelt"
6-
summary "Runfile tasks for building the Bashly gem"
7-
version Bashly::VERSION
5+
title 'Bashly Developer Toolbelt'
6+
summary 'Runfile tasks for building the Bashly gem'
87

9-
import_gem 'runfile-tasks/gem', gemname: 'bashly'
8+
import_gem 'runfile-tasks/gem'
109
import_gem 'runfile-tasks/docker', image: 'dannyben/bashly', version: Bashly::VERSION
11-
import 'support/runfile/examples'
12-
import 'support/runfile/debug'
13-
14-
help "Run shellcheck on all examples"
15-
action :shellcheck do
16-
allowed_skips = 1
17-
Example.executables.each do |example|
18-
if File.exist? example
19-
success = system "shellcheck #{example}"
20-
color = success ? 'g' : 'r'
21-
say "- shellcheck #{color}`#{example}`"
22-
exit 1 unless success
23-
else
24-
say "- skip c`#{example}`"
25-
allowed_skips -= 1
26-
if allowed_skips < 0
27-
say "- aborted: too many skips"
28-
exit 1
29-
end
30-
end
31-
end
32-
end
33-
34-
help "Run shfmt checks on all examples"
35-
action :shfmt do
36-
allowed_skips = 2
37-
Example.executables.each do |example|
38-
if example == 'examples/heredoc/cli' || !File.exist?(example)
39-
say "- skip c`#{example}`"
40-
allowed_skips -= 1
41-
if allowed_skips < 0
42-
say "- aborted: too many skips"
43-
exit 1
44-
end
45-
next
46-
end
47-
48-
success = system "shfmt -d -i 2 -ci #{example}"
49-
color = success ? 'g' : 'r'
50-
say "- shfmt #{color}`#{example}`"
51-
exit 1 unless success
52-
end
53-
end
54-
55-
help "Run json-schema checks on all examples"
56-
action :schema do
57-
Example.all.each do |example|
58-
file = example.yaml_path
59-
command = "check-jsonschema --schemafile schema.json #{file}"
60-
success = system command
61-
color = success ? 'g' : 'r'
62-
say "- check-jsonschema #{color}`#{example.dir}`"
63-
exit 1 unless success
64-
end
65-
end
66-
67-
help "Generate changelog and append old changelog"
68-
action :changelog do
69-
system "git changelog --save"
70-
# append older changelog (prior to switching to git-changelog)
71-
system "cat support/.changelog.old.md >> CHANGELOG.md"
72-
73-
# Fix typos
74-
File.write "CHANGELOG.md", File.read("CHANGELOG.md").gsub('repeatableflags', 'repeatable flags')
75-
end
10+
import 'support/runfile/*'

support/runfile/changelog.runfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
summary 'Generate changelog and append old changelog'
2+
3+
action do
4+
system "git changelog --save"
5+
# append older changelog (prior to switching to git-changelog)
6+
system "cat support/.changelog.old.md >> CHANGELOG.md"
7+
8+
# Fix typos
9+
File.write "CHANGELOG.md", File.read("CHANGELOG.md").gsub('repeatableflags', 'repeatable flags')
10+
end

support/runfile/example.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'yaml'
2+
13
# A helper class used in Runfile to generate example README files
24
class Example
35
class << self
@@ -21,7 +23,7 @@ def initialize(dir)
2123
end
2224

2325
def config
24-
@config ||= YAML.properly_load_file yaml_path
26+
@config ||= YAML.unsafe_load_file yaml_path
2527
end
2628

2729
def yaml

support/runfile/examples.runfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
title "Example Helpers"
1+
summary 'Regenerate example scripts'
22

3-
help "Regenerate example scripts"
43
action :regen do
54
# Patch the PATH to allow the extensible example to run properly
65
ENV['PATH']="#{Dir.pwd}/examples/extensible:#{ENV['PATH']}"

support/runfile/schema.runfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
summary 'Run json-schema checks on all examples'
2+
3+
action do
4+
Example.all.each do |example|
5+
file = example.yaml_path
6+
command = "check-jsonschema --schemafile schema.json #{file}"
7+
success = system command
8+
color = success ? 'g' : 'r'
9+
say "- check-jsonschema #{color}`#{example.dir}`"
10+
exit 1 unless success
11+
end
12+
end

support/runfile/shellcheck.runfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
summary 'Run shellcheck on all examples'
2+
3+
action do
4+
allowed_skips = 1
5+
Example.executables.each do |example|
6+
if File.exist? example
7+
success = system "shellcheck #{example}"
8+
color = success ? 'g' : 'r'
9+
say "- shellcheck #{color}`#{example}`"
10+
exit 1 unless success
11+
else
12+
say "- skip c`#{example}`"
13+
allowed_skips -= 1
14+
if allowed_skips < 0
15+
say "- aborted: too many skips"
16+
exit 1
17+
end
18+
end
19+
end
20+
end

support/runfile/shfmt.runfile

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
summary 'Run shfmt checks on all examples'
2+
3+
action do
4+
allowed_skips = 2
5+
Example.executables.each do |example|
6+
if example == 'examples/heredoc/cli' || !File.exist?(example)
7+
say "- skip c`#{example}`"
8+
allowed_skips -= 1
9+
if allowed_skips < 0
10+
say "- aborted: too many skips"
11+
exit 1
12+
end
13+
next
14+
end
15+
16+
success = system "shfmt -d -i 2 -ci #{example}"
17+
color = success ? 'g' : 'r'
18+
say "- shfmt #{color}`#{example}`"
19+
exit 1 unless success
20+
end
21+
end

0 commit comments

Comments
 (0)