-
-
Notifications
You must be signed in to change notification settings - Fork 20
Adding hardware test #351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding hardware test #351
Changes from 14 commits
b605096
20ed2bc
d0c1ab2
00f9e1d
679e46b
bd361a0
5af0ba5
a982d02
1962af4
b9ab875
2aa239a
9041b38
7e7818d
727367b
c97f0ab
3342e62
9236f0e
bf05b05
6c5ce4e
60c22e9
7595bb9
06a9889
a43ad17
23e0e89
1958f63
d439b3a
d86d023
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
# Copyright (c) .NET Foundation and Contributors | ||
# See LICENSE file in the project root for full license information. | ||
|
||
trigger: | ||
branches: | ||
include: | ||
- main | ||
- develop | ||
- release-* | ||
paths: | ||
exclude: | ||
- .github_changelog_generator | ||
- .gitignore | ||
- CHANGELOG.md | ||
- CODE_OF_CONDUCT.md | ||
- LICENSE.md | ||
- README.md | ||
- NuGet.Config | ||
- assets/* | ||
- config/* | ||
- .github/* | ||
|
||
# PR always trigger build | ||
pr: | ||
autoCancel: true | ||
|
||
jobs: | ||
- job: Trigger | ||
displayName: Trigger Azure Dev Ops build and test pipeline | ||
pool: | ||
vmImage: 'ubuntu-latest' | ||
|
||
variables: | ||
AZURE_DEVOPS_ORG: nanoFramework | ||
AZURE_DEVOPS_PROJECT: nanoFramework.Json | ||
AZURE_DEVOPS_PIPELINE_ID: 59 | ||
AZURE_POOL_NAME: TestStream | ||
|
||
Ellerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
steps: | ||
- script: | | ||
# Validate required environment variables | ||
for var in AZURE_DEVOPS_ORG AZURE_DEVOPS_PROJECT AZURE_DEVOPS_PIPELINE_ID AZURE_POOL_NAME; do | ||
if [ -z "${!var}" ]; then | ||
echo "Error: Required environment variable $var is not set" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# Define the Azure DevOps organization, project, and pipeline | ||
organization="${AZURE_DEVOPS_ORG}" | ||
project="${AZURE_DEVOPS_PROJECT}" | ||
pipelineId="${AZURE_DEVOPS_PIPELINE_ID}" | ||
poolName="${AZURE_POOL_NAME}" | ||
branch="${BUILD_SOURCEBRANCH}" | ||
|
||
# Encode the PAT | ||
patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64) | ||
Ellerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# Define the headers | ||
headers=( | ||
-H "Authorization: Basic $patEncoded" | ||
-H "Content-Type: application/json" | ||
) | ||
|
||
# Get the pool ID | ||
url="https://dev.azure.com/${organization}/_apis/distributedtask/pools?poolName=${poolName}&api-version=7.1" | ||
AZP_POOL_AGENTS=$(curl -s "${headers[@]}" -X GET "$url") | ||
poolId=$(echo "$AZP_POOL_AGENTS" | jq -r '.value[0].id') | ||
|
||
echo "Pool ID: $poolId" | ||
|
||
# Define the URL to get all agents in the pool | ||
url="https://dev.azure.com/${organization}/_apis/distributedtask/pools/${poolId}/agents?includeCapabilities=true&api-version=7.1" | ||
|
||
response=$(curl -s -w "%{http_code}" "${headers[@]}" -X GET "$url") | ||
http_code=${response: -3} | ||
content=${response::-3} | ||
|
||
if [ $http_code -eq 200 ]; then | ||
# Extract all userCapabilities names for online and enabled agents as a unique list | ||
capabilityNames=$(echo "$content" | jq -r '[.value[] | select(.status == "online" and .enabled == true) | .userCapabilities | keys] | unique | flatten | join("\n- ")') | ||
else | ||
echo "Failed to retrieve agent capabilities. HTTP Status Code: $http_code" | ||
echo "Response: \"$content\"" | ||
exit 1 | ||
fi | ||
Ellerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
echo "Unique userCapabilities names: \"$capabilityNames\"" | ||
|
||
# Prepare the parameters | ||
parametersJson=$(jq -n --arg appComponents "- $capabilityNames" '{templateParameters: {appComponents: $appComponents}}') | ||
|
||
echo "Parameters: \"$parametersJson\"" | ||
echo "Branch for PR: \"$branch\"" | ||
|
||
# Define the request body | ||
bodyJson=$(jq -n --argjson parameters "$parametersJson" --arg branch "$branch" '{ | ||
resources: { | ||
repositories: | ||
{ | ||
self: { | ||
refName: $branch | ||
} | ||
} | ||
}, | ||
templateParameters: $parameters.templateParameters | ||
}') | ||
|
||
echo "Request body: \"$bodyJson\"" | ||
|
||
# Define the URL | ||
url="https://dev.azure.com/${organization}/${project}/_apis/pipelines/${pipelineId}/runs?api-version=7.1" | ||
|
||
# Trigger the pipeline | ||
response=$(curl -s -w "%{http_code}" "${headers[@]}" -X POST -d "$bodyJson" "$url") | ||
http_code=${response: -3} | ||
content=${response::-3} | ||
|
||
if [ $http_code -eq 200 ]; then | ||
run_id=$(echo "$content" | jq -r '.id') | ||
echo "Pipeline triggered successfully. Run ID: $run_id" | ||
echo "##vso[task.setvariable variable=run_id]$run_id" | ||
else | ||
echo "Failed to trigger pipeline. HTTP Status Code: $http_code" | ||
echo "Response: $content" | ||
exit 1 | ||
fi | ||
displayName: 'Trigger Azure DevOps Pipeline' | ||
env: | ||
BUILD_SOURCEBRANCH: $(Build.SourceBranch) | ||
AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) | ||
|
||
- script: | | ||
echo "Pipeline to monitor Run ID: $(run_id)" | ||
# Define the URL to get the pipeline run status | ||
url="https://dev.azure.com/${AZURE_DEVOPS_ORG}/${AZURE_DEVOPS_PROJECT}/_apis/pipelines/${AZURE_DEVOPS_PIPELINE_ID}/runs/$(run_id)?api-version=7.1" | ||
|
||
# Loop to monitor the pipeline run status | ||
while true; do | ||
response=$(curl -s -w "%{http_code}" -H "Authorization: Basic $(echo -n ":${AZURE_DEVOPS_PAT}" | base64)" -X GET "$url") | ||
http_code=${response: -3} | ||
content=${response::-3} | ||
|
||
if [ $http_code -eq 200 ]; then | ||
state=$(echo "$content" | jq -r '.state') | ||
result=$(echo "$content" | jq -r '.result') | ||
|
||
echo "Pipeline run state: $state" | ||
|
||
if [ "$state" == "completed" ]; then | ||
echo "Pipeline run completed with result: $result" | ||
if [ "$result" == "succeeded" ]; then | ||
exit 0 | ||
else | ||
exit 1 | ||
fi | ||
fi | ||
else | ||
echo "Failed to get pipeline run status. HTTP Status Code: $http_code" | ||
echo "Response: $content" | ||
exit 1 | ||
fi | ||
|
||
# Wait for a while before checking again | ||
sleep 30 | ||
done | ||
Ellerbach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
displayName: 'Monitoring Azure DevOps pipeline' | ||
env: | ||
run_id: $(run_id) | ||
AZURE_DEVOPS_PAT: $(AZURE_DEVOPS_PAT) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,10 @@ | ||
# Copyright (c) .NET Foundation and Contributors | ||
# See LICENSE file in the project root for full license information. | ||
|
||
trigger: | ||
branches: | ||
include: | ||
- main | ||
- develop | ||
- release-* | ||
paths: | ||
exclude: | ||
- .github_changelog_generator | ||
- .gitignore | ||
- CHANGELOG.md | ||
- CODE_OF_CONDUCT.md | ||
- LICENSE.md | ||
- README.md | ||
- NuGet.Config | ||
- assets/* | ||
- config/* | ||
- .github/* | ||
|
||
# PR always trigger build | ||
pr: | ||
autoCancel: true | ||
# The Pipeline is going to be called by the GitHub action. | ||
# Manual trigger is always possible. | ||
trigger: none | ||
pr: none | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# add nf-tools repo to resources (for Azure Pipelines templates) | ||
resources: | ||
|
@@ -48,20 +30,49 @@ variables: | |
- name: nugetPackageName | ||
value: 'nanoFramework.Json' | ||
|
||
steps: | ||
parameters: | ||
- name: appComponents | ||
displayName: List of capabilities to run the tests on | ||
type: object | ||
default: | ||
- none | ||
|
||
Comment on lines
+33
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve parameter configuration and validation. The default value of Consider these improvements:
Here's a suggested improvement: parameters:
- name: appComponents
displayName: List of capabilities to run the tests on
type: object
+ # List of valid components: [component1, component2, ...]
+ # At least one component must be specified
default:
- - none
+ - required: true
+ - allowed:
+ - component1
+ - component2
🧰 Tools🪛 yamllint[warning] 34-34: wrong indentation: expected 2 but found 0 (indentation) |
||
stages: | ||
- stage: Build | ||
displayName: 'Build' | ||
jobs: | ||
- job: Build | ||
displayName: 'Build job' | ||
pool: | ||
# default is the following VM Image | ||
vmImage: 'windows-latest' | ||
steps: | ||
|
||
# step from template @ nf-tools repo | ||
# all build, update and publish steps | ||
- template: azure-pipelines-templates/class-lib-build.yml@templates | ||
parameters: | ||
sonarCloudProject: 'nanoframework_lib-nanoFramework.Json' | ||
runUnitTests: true | ||
unitTestRunsettings: '$(System.DefaultWorkingDirectory)\.runsettings' | ||
|
||
# step from template @ nf-tools repo | ||
# report error | ||
- template: azure-pipelines-templates/discord-webhook-task.yml@templates | ||
parameters: | ||
status: 'failure' | ||
webhookUrl: '$(DiscordWebhook)' | ||
message: '' | ||
|
||
# step from template @ nf-tools repo | ||
# all build, update and publish steps | ||
- template: azure-pipelines-templates/class-lib-build.yml@templates | ||
parameters: | ||
sonarCloudProject: 'nanoframework_lib-nanoFramework.Json' | ||
runUnitTests: true | ||
unitTestRunsettings: '$(System.DefaultWorkingDirectory)\.runsettings' | ||
- task: PublishPipelineArtifact@1 | ||
displayName: Publish Pipeline Artifact copy | ||
inputs: | ||
path: '$(System.DefaultWorkingDirectory)' | ||
artifactName: 'Artifacts' | ||
|
||
# step from template @ nf-tools repo | ||
# report error | ||
- template: azure-pipelines-templates/discord-webhook-task.yml@templates | ||
parameters: | ||
status: 'failure' | ||
webhookUrl: '$(DiscordWebhook)' | ||
message: '' | ||
- ${{ each appComponents in parameters.appComponents }}: | ||
- template: azure-pipelines-templates/device-test.yml@templates | ||
parameters: | ||
appComponents: ${{ appComponents }} | ||
unitTestRunsettings: | ||
- 'nanoFramework.Json.Test/nano.runsettings,nanoFramework.Json.Test/bin/Release/NFUnitTest.dll' | ||
josesimoes marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.