-
Notifications
You must be signed in to change notification settings - Fork 66
193 lines (185 loc) · 6.49 KB
/
trigger_ado_int_tests.yml
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
name: Run Azure DevOps Integration Tests
on:
workflow_call:
inputs:
testCentral:
description: Run Central tests
type: boolean
default: true
testADT:
description: Run ADT tests
type: boolean
default: true
testDPS:
description: Run DPS tests
type: boolean
default: true
testHub:
description: Run Hub tests
type: boolean
default: true
testADU:
description: Run ADU tests
type: boolean
default: true
python_versions:
description: "Python versions to test"
type: string
default: >
"{
Python39: { python: '3.9' },
Python310: { python: '3.10' },
Python311: { python: '3.11' },
Python312: { python: '3.12' }
}"
secrets:
ADO_PAT:
required: true
workflow_dispatch:
inputs:
testCentral:
description: Run Central tests
type: boolean
default: true
testADT:
description: Run ADT tests
type: boolean
default: true
testDPS:
description: Run DPS tests
type: boolean
default: true
testHub:
description: Run Hub tests
type: boolean
default: true
testADU:
description: Run ADU tests
type: boolean
default: true
python_versions:
description: "Python versions to test"
required: true
type: string
default: >
"{
Python39: { python: '3.9' },
Python310: { python: '3.10' },
Python311: { python: '3.11' },
Python312: { python: '3.12' }
}"
env:
DEFAULT_TITLE: "Azure DevOps Pipeline"
AZURE_DEVOPS_EXT_PAT: ${{ secrets.ADO_PAT }}
DEFINITION_ID: 147
ORG: azureiotdevxp
PROJECT: aziotcli
jobs:
call-ado-pipeline:
runs-on: ubuntu-latest
name: Run integration tests
outputs:
runId: ${{ steps.start.outputs.runId }}
portalUrl: ${{ steps.start.outputs.portalUrl }}
url: ${{ steps.start.outputs.url }}
steps:
- shell: bash
id: start
name: Trigger the pipeline
run: |-
set -ex
if [ -z "$ORG" ]; then
echo "::error::Organization is required"
exit 1
fi
if [ -z "$PROJECT" ]; then
echo "::error::Project is required"
exit 1
fi
cmdArgs=(--org "https://dev.azure.com/$ORG" --project "$PROJECT" --branch "${{ github.ref }}")
if [ -n "$DEFINITION_ID" ]; then
cmdArgs+=(--id "$DEFINITION_ID")
else
echo "::error::Pipeline definition ID must be provided"
exit 1
fi
python_versions=${{inputs.python_versions}}
python_version_strings=$(echo $python_versions | jq -R .)
cmdArgs+=("--parameters")
cmdArgs+=("pythonVersionsTestingMatrix=$python_version_strings")
cmdArgs+=("testCentral=${{inputs.testCentral}}")
cmdArgs+=("testADT=${{inputs.testADT}}")
cmdArgs+=("testDPS=${{inputs.testDPS}}")
cmdArgs+=("testHub=${{inputs.testHub}}")
cmdArgs+=("testADU=${{inputs.testADU}}")
echo "Running: az pipelines run ${cmdArgs[@]}"
res=$(az pipelines run "${cmdArgs[@]}")
if [ -z "$res" ]; then
echo "::error::Failed to trigger the pipeline"
fi
runId=$(echo $res | jq -r '.id')
portalUrl="https://dev.azure.com/$ORG/$PROJECT/_build/results?buildId=$runId&view=results"
url=$(echo $res | jq -r '.url')
echo "runId=$runId" >> $GITHUB_OUTPUT
echo "portalUrl=$portalUrl" >> $GITHUB_OUTPUT
echo "url=$url" >> $GITHUB_OUTPUT
- name: Summary
id: summary
run: |-
echo "# ${PIPELINE:-$DEFAULT_TITLE} Started" >> $GITHUB_STEP_SUMMARY
echo "## Azure DevOps Pipeline" >> $GITHUB_STEP_SUMMARY
echo "You can follow the progress [here](${{ steps.start.outputs.portalUrl }})" >> $GITHUB_STEP_SUMMARY
wait-for-completion:
runs-on: ubuntu-latest
name: Wait for the pipeline to complete
needs: [call-ado-pipeline]
env:
RUN_ID: ${{ needs.call-ado-pipeline.outputs.runId }}
PORTAL_URL: ${{ needs.call-ado-pipeline.outputs.portalUrl }}
steps:
- name: Wait for the pipeline to complete
run: |
set -e
runId="${{ needs.call-ado-pipeline.outputs.runId }}"
status="none"
result="none"
lastLog=1
while [[ "$status" =~ (inProgress|notStarted|postponed|none) ]]; do
sleep 60
res=$(az pipelines runs show --id "$RUN_ID" --org "https://dev.azure.com/$ORG" --project "$PROJECT")
status=$(echo "$res" | jq -r '.status')
result=$(echo "$res" | jq -r '.result')
done
# if status is not completed, or the result is one of failed, canceled; then fail the job
if [[ "$status" != "completed" || "$result" =~ (failed|canceled) ]]; then
echo "::error::Pipeline did not complete successfully"
echo "# ❌ ${PIPELINE:-$DEFAULT_TITLE} Failed ❌" >> $GITHUB_STEP_SUMMARY
echo "The pipeline did not complete successfully. Please check the logs [here](${PORTAL_URL})" >> $GITHUB_STEP_SUMMARY
exit 1
fi
echo "# ✅ ${PIPELINE:-$DEFAULT_TITLE} Completed ✅" >> $GITHUB_STEP_SUMMARY
echo "The pipeline completed successfully. You can check the logs [here](${PORTAL_URL})" >> $GITHUB_STEP_SUMMARY
CancelPipeline:
runs-on: ubuntu-latest
needs: [call-ado-pipeline, wait-for-completion]
if: cancelled()
env:
RUN_ID: ${{ needs.call-ado-pipeline.outputs.runId }}
RUN_URL: ${{ needs.call-ado-pipeline.outputs.url }}
PORTAL_URL: ${{ needs.call-ado-pipeline.outputs.portalUrl }}
steps:
- name: Cancel the pipeline
run: |
set -ex
if [[ -z "$RUN_ID" ]]; then
echo "No pipeline to cancel"
exit 0
fi
curl \
-X PATCH \
-u ":$AZURE_DEVOPS_EXT_PAT" \
-H "Content-Type: application/json" \
-d '{"status": "cancelling"}' \
"${RUN_URL}?api-version=7.2-preview.7"
echo "# ❌ ${PIPELINE:-$DEFAULT_TITLE} Cancelled ❌" >> $GITHUB_STEP_SUMMARY
echo "The pipeline was cancelled. You can check the logs [here](${PORTAL_URL})" >> $GITHUB_STEP_SUMMARY