-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.fsx
193 lines (180 loc) · 6.82 KB
/
demo.fsx
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#r "nuget: Fun.Result, 0.2.1"
#r "nuget: Spectre.Console, 0.46.0"
#r "Fun.Build/bin/Debug/netstandard2.0/Fun.Build.dll"
open Fun.Result
open Fun.Build
open Fun.Build.Github
// You can create a stage and reuse it in any pipeline or nested stages
let demo1 =
stage "Ways to run something" {
timeout 30 // You can set default timeout for the stage
timeoutForStep 30 // You can set default timeout for step under the stage
envVars [ "envKey", "envValue" ] // You can add or override environment variables
// Use cmd, so we can encrypt sensitive argument for formatable string
runSensitive ($"""dotnet {"--version"}""")
run (fun ctx -> ctx.RunSensitiveCommand $"""dotnet {"--version"}""")
// You can run command directly with a string
run "dotnet --version"
run (fun ctx -> "dotnet --version")
run (fun ctx -> async { return "dotnet --version" })
// You use use the RunCommand to run multiple command according to your logics
run (fun ctx -> asyncResult {
do! ctx.RunCommand "dotnet --version"
do! ctx.RunCommand "dotnet --version"
})
// You can run async functions
run (Async.Sleep 1000)
run (fun _ -> Async.Sleep 1000)
run (fun _ -> async { return 0 }) // return an exit code to indicate if it successful
// You can also run sync functions
run (fun ctx -> ())
run (fun ctx -> 0) // return an exit code to indicate if it successful
// You can also use the low level api
step (fun ctx _ -> async { return Ok() })
}
pipeline "Fun.Build" {
description "This is a demo pipeline for docs"
timeout 30 // You can set overall timeout for the pipeline
timeoutForStep 10 // You can set default timeout for every step in every stage
timeoutForStage 10 // You can set default timeout for every stage
envVars [ "envKey", "envValue" ] // You can add or override environment variables
cmdArgs [ "arg1"; "arg2" ] // You can reset the command args
workingDir __SOURCE_DIRECTORY__
// You can also override the accept exit code for success. By default 0 is for success.
// But if your external program is using other code you can add it here.
acceptExitCodes [ 0; 2 ]
// By default steps will not add prefix for printing information.
// You can also set the flag on each stage.
noPrefixForStep false
// Below is a custom extended operation
collapseGithubActionLogs
demo1
stage "Demo2" {
// whenAny, whenNot, whenAll. They can also be composed.
whenBranch "master" // Check current branch is master
whenAny {
envVar "envKey" // Check has environment variable
envVar "envKey" "envValue" // Check has environment variable value
cmdArg "cmdKey" "" "Check has cmd arg"
cmdArg "cmdKey" "cmdValue" "Check has cmd arg value which should be behind the cmdKey"
whenNot { cmdArg "--not-demo" }
when' (stage "Check" { run (fun ctx -> Ok()) }) // Check result of a stage, useful for dynamic checks
}
shuffleExecuteSequence // It can shuffle the sequence of steps executing sequence
run "dotnet --version"
run "dotnet --list-sdks"
}
// You can also nest stages, the stage will be treated as a single stage for parent stage.
stage "Demo3" {
stage "Platform" {
workingDir @"C:\Users"
whenWindows
run "powershell pwd"
}
stage "Demo nested" {
shuffleExecuteSequence
echo "cool nested"
stage "Deeper" { echo "cooller" }
stage "inactive" {
whenCmdArg "arg3"
echo "Got here!"
}
}
stage "Exit code" {
acceptExitCodes [ 123 ]
run (fun _ -> 123)
}
// You can open link in browser every easily
openBrowser "https://github.com/slaveOftime/Fun.Build"
run (fun ctx -> ctx.OpenBrowser "https://github.com/slaveOftime/Fun.Build")
}
stage "FailIfIgnored" {
failIfIgnored // When set this, the stage cannot be ignored
whenCmdArg "arg2"
echo "Got here!"
}
stage "inactive" {
whenCmdArg "arg3"
echo "Got here!"
}
post [ // Post stages are optional. It will run even other normal stages are failed.
stage "Post stage" {
echo "You are finished 😂"
echo (fun ctx -> sprintf "You are finished here: %A" (ctx.GetWorkingDir()))
run (fun _ -> async {
return 0 // do something
})
}
]
// You can have multiple pipelines, sometimes you only want to run it only if the command specified the pipeline name.
// If this is set to false, then it will always run if you do not specify which pipeline to run. By default it is true.
// To specify you can do this: dotnet fsi build.fsx -p Fun.Build
runIfOnlySpecified false
// You can also run it directly
// runImmediate
}
pipeline "pipeline-verify-demo" {
description "Verify before pipeline start running"
// Will throw exception when verification failed.
// You can define your own logic
verify (fun ctx -> false)
// To keep consistence, the condition is similar like when building stage
whenCmdArg "verify"
whenAny {
cmdArg "v1"
branch "master"
}
runIfOnlySpecified
}
pipeline "cmd-info" {
description "Check cmd info build style"
whenCmd {
fullName "-w" "--watch"
// Description can also support multiple lines
description "watch cool stuff \n dasd asdad \n asdasd as123"
}
whenCmd {
name "--debug"
description "optional argument"
optional
}
whenEnv {
name "PRODUCTION"
description "optional argument"
optional
}
whenGithubAction
stage "condition demo" {
noStdRedirectForStep
failIfIgnored
// You can use whenCmd CE for more complex situation.
whenCmd {
shortName "-w"
// Description can also support multiple lines
description "watch cool stuff \n dasd asdad \n asdasd as123"
}
whenCmd {
shortName "-r"
description "run cool stuff"
acceptValues [ "v1"; "v2" ]
}
whenCmd {
longName "--build"
description "build your dream"
acceptValues [ "v1"; "v2" ]
}
whenAny {
cmdArg "--foo"
envVar "--bar"
platformLinux
platformWindows
branch "master"
}
echo "here we are"
run "dotnet --list-sdks"
}
runIfOnlySpecified
}
// This will collect command line help information for you
// You can run: dotnet fsi demo.fsx -- -h
tryPrintPipelineCommandHelp ()