diff --git a/app/controllers/api/v1/projects/pipelines_controller.rb b/app/controllers/api/v1/projects/pipelines_controller.rb index 888e68960..8d8f7695b 100644 --- a/app/controllers/api/v1/projects/pipelines_controller.rb +++ b/app/controllers/api/v1/projects/pipelines_controller.rb @@ -6,6 +6,16 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipelines = paginate @pipelines end + def test_yaml + pipeline_yaml = build_pipeline_yaml_new("test", JSON.parse(demo2.to_json)) + respond_to do |format| + format.html { @nodes = Action::Node.all } + # format.yaml { @nodes = Action::Node.all } + format.yaml { render template: "api/v1/projects/pipelines/test_yaml", content_type: "text/html" } + format.json { render_ok({ pipeline_yaml: pipeline_yaml }) } + end + end + def create size = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).size tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0 @@ -29,7 +39,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController @pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml" @pipeline.branch = params[:branch] || @project.default_branch @pipeline.json = params[:pipeline_json].to_json - pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json]) + pipeline_yaml = build_pipeline_yaml_new(params[:pipeline_name], params[:pipeline_json]) tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank? @pipeline.yaml = pipeline_yaml Rails.logger.info "pipeline_yaml base64=========================#{Base64.encode64(@pipeline.yaml).gsub(/\n/, '')}" @@ -37,7 +47,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create")) tip_exception(interactor.error) unless interactor.success? file = interactor.result - render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) + render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] }) end def build_yaml @@ -85,8 +95,8 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController def build_pipeline_yaml(pipeline_name, pipeline_json) if pipeline_json.present? && pipeline_json.present? @pipeline_name = pipeline_name - params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } - on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } + params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["name"]) } + on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["name"]) } @on_nodes = build_nodes(on_nodes) @steps_nodes = build_nodes(params_nodes) yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) @@ -100,39 +110,23 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController pipeline_yaml end - def build_test_yaml - @pipeline_name = "I like it" - params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) } - on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) } + def build_pipeline_yaml_new(pipeline_name, pipeline_json) + @pipeline_name = pipeline_name + job_nodes = pipeline_json["nodes"].select { |node| node["data"]["name"].to_s.include?("job") } + on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule", "on-pull_request", "on-fork"].include?(node["data"]["name"]) } @on_nodes = build_nodes(on_nodes) - @steps_nodes = [] - params_nodes.each do |input_node| - # Rails.logger.info "input_node=====0===#{input_node["name"]}======#{input_node["inputs"]}" - node = Action::Node.find_by(name: input_node["name"]) + @job_nodes = [] + job_nodes.each do |job| + node = Action::Node.find_by(name: job["data"]["name"]) + node.label = job["data"]["label"] if job["data"]["label"].present? next if node.blank? - node.label = input_node["label"] if input_node["label"].present? - run_values = {} - input_values = {} - if input_node["inputs"].present? - Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}" - input_node["inputs"].each do |input| - # Rails.logger.info "@inputs.input_name===#{input[:name]}" - # Rails.logger.info "@inputs.input_value===#{input["value"]}" - if input[:name].to_s.gsub("--", "") == "run" - run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) - else - input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) - end - end - node.run_values = run_values - node.input_values = input_values - # Rails.logger.info "@input_values run_values===#{node.run_values.to_json}" - # Rails.logger.info "@input_values input_values===#{node.input_values.to_json}" - end - @steps_nodes.push(node) + next_edge_nodes = JSON.parse(demo2.to_json)["edges"].select { |edge| edge["source"]["cell"].include?(job["id"]) } + node_ids = next_edge_nodes.map { |t| t["target"]["cell"] } + next_step_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node_ids.include?(node["data"]["id"]) && !node["data"]["name"].to_s.include?("job") }&.first + node.sub_nodes = [] + get_all_child_nodes(node, next_step_node) if next_step_node.present? + @job_nodes.push(node) end - Rails.logger.info "@@on_nodes===#{@on_nodes.to_json}" - Rails.logger.info "@steps_nodes===#{@steps_nodes.to_json}" yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding) pipeline_yaml = yaml.gsub(/^\s*\n/, "") Rails.logger.info "=========================" @@ -177,10 +171,7 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController run_values = {} input_values = {} if input_node["inputs"].present? - Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}" input_node["inputs"].each do |input| - # Rails.logger.info "@inputs.input_name===#{input[:name]}" - # Rails.logger.info "@inputs.input_value===#{input["value"]}" if input[:name].to_s.gsub("--", "") == "run" run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" }) else @@ -195,269 +186,1694 @@ class Api::V1::Projects::PipelinesController < Api::V1::BaseController steps_nodes end - def demo + def get_all_child_nodes(job_node, target_node) + job_node.sub_nodes.push(get_node_info(target_node)) + target_edge = JSON.parse(demo2.to_json)["edges"].select { |node| node["source"]["cell"].to_s.include?(target_node["id"]) }&.first + # 判断是否有子节点 + if target_edge.present? + next_node = JSON.parse(demo2.to_json)["nodes"].select { |node| node["id"].include?(target_edge["target"]["cell"]) }.first + get_all_child_nodes(job_node, next_node) + end + end + + def get_node_info(input_node) + node = Action::Node.find_by(name: input_node["data"]["name"]) + return nil if node.blank? + node.label = input_node["data"]["label"] if input_node["data"]["label"].present? + run_values = {} + input_values = {} + if input_node["data"]["inputs"].present? + input_node["data"]["inputs"].each do |input| + if input["name"].to_s.gsub("--", "") == "run" + run_values = run_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) + else + input_values = input_values.merge({ "#{input["name"].gsub("--", "")}": "#{input["value"]}" }) + end + end + node.run_values = run_values + node.input_values = input_values + end + node + end + + def demo2 { - "nodes": [{ - "id": "on-schedule-2fcf505", - "name": "on-schedule", - "full_name": "on-schedule", - "description": " 定时器计划器", - "icon": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1", - "action_node_types_id": 3, - "yaml": "", - "sort_no": 0, - "use_count": 0, - "inputs": [{ - "id": 8, - "name": "cron", - "input_type": "input", - "description": "示例:\r\n- cron: '20 8 * * *'", - "is_required": true, - "value": "- corn: '0 10 * * *'" - }], - "x": 586, - "y": 165.328125, - "label": "on-schedule", - "img": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "labelCfg": { - "style": { - "fill": "transparent", - "fontSize": 0, - "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)", - "overflow": "hidden", - "x": -20, - "y": 0, - "textAlign": "left", - "textBaseline": "middle" - } - }, - "style": { - "active": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10 - }, - "selected": { - "fill": "rgb(255, 255, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 4, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10, - "text-shape": { - "fontWeight": 500 - } - }, - "highlight": { - "fill": "rgb(223, 234, 255)", - "stroke": "#4572d9", - "lineWidth": 2, - "text-shape": { - "fontWeight": 500 - } - }, - "inactive": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(191, 213, 255)", - "lineWidth": 1 - }, - "disable": { - "fill": "rgb(250, 250, 250)", - "stroke": "rgb(224, 224, 224)", - "lineWidth": 1 - }, - "nodeSelected": { - "fill": "red", - "shadowColor": "red", - "stroke": "red", - "text-shape": { - "fill": "red", - "stroke": "red" - } - }, + "nodes": [ + { + "position": { + "x": 290, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, "fill": "#fff", - "stroke": "transparent", - "cursor": "pointer", - "radius": 10, - "overflow": "hidden", - "lineWidth": 0.5, - "shadowColor": "rgba(75,84,137,0.05)", - "shadowBlur": 12 - }, - "cron": "- corn: '0 10 * * *'", - "depth": 0 - }, { - "id": "actions/setup-node@v3-257f29d", - "name": "node", - "full_name": "actions/setup-node@v3", - "description": "", - "icon": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6", - "action_node_types_id": 1, - "yaml": "", - "sort_no": 0, - "use_count": 0, - "inputs": [{ - "id": 2, - "name": "node-version", - "input_type": "select", - "is_required": false, - "value": 55 - }], - "x": 608, - "y": 357.328125, - "label": "node", - "img": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6", - "isCluster": false, - "type": "rect-node", - "size": [110, 36], - "labelCfg": { - "style": { - "fill": "transparent", - "fontSize": 0, - "boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)", - "overflow": "hidden", - "x": -20, - "y": 0, - "textAlign": "left", - "textBaseline": "middle" - } - }, - "style": { - "active": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10 - }, - "selected": { - "fill": "rgb(255, 255, 255)", - "stroke": "rgb(95, 149, 255)", - "lineWidth": 4, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10, - "text-shape": { - "fontWeight": 500 - } - }, - "highlight": { - "fill": "rgb(223, 234, 255)", - "stroke": "#4572d9", - "lineWidth": 2, - "text-shape": { - "fontWeight": 500 - } - }, - "inactive": { - "fill": "rgb(247, 250, 255)", - "stroke": "rgb(191, 213, 255)", - "lineWidth": 1 - }, - "disable": { - "fill": "rgb(250, 250, 250)", - "stroke": "rgb(224, 224, 224)", - "lineWidth": 1 - }, - "nodeSelected": { - "fill": "red", - "shadowColor": "red", - "stroke": "red", - "text-shape": { - "fill": "red", - "stroke": "red" - } - }, + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, "fill": "#fff", - "stroke": "transparent", - "cursor": "pointer", - "radius": 10, - "overflow": "hidden", - "lineWidth": 0.5, - "shadowColor": "rgba(75,84,137,0.05)", - "shadowBlur": 12 - }, - "depth": 0, - "node-version": 55 - }], - "edges": [{ - "source": "on-schedule-2fcf505", - "target": "actions/setup-node@v3-257f29d", - "style": { - "active": { - "stroke": "rgb(95, 149, 255)", - "lineWidth": 1 - }, - "selected": { - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "shadowColor": "rgb(95, 149, 255)", - "shadowBlur": 10, - "text-shape": { - "fontWeight": 500 - } - }, - "highlight": { - "stroke": "rgb(95, 149, 255)", - "lineWidth": 2, - "text-shape": { - "fontWeight": 500 - } - }, - "inactive": { - "stroke": "rgb(234, 234, 234)", - "lineWidth": 1 - }, - "disable": { - "stroke": "rgb(245, 245, 245)", - "lineWidth": 1 - }, - "endArrow": { - "path": "M 6,0 L 9,-1.5 L 9,1.5 Z", - "d": 4.5, - "fill": "#CDD0DC" - }, - "cursor": "pointer", - "lineWidth": 1, - "opacity": 1, - "stroke": "#CDD0DC", - "radius": 1 - }, - "nodeStateStyle": { - "hover": { - "opacity": 1, - "stroke": "#8fe8ff" - } - }, - "labelCfg": { - "autoRotate": true, - "style": { - "fontSize": 10, - "fill": "#FFF" - } - }, - "id": "edge-0.96904321945951241716516719464", - "startPoint": { - "x": 586, - "y": 183.578125, - "anchorIndex": 1 - }, - "endPoint": { - "x": 608, - "y": 339.078125, - "anchorIndex": 0 - }, - "sourceAnchor": 1, - "targetAnchor": 0, - "type": "cubic-vertical", - "curveOffset": [0, 0], - "curvePosition": [0.5, 0.5], - "minCurveOffset": [0, 0] - }], - "combos": [] + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "on-push-b2c871f-left", + "group": "left" + }, + { + "id": "on-push-b2c871f-right", + "group": "right" + }, + { + "id": "on-push-b2c871f-top", + "group": "top" + }, + { + "id": "on-push-b2c871f-bottom", + "group": "bottom" + } + ] + }, + "id": "on-push-b2c871f", + "data": { + "id": 11, + "label": "代码push事件启动", + "name": "on-push", + "full_name": "on-push", + "description": "GitLink仓库push事件", + "icon": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c", + "action_node_types_id": 3, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "start", + "is_mutil_link": true, + "link_type": "job", + "inputs": [ + { + "id": 6, + "name": "branches", + "input_type": "input", + "description": "分支名称,多个分支英文逗号隔开,如'master,dev'", + "is_required": true + }, + { + "id": 7, + "name": "paths-ignore", + "input_type": "input", + "description": "忽略文件,多个文件英文逗号隔开,如'**.md,**.yaml'", + "is_required": false + } + ], + "x": 673, + "y": 495, + "img": "http://172.20.32.201:4000/api/attachments/c2f255e7-f359-4085-b5ce-1f05850ad74c" + }, + "zIndex": 1, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "job-ed9ed25-left", + "group": "left" + }, + { + "id": "job-ed9ed25-right", + "group": "right" + }, + { + "id": "job-ed9ed25-top", + "group": "top" + }, + { + "id": "job-ed9ed25-bottom", + "group": "bottom" + } + ] + }, + "id": "job-ed9ed25", + "data": { + "id": 29, + "label": "任务", + "name": "job", + "full_name": "", + "description": "允许并行多个任务", + "icon": "", + "action_node_types_id": 7, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "job", + "is_mutil_link": true, + "link_type": "job,step", + "inputs": [], + "x": 1093, + "y": 513, + "img": "" + }, + "zIndex": 2, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1090, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "job-3359fd2c-left", + "group": "left" + }, + { + "id": "job-3359fd2c-right", + "group": "right" + }, + { + "id": "job-3359fd2c-top", + "group": "top" + }, + { + "id": "job-3359fd2c-bottom", + "group": "bottom" + } + ] + }, + "id": "job-3359fd2c", + "data": { + "id": 29, + "label": "任务", + "name": "job", + "full_name": "", + "description": "允许并行多个任务", + "icon": "", + "action_node_types_id": 7, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "job", + "is_mutil_link": true, + "link_type": "job,step", + "inputs": [], + "x": 1493, + "y": 540, + "img": "" + }, + "zIndex": 3, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 380 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-79d5ba5d-left", + "group": "left" + }, + { + "id": "shell-79d5ba5d-right", + "group": "right" + }, + { + "id": "shell-79d5ba5d-top", + "group": "top" + }, + { + "id": "shell-79d5ba5d-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-79d5ba5d", + "data": { + "id": "shell-79d5ba5d", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 111" + } + ], + "x": 1190, + "y": 662, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 111" + }, + "zIndex": 5, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1470, + "y": 190 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "job-7760b89e-left", + "group": "left" + }, + { + "id": "job-7760b89e-right", + "group": "right" + }, + { + "id": "job-7760b89e-top", + "group": "top" + }, + { + "id": "job-7760b89e-bottom", + "group": "bottom" + } + ] + }, + "id": "job-7760b89e", + "data": { + "id": 29, + "label": "任务", + "name": "job", + "full_name": "", + "description": "允许并行多个任务", + "icon": "", + "action_node_types_id": 7, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "job", + "is_mutil_link": true, + "link_type": "job,step", + "inputs": [], + "x": 1909, + "y": 552, + "img": "" + }, + "zIndex": 4, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1090, + "y": 370 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-dd97c50-left", + "group": "left" + }, + { + "id": "shell-dd97c50-right", + "group": "right" + }, + { + "id": "shell-dd97c50-top", + "group": "top" + }, + { + "id": "shell-dd97c50-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-dd97c50", + "data": { + "id": "shell-dd97c50", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 444" + } + ], + "x": 1572, + "y": 725, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 444" + }, + "zIndex": 7, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 560 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-799aadee-left", + "group": "left" + }, + { + "id": "shell-799aadee-right", + "group": "right" + }, + { + "id": "shell-799aadee-top", + "group": "top" + }, + { + "id": "shell-799aadee-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-799aadee", + "data": { + "id": "shell-799aadee", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 222" + } + ], + "x": 1190, + "y": 922, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 222" + }, + "zIndex": 6, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1470, + "y": 370 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-1766a765-left", + "group": "left" + }, + { + "id": "shell-1766a765-right", + "group": "right" + }, + { + "id": "shell-1766a765-top", + "group": "top" + }, + { + "id": "shell-1766a765-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-1766a765", + "data": { + "id": "shell-1766a765", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 666" + } + ], + "x": 1986, + "y": 702, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 666" + }, + "zIndex": 9, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 1090, + "y": 550 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-4e09400-left", + "group": "left" + }, + { + "id": "shell-4e09400-right", + "group": "right" + }, + { + "id": "shell-4e09400-top", + "group": "top" + }, + { + "id": "shell-4e09400-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-4e09400", + "data": { + "id": "shell-4e09400", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 555" + } + ], + "x": 1577, + "y": 904, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 555" + }, + "zIndex": 8, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + }, + { + "position": { + "x": 680, + "y": 760 + }, + "size": { + "width": 212, + "height": 48 + }, + "view": "react-shape-view", + "shape": "data-processing-dag-node", + "ports": { + "groups": { + "top": { + "position": { + "name": "top", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "bottom": { + "position": { + "name": "bottom", + "args": { + "dx": 0 + } + }, + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "left": { + "position": "left", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + }, + "right": { + "position": "right", + "attrs": { + "circle": { + "r": 4, + "magnet": true, + "strokeWidth": 1, + "fill": "#fff", + "stroke": "#85A5FF" + } + } + } + }, + "items": [ + { + "id": "shell-5cec9ec-left", + "group": "left" + }, + { + "id": "shell-5cec9ec-right", + "group": "right" + }, + { + "id": "shell-5cec9ec-top", + "group": "top" + }, + { + "id": "shell-5cec9ec-bottom", + "group": "bottom" + } + ] + }, + "id": "shell-5cec9ec", + "data": { + "id": "shell-5cec9ec", + "label": "运行Shell脚本", + "name": "shell", + "full_name": "shell", + "description": "", + "icon": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "action_node_types_id": 4, + "yaml": "", + "sort_no": 0, + "use_count": 0, + "node_type": "step", + "is_mutil_link": false, + "link_type": "step", + "inputs": [ + { + "id": 3, + "name": "run", + "input_type": "input", + "is_required": false, + "value": "echo 333" + } + ], + "x": 1189, + "y": 1082, + "img": "http://172.20.32.201:4000/api/attachments/1d739f94-4e5e-41b8-be7b-13482a099c76", + "run": "echo 333" + }, + "zIndex": 10, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "x": "100%", + "y": 0 + } + } + ] + } + } + ], + "edges": [ + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "9cd9fab0-875a-4ddc-9d32-06fb5abcd986", + "zIndex": -1, + "source": { + "cell": "on-push-b2c871f", + "port": "on-push-b2c871f-right" + }, + "target": { + "cell": "job-ed9ed25", + "port": "job-ed9ed25-left" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "32fee66b-377e-49a6-9f5c-b6a7cb78b4f0", + "zIndex": -1, + "source": { + "cell": "job-ed9ed25", + "port": "job-ed9ed25-right" + }, + "target": { + "cell": "job-3359fd2c", + "port": "job-3359fd2c-left" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "84b37c54-b347-4ecb-8e7d-f338bb83c503", + "zIndex": -1, + "source": { + "cell": "job-3359fd2c", + "port": "job-3359fd2c-right" + }, + "target": { + "cell": "job-7760b89e", + "port": "job-7760b89e-left" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "1703563e-2233-4d23-89ec-ed61f4243791", + "zIndex": -1, + "source": { + "cell": "job-ed9ed25", + "port": "job-ed9ed25-bottom" + }, + "target": { + "cell": "shell-79d5ba5d", + "port": "shell-79d5ba5d-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "0be52bf9-8be4-43a9-aaca-1632eaf450ce", + "zIndex": -1, + "source": { + "cell": "shell-79d5ba5d", + "port": "shell-79d5ba5d-bottom" + }, + "target": { + "cell": "shell-799aadee", + "port": "shell-799aadee-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "5b9800bd-5486-4b30-9142-49e6c5a2f78b", + "zIndex": -1, + "source": { + "cell": "job-3359fd2c", + "port": "job-3359fd2c-bottom" + }, + "target": { + "cell": "shell-dd97c50", + "port": "shell-dd97c50-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "0b01ccf2-0ac9-48d5-a5d1-34a4ccc3f1f7", + "zIndex": -1, + "source": { + "cell": "shell-dd97c50", + "port": "shell-dd97c50-bottom" + }, + "target": { + "cell": "shell-4e09400", + "port": "shell-4e09400-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "c10ada7b-ada5-4970-b05d-ea31b97c1408", + "zIndex": -1, + "source": { + "cell": "job-7760b89e", + "port": "job-7760b89e-bottom" + }, + "target": { + "cell": "shell-1766a765", + "port": "shell-1766a765-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + }, + { + "shape": "data-processing-curve", + "inherit": "edge", + "connector": { + "name": "rounded", + "args": { + "radius": 10 + } + }, + "router": { + "name": "manhattan" + }, + "attrs": { + "line": { + "strokeDasharray": "0" + } + }, + "id": "78909862-8e2a-4750-8b5c-c621a7c327ba", + "zIndex": -1, + "source": { + "cell": "shell-799aadee", + "port": "shell-799aadee-bottom" + }, + "target": { + "cell": "shell-5cec9ec", + "port": "shell-5cec9ec-top" + }, + "tools": { + "items": [ + { + "name": "button-remove", + "args": { + "distance": -40 + } + } + ] + } + } + ] } end + end diff --git a/app/models/action/node.rb b/app/models/action/node.rb index 290d302bd..8d2620d06 100644 --- a/app/models/action/node.rb +++ b/app/models/action/node.rb @@ -17,13 +17,17 @@ # created_at :datetime not null # updated_at :datetime not null # label :string(255) +# node_type :string(255) +# is_mutil_link :boolean +# link_type :string(255) # # Indexes # -# index_action_nodes_on_action_node_types_id (action_node_types_id) -# index_action_nodes_on_user_id (user_id) +# by_name (name) +# index_action_nodes_on_action_types_id (action_node_types_id) +# index_action_nodes_on_user_id (user_id) # -# node_type 0: 触发器 1: 任务作业, 2: 步骤 + class Action::Node < ApplicationRecord self.table_name = 'action_nodes' default_scope { order(sort_no: :asc) } @@ -34,7 +38,7 @@ class Action::Node < ApplicationRecord belongs_to :user, optional: true - attr_accessor :cust_name, :run_values, :input_values, :next_step_nodes + attr_accessor :cust_name, :run_values, :input_values, :sub_nodes validates :name, presence: { message: "不能为空" } validates :full_name, length: { maximum: 200, too_long: "不能超过200个字符" } diff --git a/app/views/api/v1/projects/pipelines/_jobs.yaml.erb b/app/views/api/v1/projects/pipelines/_jobs.yaml.erb new file mode 100644 index 000000000..4f54cdc0a --- /dev/null +++ b/app/views/api/v1/projects/pipelines/_jobs.yaml.erb @@ -0,0 +1,29 @@ +jobs: +<%@job_nodes.each_with_index do |job,index| %> + job<%=index + 1 %>: + name: "<%=job.label || job.name %>" + # 运行环境,这里就是上面定义的多个 os + runs-on: 'ubuntu-latest' + <% if index >0 %> + needs: job<%=index %> + <% end %> + steps: + <%job.sub_nodes.each do |node| %> + - name: <%=node.label || node.name %> + <% if node.name !="shell" %> + uses: <%=node.full_name %> + <% end %> + <%if node.input_values.present? %> + with: + <% node.input_values.each_key do |key| %> + <%=key %>: '<%=node.input_values[key] %>' + <%end %> + <%end %> + <%if node.run_values.present? %> + <% node.run_values.each_key do |key| %> + <%=key %>: | + <%=node.run_values[key] %> + <%end %> + <%end %> + <% end %> +<%end %> \ No newline at end of file diff --git a/app/views/api/v1/projects/pipelines/_test_job.yaml.erb b/app/views/api/v1/projects/pipelines/_test_job.yaml.erb new file mode 100644 index 000000000..f9b905e9e --- /dev/null +++ b/app/views/api/v1/projects/pipelines/_test_job.yaml.erb @@ -0,0 +1,51 @@ +# steps: + # 将job的工作目录指向$GITHUB_WORSPACES checkout@v2比较旧不推荐使用 + - name: Checkout codes + uses: actions/checkout@v3 + - name: Install Java and Maven + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + # 设置jdk环境 + - name: download latest temurin JDK + id: download_latest_jdk + env: + HTTPS_PROXY: http://172.20.32.253:3128 + HTTP_PROXY: http://172.20.32.253:3128 + #run: curl -o https://testgitea2.trustie.net/xxq250/licensee-identify-api-sss/raw/branch/master/openlogic-openjdk-11.0.22+7-linux-x64.tar.gz + run: wget -O $RUNNER_TEMP/java_package.tar.gz "http://172.20.32.202:10082/xxq250/licensee-identify-api-sss/raw/branch/master/OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz" + - uses: actions/setup-java@v4 + with: + distribution: 'jdkfile' + jdkFile: ${{ runner.temp }}/java_package.tar.gz + java-version: '11.0.0' + architecture: x64 + mvn-toolchain-vendor: 'Oracle' + # 设置maven 仓库缓存 避免每次构建时都重新下载依赖 + - name: Cache local Maven repository + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + - name: Test java version + run: java -version + - name: Set up Maven + uses: stCarolas/setup-maven@v5 + with: + maven-version: 3.8.2 + - name: Setup Maven mirrors + uses: s4u/maven-settings-action@v3.0.0 + with: + mirrors: '[{"id": "alimaven", "name": "aliyun maven", "mirrorOf": "central", "url": "http://172.20.32.181:30005/repository/aliyun-maven/"}]' + - name: env show + run: env + - name: cat maven-settings.xml + run: cat /root/.m2/settings.xml + - name: Test with Maven + run: mvn clean test -B -U + env: + https_proxy: http://172.20.32.253:3128 + http_proxy: http://172.20.32.253:3128 diff --git a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb index cbe7a8333..aa170b071 100644 --- a/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb +++ b/app/views/api/v1/projects/pipelines/build_pipeline.yaml.erb @@ -1,7 +1,4 @@ -# action name -name: <%=@pipeline_name %> - -# 什么时候触发这个workflow +name: "<%=@pipeline_name %>" on: <%@on_nodes.each do |node| %> <%if node.name.to_s.include?("on-push") %> @@ -39,16 +36,18 @@ on: <% end %> jobs: - job1: - # 运行环境 +<%@job_nodes.each_with_index do |job,index| %> + job<%=index %>: + name: "<%=job.label || job.name %>" + # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' steps: - <%@steps_nodes.each do |node| %> + <%job.sub_nodes.each do |node| %> - name: <%=node.label || node.name %> - <% if node.name !="shell" %> + <% if node.name !="shell" %> uses: <%=node.full_name %> - <% end %> - <%if node.input_values.present? %> + <% end %> + <%if node.input_values.present? %> with: <% node.input_values.each_key do |key| %> <%=key %>: '<%=node.input_values[key] %>' @@ -56,7 +55,9 @@ jobs: <%end %> <%if node.run_values.present? %> <% node.run_values.each_key do |key| %> - <%=key %>: '<%=node.run_values[key] %>' + <%=key %>: | + <%=node.run_values[key] %> <%end %> <%end %> <% end %> +<%end %> diff --git a/app/views/api/v1/projects/pipelines/test.yaml.erb b/app/views/api/v1/projects/pipelines/test.yaml.erb index 3ec890230..0411ba6cd 100644 --- a/app/views/api/v1/projects/pipelines/test.yaml.erb +++ b/app/views/api/v1/projects/pipelines/test.yaml.erb @@ -1,22 +1,20 @@ -name: Check dist<%= @name %> - # action name name: Test with Junit # 什么时候触发这个workflow on: # push 到master分之的时候 这里可以指定多个 - #push: - # branches: - # - master -# paths-ignore: -# - '**.md' + push: + branches: + - master + paths-ignore: + - '**.md' # pull request 到master分之的时候, 这里可以指定多个 - #pull_request: - # branches: - # - master -# paths-ignore: -# - '**.md' + pull_request: + branches: + - master + paths-ignore: + - '**.md' # 定时调度执行 schedule: - cron: '26 10,11 * * *' @@ -35,16 +33,15 @@ jobs: os: [ 'ubuntu-latest' ] # 运行环境,这里就是上面定义的多个 os runs-on: 'ubuntu-latest' - steps: # 将job的工作目录指向$GITHUB_WORSPACES checkout@v2比较旧不推荐使用 - name: Checkout codes uses: actions/checkout@v3 - #- name: Install Java and Maven - # uses: actions/setup-java@v3 - # with: - # java-version: '11' - # distribution: 'temurin' + - name: Install Java and Maven + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' # 设置jdk环境 - name: download latest temurin JDK id: download_latest_jdk diff --git a/app/views/api/v1/projects/pipelines/test_yaml.yaml.erb b/app/views/api/v1/projects/pipelines/test_yaml.yaml.erb new file mode 100644 index 000000000..14ac79a4d --- /dev/null +++ b/app/views/api/v1/projects/pipelines/test_yaml.yaml.erb @@ -0,0 +1,26 @@ +# action name +name: Test with Junit + +# 什么时候触发这个workflow +on: + # push 到master分之的时候 这里可以指定多个 + push: + branches: + - master + paths-ignore: + - '**.md' + # pull request 到master分之的时候, 这里可以指定多个 + pull_request: + branches: + - master + paths-ignore: + - '**.md' + # 定时调度执行 + schedule: + - cron: '26 10,11 * * *' +env: + https_proxy: http://172.20.32.253:3128 + http_proxy: http://172.20.32.253:3128 + +# 一个workflow可以由多个job组成,多个job可以并行运行 +<%= render(partial: 'api/v1/projects/pipelines/jobs') %> diff --git a/config/routes/api.rb b/config/routes/api.rb index 3f75a3b22..a6fe42d86 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -166,6 +166,7 @@ defaults format: :json do resources :pipelines do post :build_yaml, on: :collection post :save_yaml, on: :collection + get :test_yaml, on: :collection end resources :pulls, module: 'pulls' do member do