yamlease 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/ye +15 -0
- data/lib/pipeline.erb +36 -0
- data/lib/yamlease.rb +139 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 24000ab0868dfc5d4ff909d95a3b8960f01980e3d376617f0aa7886fb87b4c6d
|
4
|
+
data.tar.gz: 873325fb4c005899ab7ac9768d8638967590ed6cfe0ee8370890a9355db0c45c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2af38f4626df5dfdec0024351849ac70539459cd5ca3a6c5f1882abf7b9ee02e321555a013255ae7c9b2b4004c64eded07296e3ff13b04a28adde636c66af59a
|
7
|
+
data.tar.gz: 9990c4f80cd527525735b385b8fecd3a2ff589956d3a5f0022095a655625a916d8586cee8323b6232d5ebd040f192588f1c8a14cff70d98b535c3c7e07350186
|
data/bin/ye
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless require_relative '../lib/yamlease'
|
4
|
+
require 'yamlease'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'erb'
|
8
|
+
|
9
|
+
rp = ReleasePipeline.new(ARGV.first)
|
10
|
+
|
11
|
+
stages = rp.stages
|
12
|
+
|
13
|
+
template = ERB.new(File.read("lib/pipeline.erb"), trim_mode: "-")
|
14
|
+
puts template.result(binding)
|
15
|
+
|
data/lib/pipeline.erb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
trigger:
|
2
|
+
- main
|
3
|
+
|
4
|
+
variables:
|
5
|
+
<% for key, value in rp.variables_to_yaml %>
|
6
|
+
<%= key %>: <%= value -%>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
pool:
|
10
|
+
|
11
|
+
vmImage: ubuntu-latest
|
12
|
+
|
13
|
+
stages:
|
14
|
+
|
15
|
+
- stage: BuildThings
|
16
|
+
jobs:
|
17
|
+
- job: Build
|
18
|
+
steps:
|
19
|
+
- bash: "echo Build your application here"
|
20
|
+
<% for stage in stages %>
|
21
|
+
- stage: <%= stage.name %>
|
22
|
+
jobs:
|
23
|
+
<% for job in stage.jobs %>
|
24
|
+
- job: <%= job.name %>
|
25
|
+
steps:
|
26
|
+
<% for task in job.tasks %>
|
27
|
+
- task: <%= task.yaml_name %>
|
28
|
+
displayName: "<%= task.display_name %>"
|
29
|
+
inputs:
|
30
|
+
<% for input in task.inputs -%>
|
31
|
+
<%= input.join(': ') %>
|
32
|
+
<% end %>
|
33
|
+
<% end %>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<% end %>
|
data/lib/yamlease.rb
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'yaml'
|
3
|
+
require "hash_with_dot_access"
|
4
|
+
|
5
|
+
|
6
|
+
class Stage
|
7
|
+
attr_reader :name, :url, :yaml
|
8
|
+
attr_writer :yaml
|
9
|
+
|
10
|
+
def initialize(name, url)
|
11
|
+
@name = name
|
12
|
+
@url = url
|
13
|
+
@tasks = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def jobs
|
17
|
+
self.yaml["deployPhases"].collect do |job|
|
18
|
+
_job = Job.new(job.name, job.badgeUrl)
|
19
|
+
_job.yaml = job
|
20
|
+
_job
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
class Job
|
27
|
+
attr_reader :url, :yaml
|
28
|
+
attr_writer :yaml
|
29
|
+
|
30
|
+
def initialize(name, url)
|
31
|
+
@name = name
|
32
|
+
@url = url
|
33
|
+
end
|
34
|
+
|
35
|
+
def tasks
|
36
|
+
self.yaml["workflowTasks"].collect do |task|
|
37
|
+
Task.new(yaml = task)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def name
|
42
|
+
parts = @name.split(" ")
|
43
|
+
parts.map do |part|
|
44
|
+
first_character = part[0]
|
45
|
+
part[0] = first_character.upcase
|
46
|
+
part
|
47
|
+
end.join("")
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class Task
|
53
|
+
attr_writer :yaml
|
54
|
+
attr_reader :display_name, :task_id
|
55
|
+
|
56
|
+
def initialize(yaml)
|
57
|
+
@yaml = yaml
|
58
|
+
@display_name = yaml.name
|
59
|
+
@task_id = yaml.taskId
|
60
|
+
end
|
61
|
+
|
62
|
+
def yaml_name
|
63
|
+
TaskDefinition.yaml_name(task_id)
|
64
|
+
end
|
65
|
+
|
66
|
+
def convert_vars_to_yaml(text)
|
67
|
+
text.gsub(/\$\((.+)\)/, '${{\1}}')
|
68
|
+
end
|
69
|
+
|
70
|
+
def inputs
|
71
|
+
_inputs = @yaml.inputs
|
72
|
+
_inputs.delete_if { |key, value| value == "" }
|
73
|
+
_inputs.each do |key, value|
|
74
|
+
if value.include?('*')
|
75
|
+
_inputs[key] = "'#{value}'"
|
76
|
+
end
|
77
|
+
value = _inputs[key]
|
78
|
+
_inputs[key] = convert_vars_to_yaml(value)
|
79
|
+
end
|
80
|
+
_inputs
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class TaskDefinition
|
86
|
+
def initialize
|
87
|
+
@file_read = File.read("task_map.txt")
|
88
|
+
end
|
89
|
+
|
90
|
+
def yaml_name(id)
|
91
|
+
matches = @file_read.split("\n").select do |line|
|
92
|
+
task_id, _task_name = line.split(" ")
|
93
|
+
task_id.downcase == id.downcase
|
94
|
+
end
|
95
|
+
|
96
|
+
task_name = matches.length > 0 ? matches[0].split(" ")[1] : "Unknown"
|
97
|
+
task_name.sub(/V(\d+)$/, '@\1')
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.yaml_name(id)
|
101
|
+
self.new.yaml_name(id)
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
class ReleasePipeline
|
107
|
+
attr_reader :url, :variables
|
108
|
+
|
109
|
+
def initialize(filename = nil)
|
110
|
+
raise ArgumentError.new("I need a YAML file to parse") if filename.nil?
|
111
|
+
self.parse(filename)
|
112
|
+
end
|
113
|
+
|
114
|
+
def parse(filename = "show.yml")
|
115
|
+
@pipeline = YAML.load(File.read(filename)).with_dot_access
|
116
|
+
@url = @pipeline["url"]
|
117
|
+
@variables = @pipeline["variables"]
|
118
|
+
end
|
119
|
+
|
120
|
+
def variables_to_yaml
|
121
|
+
response = {}
|
122
|
+
@variables.each do |key, value|
|
123
|
+
response[key] = value.value
|
124
|
+
end
|
125
|
+
response
|
126
|
+
end
|
127
|
+
|
128
|
+
# stages are environments
|
129
|
+
def stages
|
130
|
+
@pipeline["environments"].collect do |stage|
|
131
|
+
_stage = Stage.new(stage.name, stage.badgeUrl)
|
132
|
+
_stage.yaml = stage
|
133
|
+
_stage
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yamlease
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Julian Simpson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: |-
|
14
|
+
If you have a release pipeline in Azure DevOps, this gem will convert it to YAML. Export the release
|
15
|
+
definition to yaml and pipe it to this tool.
|
16
|
+
email: simpsonjulian@gmail.com
|
17
|
+
executables:
|
18
|
+
- ye
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- bin/ye
|
23
|
+
- lib/pipeline.erb
|
24
|
+
- lib/yamlease.rb
|
25
|
+
homepage: https://rubygems.org/gems/yamlease
|
26
|
+
licenses:
|
27
|
+
- AGPL-3.0
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubygems_version: 3.2.32
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: Convert Azure DevOps Release Pipelines to YAML
|
48
|
+
test_files: []
|