-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathbuild.rb
executable file
·58 lines (43 loc) · 1.73 KB
/
build.rb
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
#!/usr/bin/env ruby
# Generate a GitHub Action with separate builds for every image
# based on the contents of the two target files
require "date"
require "erb"
require "fileutils"
@images = []
["linux", "alpine"].each do |target|
File.open(target).each do |line|
base,tag = line.split
@images.append [base, tag ? tag : base, target]
end
end
# Matrix builds require a least one item in the matrix to be valid
# so we grab the first entry to populate the matrix.
# Everything else is used as explicitly included jobs.
@seed = @images.shift
# Generate the dev.yml
templatename = File.join("_templates", "dev.yml.erb")
renderer = ERB.new(File.read(templatename))
File.open(".github/workflows/dev.yml", "w") { |file| file.puts renderer.result() }
# We need to write a file to trigger the image build action, as just changing the
# contents of workflow doesn't trigger it
File.open(".generated", "w") { |file| file.puts DateTime.now.iso8601 }
# Available distributions of snyk
# https://docs.snyk.io/snyk-cli/releases-and-channels-for-the-snyk-cli
release_channel_map = {
"stable" => "",
"preview" => "-preview",
"rc" => "-rc"
}
# Generate workflows for each distribution channel
release_channel_map.each do |release_channel, post_fix|
@release_channel = release_channel
@post_fix = post_fix
# Generate the workflow .yml
templatename = File.join("_templates", "release-channel.yml.erb")
renderer = ERB.new(File.read(templatename))
File.open(".github/workflows/" + release_channel + ".yml", "w") { |file| file.puts renderer.result() }
end
# We need to write a file to trigger the image build action, as just changing the
# contents of workflow doesn't trigger it
File.open(".generated", "w") { |file| file.puts DateTime.now.iso8601 }