This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrust.groovy
137 lines (125 loc) · 3.57 KB
/
rust.groovy
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
import com.concur.*;
workflowDoc = '''
title: Rust
overview: Steps for building and testing with Golang.
additional_resources:
- name: Rust
url: https://www.rust-lang.org/en-US/
- name: Cargo
url: http://doc.crates.io
- name: Docker Images
url: https://hub.docker.com/_/rust/
tools:
- type: String
name: buildImage
required: true
description: Docker image containg tools for Rust.
- type: List
name: additionalArgs
description: A list of additional flags to send to the cargo command.
- type: List
name: components
description: Additional rustup components to install.
- type: String
name: command
description: Which cargo command to execute.
default: build
full_example: |
pipelines:
tools:
branches:
patterns:
feature: .+
branches:
feature:
steps:
- rust:
- cargo:
command: build
'''
concurPipeline = new Commands()
concurUtil = new Util()
/*
description: Create a Pull Request in GitHub.
parameters:
- type: String
name: buildImage
description: Docker image containg tools for Rust.
- type: List
name: additionalArgs
description: A list of additional flags to send to the cargo command.
- type: List
name: components
description: Additional rustup components to install.
- type: String
name: command
description: Which cargo command to execute.
default: build
example: |
branches:
feature:
steps:
- rust:
# Simple
- cargo:
# Advanced
- cargo:
command: build
title: Fix for issue {{ branch_name }}.
*/
public cargo(Map yml, Map args) {
String buildImage = args?.buildImage ?: yml.tools?.rust?.buildImage
List additionalArgs = args?.additionalArgs ?: yml.tools?.rust?.additionalArgs
List rustupComponents = args?.components ?: yml.tools?.rust?.components
String command = args?.command ?: yml.tools?.rust?.command ?: "build"
assert buildImage : "Workflows :: rust :: cargo :: [buildImage] is needed in [tools.rust] or as a parameter to the test step."
buildImage = concurUtil.mustacheReplaceAll(buildImage)
String cargoCommand = "cargo ${command}"
/**
* Define additional args as any of the following
* ----------------------------------------------
* rust:
* - cargo:
* additionalArgs:
* - "--force"
* - "--skip-test"
* - "-v"
* ----------------------------------------------
*/
if (additionalArgs) {
cargoCommand = "$cargoCommand ${additionalArgs.join(' ')}"
}
concurPipeline.debugPrint("Workflows :: rust :: cargo", [
'buildImage' : buildImage,
'command' : command,
'additionalArgs' : additionalArgs,
'cargoCommand' : cargoCommand
])
// -u 0:0 runs as root, -v mounts the current workspace to your gopath
docker.image(buildImage).inside("-v \"${pwd()}/.cargo:/usr/local/cargo/registry/:rw\"") {
/*
RustUp is a tool for managing Rust and its components
*/
if (rustupComponents) {
rustupComponents.each {
sh "rustup component add $it"
}
}
sh cargoCommand
}
}
/*
* Set the name of the stage dynamically.
*/
public getStageName(Map yml, Map args, String stepName) {
switch(stepName) {
case 'cargo':
def cargoCommand = args?.command ?: "build"
return "rust: cargo: ${cargoCommand}"
}
}
public tests(Map yml, Map args) {
String workflowName = 'rust'
println "Testing $workflowName"
}
return this;