-
Notifications
You must be signed in to change notification settings - Fork 0
/
prep.sh
executable file
·361 lines (309 loc) · 9.98 KB
/
prep.sh
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#! /bin/bash
set -x
# ========================================
# take over env vars set by make if they dont exist substitute some default
# note the Publiser=Author (the Publiser needs to exist before you can test the actual extension)
DIR="${DIR:-mytask1}"
Name="${NAME:-test-ado-extension}"
FriendlyName="${FRIENDLYNAME:-Testing a azure devops extension pipeline}"
Description="${DESCRIPTION:-This is a test for a azure devops extension}"
Author="${AUTHOR:-JustAnotherAuthor}"
License="${LICENSE:-MIT}"
Version="${VERSION:-0.1.0}"
# ========================================
# https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?toc=%2Fazure%2Fdevops%2Fmarketplace-extensibility%2Ftoc.json&view=azure-devops
TS_VERSION="4.6.3"
# ========================================
prep_azure_devops()
{
# do we have node installed
node -v
# do we have npm
npm -v
# To have the tsc command available,
# make sure that TypeScript is installed globally
# with npm in your development environment.
sudo npm install "typescript@${TS_VERSION}" -g --save-dev
tsc -v
sudo npm install mocha -g --save-dev
# Node CLI for Azure DevOps
sudo npm install -g tfx-cli
}
init_new_directory()
{
echo node_modules > .gitignore
# https://docs.npmjs.com/cli/v10/commands/npm-init
npm init --yes \
--init-license="${License}" \
--init-author-name="${Author}" \
--init-version="${Version}"
npm install azure-pipelines-task-lib --save
# npm install typed-rest-client --save
npm install @types/node --save-dev
npm install @types/q --save-dev
# Install test tools. We use Mocha as the test driver in this procedure.
npm install sync-request --save-dev
npm install @types/mocha --save-dev
tsc --init --target es6 # must be es6, es2022 does not work with async function
}
init_new_task()
{
# https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?toc=%2Fazure%2Fdevops%2Fmarketplace-extensibility%2Ftoc.json&view=azure-devops#taskjson-components
# Property Description
# id A unique GUID for your task.
# name Name with no spaces.
# friendlyName Descriptive name (spaces allowed).
# description Detailed description of what your task does.
# author Short string describing the entity developing the build or release task, for example: "Microsoft Corporation."
# instanceNameFormat How the task displays within the build/release step list.
# You can use variable values by using $(variablename).
# groups Describes the logical grouping of task properties in the UI.
# inputs Inputs to be used when your build or release task runs. This task expects an input with the name samplestring.
# execution Execution options for this task, including scripts.
# restrictions Restrictions being applied to the task about GitHub Codespaces commands task can call, and variables task can set.
# We recommend that you specify restriction mode for new tasks.
if [ -f ".uuid" ]
then
UUID=$( cat .uuid )
else
UUID=$( /usr/bin/uuid -v 4 ) # https://guid.one/guid
echo "${UUID}" >.uuid
fi
cat <<! |
{
"$schema": "https://raw.githubusercontent.com/Microsoft/azure-pipelines-task-lib/master/tasks.schema.json",
"id": "${UUID}",
"name": "${Name}",
"friendlyName": "${FriendlyName}",
"description": "${Description}",
"helpMarkDown": "${Name}",
"category": "Azure Pipelines",
"author": "${Author}",
"version": {
"Major": 0,
"Minor": 1,
"Patch": 0
},
"instanceNameFormat": "$(echo ${Name} | sed -e 's/-/ /g')",
"inputs": [
{
"name": "samplestring",
"type": "string",
"label": "Sample String",
"defaultValue": "a sample string",
"required": false,
"helpMarkDown": "A sample string"
}
],
"execution": {
"Node": {
"target": "index.js"
}
}
}
!
jq -r . |
tee task.json
}
init_new_ts_file()
{
cat <<! | tee index.ts
'use strict';
import tl = require('azure-pipelines-task-lib/task');
async function run() {
try {
const inputString: string | undefined = tl.getInput('samplestring', true);
if (inputString == 'bad') {
tl.setResult(tl.TaskResult.Failed, 'Bad input was given');
return;
}
console.log('Hello', inputString);
}
catch (err) {
if (err instanceof Error) {
tl.setResult(tl.TaskResult.Failed, err.message);
}
}
}
run();
!
}
compile_tc2js()
{
# to compile the ts into js do:
tsc
}
test_run()
{
node index.js
}
make_initial_manifest()
{
# https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?toc=%2Fazure%2Fdevops%2Fmarketplace-extensibility%2Ftoc.json&view=azure-devops#files
# Files → Path must point to our build directory
# https://learn.microsoft.com/en-us/azure/devops/extend/develop/add-build-task?toc=%2Fazure%2Fdevops%2Fmarketplace-extensibility%2Ftoc.json&view=azure-devops#contributions # Contributions → Properties → Name must also point to our build directory
# Contributions.id:
# Identifier of the contribution.
# Must be unique within the extension.
# Doesn't need to match the name of the build or release task.
# Typically the build or release task name is in the ID of the contribution.
cat <<! | jq -r . | tee vss-extension.json
{
"manifestVersion": 1,
"id": "${Name}",
"name": "${Author}",
"version": "${Version}",
"publisher": "${Author}",
"public": false,
"description": "${Description}",
"targets": [
{
"id": "Microsoft.VisualStudio.Services"
}
],
"categories": [
"Azure Pipelines"
],
"icons": {
"default": "images/extension-icon.png"
},
"files": [
{
"path": "${DIR}"
}
],
"content": {
"details": {
"path": "overview.md"
}
},
"links": {
"home": {
"uri": "https://www.${Author}.com/"
},
"getstarted": {
"uri": "https://www.${Author}.com/"
},
"learn": {
"uri": "https://www.${Author}.com/"
},
"support": {
"uri": "https://www.${Author}.com/"
},
"repository": {
"uri": "https://github.com/"
},
"issues": {
"uri": "https://github.com/"
}
},
"repository": {
"type": "git",
"uri": "https://github.com/"
},
"tags": [
"${Author}"
],
"contributions": [
{
"id": "custom-build-release-task",
"type": "ms.vss-distributed-task.task",
"targets": [
"ms.vss-distributed-task.tasks"
],
"properties": {
"name": "${DIR}"
}
}
]
}
!
}
make_package_extension()
{
tfx extension create \
--manifest-globs vss-extension.json
}
make_readme()
{
echo "# ${Name}
${FriendlyName}
## Description
${Description}
## Author
${Author}
## License
${License}
## Version
${Version}
" >overview.md
}
main()
{
prep_azure_devops
grep -q '*.vsix' .gitignore || {
echo "*.vsix" >> .gitignore
}
mkdir -p "${DIR}"
pushd "${DIR}"
{
init_new_directory
init_new_task
init_new_ts_file
compile_tc2js
test_run
}
popd
make_readme
# make sure the image exists
mkdir -p images
touch images/extension-icon.png
make_initial_manifest
make_package_extension
# NOTE: dont use `--rev-version`, do it yourself, see below
# An extension or integration's version must be incremented on every update.
# When you're updating an existing extension, either update the version in the manifest or pass the --rev-version command line switch.
# This increments the patch version number of your extension and saves the new version to your manifest.
# You must rev both the task version and extension version for an update to occur.
# Note: `tfx extension create --manifest-globs vss-extension.json --rev-version` only updates the extension version and not the task version.
}
main
exit
# ##[debug]Evaluating condition for step: 'testadoextension'
# ##[debug]Evaluating: SucceededNode()
# ##[debug]Evaluating SucceededNode:
# ##[debug]=> True
# ##[debug]Result: True
# Starting: testadoextension
# ==============================================================================
# Task : Testing a azure devops extension pipeline
# Description : This is a test for a azure devops extension.
# Version : 0.1.0
# Author : JustAnotherAuthor
# Help : test-ado-extension
# ==============================================================================
# ##[debug]Agent running environment resource - Disk: available:20047.00MB out of 74244.00MB, Memory: used 23MB out of 6921MB, CPU: usage 38.77
# ##[debug]Using node path: /home/vsts/agents/3.232.3/externals/node/bin/node
# ##[debug]agent.TempDirectory=/home/vsts/work/_temp
# ##[debug]loading inputs and endpoints
# ##[debug]loading INPUT_SAMPLESTRING
# ##[debug]loading INPUT_RLPORTAL_SERVER
# ##[debug]loading INPUT_RLPORTAL_ORG
# ##[debug]loading INPUT_RLPORTAL_GROUP
# ##[debug]loading INPUT_RL_PACKAGE_URL
# ##[debug]loading INPUT_BUILD_PATH
# ##[debug]loading INPUT_MY_ARTIFACT_TO_SCAN
# ##[debug]loading INPUT_REPORT_PATH
# ##[debug]loading ENDPOINT_AUTH_SYSTEMVSSCONNECTION
# ##[debug]loading ENDPOINT_AUTH_SCHEME_SYSTEMVSSCONNECTION
# ##[debug]loading ENDPOINT_AUTH_PARAMETER_SYSTEMVSSCONNECTION_ACCESSTOKEN
# ##[debug]loading SECRET_SYSTEM_ACCESSTOKEN
# ##[debug]loading SECRET_RLPORTAL_ACCESS_TOKEN
# ##[debug]loaded 13
# ##[debug]Agent.ProxyUrl=undefined
# ##[debug]Agent.CAInfo=undefined
# ##[debug]Agent.ClientCert=undefined
# ##[debug]Agent.SkipCertValidation=undefined
# ##[debug]samplestring=a sample string
# Hello a sample string
# Finishing: testadoextension