Skip to content
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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Adding hardware test #351

wants to merge 14 commits into from

Conversation

Ellerbach
Copy link
Member

@Ellerbach Ellerbach commented Oct 14, 2024

Description

Adding hardware test

Motivation and Context

  • Adding hardware test
  • Run real hardware tests on real devices!

How Has This Been Tested?

With this PR pipeline

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

Summary by CodeRabbit

  • New Features

    • Introduced a structured Azure DevOps pipeline configuration for automated builds based on specific branch activities and pull requests.
    • Added functionality for monitoring pipeline run status and capturing results.
    • Implemented a new parameter appComponents for enhanced configurability of testing components.
  • Bug Fixes

    • Improved error handling during pipeline execution and monitoring.
  • Refactor

    • Restructured pipeline steps into a staged approach for better organization.

Copy link

coderabbitai bot commented Oct 14, 2024

Walkthrough

The pull request introduces significant modifications to two YAML configuration files for Azure DevOps pipelines. In azure-pipelines.yml, the trigger settings have been changed to prevent automatic execution, and a new parameter appComponents has been added. The pipeline structure is enhanced with a Build stage and job, including artifact publishing and a loop for testing components. The azure-bootstrap.yml file implements a triggering mechanism for builds based on specific branch activities and pull requests, featuring two jobs for initiating and monitoring pipeline runs, with error handling integrated throughout.

Changes

File Change Summary
azure-pipelines.yml - Trigger configuration updated to trigger: none and pr: none.
- Added parameter appComponents (object type).
- Introduced Build stage and Build job.
- Added PublishPipelineArtifact@1 task.
- Implemented loop for appComponents to invoke device-test.yml template.
azure-bootstrap.yml - Configured triggers for specific branches and excluded certain paths.
- Implemented two jobs: one for triggering builds and another for monitoring pipeline status.
- Added error handling and monitoring logic for pipeline runs.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AzureDevOps
    participant Pipeline

    User->>AzureDevOps: Push changes to branch
    AzureDevOps->>Pipeline: Trigger pipeline based on branch activity
    Pipeline->>Pipeline: Validate environment variables
    Pipeline->>Pipeline: Trigger build and test
    Pipeline->>Pipeline: Monitor pipeline run status
    Pipeline->>User: Notify success or failure
Loading

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
azure-pipelines.yml (4)

51-57: LGTM! Consider fixing indentation.

The introduction of the appComponents parameter enhances the pipeline's flexibility by allowing dynamic specification of test components. This is a good practice for maintaining a configurable and reusable pipeline.

Consider adjusting the indentation to align with YAML best practices:

parameters:
  - name: appComponents
    displayName: List of capabilities to run the tests on
    type: object
    default:
      - XIAO_ESP32C3
      - ESP32_C3_REV3
🧰 Tools
🪛 yamllint

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


59-90: LGTM! Consider addressing minor formatting issues.

The introduction of a staged approach with a dedicated Build stage improves the pipeline's structure and readability. The use of templates for class library build and error reporting promotes code reuse and maintainability. The new artifact publishing task ensures that build outputs are available for subsequent stages or manual download, which is a good practice.

Consider addressing the following minor formatting issues:

  1. Adjust indentation for improved readability and YAML best practices.
  2. Remove trailing spaces on lines 80 and 96.

Example of corrected indentation:

stages:
  - stage: Build
    displayName: 'Build'
    jobs:
      - job: Build
        displayName: 'Build job'
        pool:
          vmImage: 'windows-latest'
        steps:
          - template: azure-pipelines-templates/class-lib-build.yml@templates
            parameters:
              sonarCloudProject: 'nanoframework_lib-nanoFramework.Json'
              runUnitTests: true
              unitTestRunsettings: '$(System.DefaultWorkingDirectory)\.runsettings'

          - template: azure-pipelines-templates/discord-webhook-task.yml@templates
            parameters:
              status: 'failure'
              webhookUrl: '$(DiscordWebhook)'
              message: ''

          - task: PublishPipelineArtifact@1
            displayName: Publish Pipeline Artifact copy
            inputs:
              path: '$(System.DefaultWorkingDirectory)'
              artifactName: 'Artifacts'
🧰 Tools
🪛 yamllint

[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


92-97: LGTM! Consider parameterizing unitTestRunsettings and fix formatting.

The introduction of a loop to iterate over appComponents is an excellent approach. It allows for dynamic execution of device tests, increasing flexibility and reducing redundancy in the pipeline configuration.

Consider parameterizing the unitTestRunsettings to allow for more flexibility:

parameters:
  - name: unitTestRunsettings
    type: string
    default: 'nanoFramework.Json.Test\nano.runsettings,nanoFramework.Json.Test\bin\Debug\nanoFramework.System.Text.dll'

# ... (in the loop section)
- ${{ each appComponents in parameters.appComponents }}:
  - template: azure-pipelines-templates/device-test.yml
    parameters:
      appComponents: ${{ appComponents }}
      unitTestRunsettings: ${{ parameters.unitTestRunsettings }}

Also, please address the following formatting issues:

  1. Remove trailing spaces on lines 92 and 96.
  2. Adjust indentation for improved readability.
  3. Ensure there's a new line character at the end of the file.
🧰 Tools
🪛 yamllint

[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)


Line range hint 1-97: Great improvements overall! Consider a final formatting pass.

The restructuring of this Azure Pipelines configuration file is a significant improvement. The introduction of parameters, stages, and the loop for device testing enhances the pipeline's flexibility, reusability, and maintainability. The consistent use of templates for reusable components is also a great practice.

To further improve the file's readability and adhere to YAML best practices, consider doing a final formatting pass to address the following:

  1. Ensure consistent indentation throughout the file (2 spaces for each level is standard for YAML).
  2. Remove all trailing spaces.
  3. Add a new line character at the end of the file.

You can use a YAML linter or your IDE's formatting tools to help with these adjustments.

🧰 Tools
🪛 yamllint

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 68ad890 and b605096.

📒 Files selected for processing (1)
  • azure-pipelines.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
azure-pipelines.yml

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
azure-pipelines.yml (5)

51-57: Approve the addition of parameters with a minor indentation fix.

The introduction of the appComponents parameter enhances the pipeline's flexibility, allowing for dynamic specification of test components. This aligns well with the PR objective of adding hardware testing capabilities.

To address the YAML linting warning, please adjust the indentation of the parameters section. Apply this diff:

-parameters:
-- name: appComponents
-  displayName: List of capabilities to run the tests on
-  type: object
-  default:
-    - XIAO_ESP32C3
-    - ESP32_C3_REV3
+parameters:
+  - name: appComponents
+    displayName: List of capabilities to run the tests on
+    type: object
+    default:
+      - XIAO_ESP32C3
+      - ESP32_C3_REV3
🧰 Tools
🪛 yamllint

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


59-67: Approve the introduction of stages with a minor indentation fix.

The addition of the stages section with a Build stage and job improves the pipeline's structure and readability. This change aligns with best practices for Azure Pipelines and ensures a consistent build environment.

To address the YAML linting warning, please adjust the indentation of the stages section. Apply this diff:

-stages:
-- stage: Build
-  displayName: 'Build'
-  jobs:
-  - job: Build
-    displayName: 'Build job'
-    pool:
-      # default is the following VM Image
-      vmImage: 'windows-latest'
+stages:
+  - stage: Build
+    displayName: 'Build'
+    jobs:
+      - job: Build
+        displayName: 'Build job'
+        pool:
+          # default is the following VM Image
+          vmImage: 'windows-latest'
🧰 Tools
🪛 yamllint

[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


70-85: Approve the reorganized build steps with a minor formatting fix.

The reorganization of build steps within the Build job, using templates for class library build and error reporting, promotes code reuse and maintainability. The inclusion of SonarCloud analysis and unit tests enhances code quality checks, which is commendable.

To address the YAML linting error, please remove the trailing space from line 80. Apply this diff:

-    - template: azure-pipelines-templates/discord-webhook-task.yml@templates  
+    - template: azure-pipelines-templates/discord-webhook-task.yml@templates
🧰 Tools
🪛 yamllint

[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


86-90: Approve artifact publishing with optimization suggestion.

The addition of the artifact publishing step is crucial for sharing build outputs between jobs or for archiving purposes. This is a good practice in CI/CD pipelines.

Consider optimizing the artifact content by specifying only the necessary files or directories instead of publishing the entire working directory. This can reduce storage usage and improve artifact download times. For example:

- task: PublishPipelineArtifact@1
  displayName: Publish Pipeline Artifact
  inputs:
    path: '$(Build.ArtifactStagingDirectory)'
    artifact: 'BuildOutputs'

Ensure to copy only the required files to the $(Build.ArtifactStagingDirectory) before this step.


92-97: Approve the device testing loop with minor formatting fixes.

The addition of the loop to iterate over appComponents and execute device tests using the device-test.yml template is an excellent implementation. This dynamic approach aligns perfectly with the PR objective of adding hardware testing capabilities.

To address the YAML linting errors, please apply the following fixes:

  1. Remove trailing spaces from lines 92 and 96.
  2. Add a newline at the end of the file.

Apply this diff:

-- ${{ each appComponents in parameters.appComponents }}:   
+- ${{ each appComponents in parameters.appComponents }}:
   - template: azure-pipelines-templates/device-test.yml@templates
     parameters:
       appComponents: ${{ appComponents }}
-      unitTestRunsettings: 
+      unitTestRunsettings:
         - 'nanoFramework.Json.Test/nano.runsettings,nanoFramework.Json.Test/bin/Release/nanoFramework.System.Text.dll'
+
🧰 Tools
🪛 yamllint

[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 20ed2bc and bd361a0.

⛔ Files ignored due to path filters (1)
  • nanoFramework.Json.Benchmark/nanoFramework.Json.Benchmark.nfproj is excluded by none and included by none
📒 Files selected for processing (1)
  • azure-pipelines.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
azure-pipelines.yml

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
azure-pipelines.yml (1)

Line range hint 1-97: Overall approval with minor formatting suggestions.

The changes to the azure-pipelines.yml file significantly enhance the pipeline's flexibility and align well with the PR objective of adding hardware testing capabilities. The introduction of parameters, stages, and the device testing loop are particularly noteworthy improvements.

Key points:

  1. The appComponents parameter allows for dynamic specification of test components.
  2. The introduction of stages improves the pipeline's structure and readability.
  3. The device testing loop enables efficient execution of tests across multiple hardware components.

While the overall structure and content of the changes are excellent, please address the minor formatting issues mentioned in the previous comments to ensure consistency and adhere to YAML best practices.

🧰 Tools
🪛 yamllint

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (5)
azure-pipelines.yml (5)

51-57: Approve the addition of appComponents parameter with a minor formatting suggestion.

The introduction of the appComponents parameter aligns well with the PR objective of adding hardware testing capabilities. It provides a flexible way to specify the components for testing.

However, there's a minor formatting issue:

Please adjust the indentation of the parameter section. Each item should be indented with 2 spaces. Here's the corrected version:

parameters:
  - name: appComponents
    displayName: List of capabilities to run the tests on
    type: object
    default:
      - XIAO_ESP32C3
      - ESP32_C3_REV3
🧰 Tools
🪛 yamllint

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


59-68: Approve the introduction of stages with a minor formatting suggestion.

The addition of the stages section with a Build stage and job improves the pipeline's structure and readability. This change aligns with best practices for Azure Pipelines.

However, there's a minor formatting issue:

Please adjust the indentation of the stages section. Each level should be indented with 2 spaces. Here's the corrected version:

stages:
  - stage: Build
    displayName: 'Build'
    jobs:
      - job: Build
        displayName: 'Build job'
        pool:
          # default is the following VM Image
          vmImage: 'windows-latest'
🧰 Tools
🪛 yamllint

[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


70-85: Approve the build steps with a minor formatting suggestion.

The encapsulation of build steps within the Build job and the use of templates for class library build and error reporting are excellent practices. The addition of runUnitTests and unitTestRunsettings parameters aligns well with the PR objective of adding testing capabilities.

However, there's a minor formatting issue:

Please remove the trailing space from line 80. Here's the corrected line:

    - template: azure-pipelines-templates/discord-webhook-task.yml@templates
🧰 Tools
🪛 yamllint

[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


92-97: Approve the addition of device testing with minor formatting suggestions.

The introduction of the device testing section using a loop to iterate over appComponents is an excellent implementation of the PR objective. This approach allows for flexible and extensible testing of multiple hardware components.

However, there are a few minor formatting issues:

  1. Remove the trailing spaces from lines 92 and 96.
  2. Add a newline character at the end of the file.

Here's the corrected version:

- ${{ 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'

Note the added newline at the end.

🧰 Tools
🪛 yamllint

[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)


Line range hint 1-97: Overall approval with offer for further assistance.

The changes to azure-pipelines.yml are well-structured and align perfectly with the PR objective of adding hardware testing capabilities. The introduction of the appComponents parameter, the restructuring into stages, and the addition of device testing demonstrate a significant improvement in the pipeline's flexibility and functionality.

While there were some minor formatting issues (mainly indentation and trailing spaces), these do not detract from the overall quality of the changes. The use of templates, the addition of artifact publishing, and the loop for device testing are all excellent practices that enhance the pipeline's maintainability and extensibility.

If you'd like any assistance in further optimizing the pipeline or addressing the minor formatting issues, please let me know. I'd be happy to help generate a script to automatically fix the formatting or suggest any additional enhancements to the pipeline structure.

🧰 Tools
🪛 yamllint

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between bd361a0 and 5af0ba5.

📒 Files selected for processing (1)
  • azure-pipelines.yml (1 hunks)
🧰 Additional context used
🪛 yamllint
azure-pipelines.yml

[warning] 52-52: wrong indentation: expected 2 but found 0

(indentation)


[warning] 60-60: wrong indentation: expected 2 but found 0

(indentation)


[warning] 63-63: wrong indentation: expected 4 but found 2

(indentation)


[warning] 72-72: wrong indentation: expected 6 but found 4

(indentation)


[error] 80-80: trailing spaces

(trailing-spaces)


[error] 92-92: trailing spaces

(trailing-spaces)


[warning] 93-93: wrong indentation: expected 4 but found 2

(indentation)


[error] 96-96: trailing spaces

(trailing-spaces)


[error] 97-97: no new line character at the end of file

(new-line-at-end-of-file)

🔇 Additional comments (1)
azure-pipelines.yml (1)

86-90: Approve the addition of artifact publishing step.

The inclusion of the PublishPipelineArtifact@1 task is a valuable addition to the pipeline. This step ensures that build artifacts are preserved and can be used in subsequent pipeline stages or for debugging purposes, which aligns with CI/CD best practices.

@Ellerbach
Copy link
Member Author

Copy link

sonarcloud bot commented Oct 16, 2024

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

🧹 Outside diff range and nitpick comments (3)
azure-pipelines.yml (1)

40-71: Fix YAML indentation and enhance path handling.

The build configuration is solid, but there are some improvements needed:

  1. Fix indentation according to YAML best practices
  2. Consider using path variables for cross-platform compatibility (PR comment about Linux paths)

Apply these fixes:

 stages:
   - stage: Build
     displayName: 'Build'
     jobs:
       - job: Build
         displayName: 'Build job'
         steps:
           - template: azure-pipelines-templates/class-lib-build.yml@templates
             parameters:
               sonarCloudProject: 'nanoframework_lib-nanoFramework.Json'
               runUnitTests: true
-              unitTestRunsettings: '$(System.DefaultWorkingDirectory)\.runsettings'
+              unitTestRunsettings: '$(System.DefaultWorkingDirectory)/.runsettings'
🧰 Tools
🪛 yamllint

[warning] 41-41: wrong indentation: expected 2 but found 0

(indentation)


[warning] 44-44: wrong indentation: expected 4 but found 2

(indentation)


[warning] 53-53: wrong indentation: expected 6 but found 4

(indentation)


[error] 61-61: trailing spaces

(trailing-spaces)

azure-bootstrap.yml (2)

4-26: Consider adding explicit path includes for hardware test files.

While the path exclusions are well-defined, consider adding explicit path includes to ensure the pipeline only triggers for changes related to hardware testing. This would prevent unnecessary builds for unrelated changes.

 trigger:
   branches:
     include:
       - main
       - develop
       - release-*
   paths:
+    include:
+      - tests/hardware/**
+      - device-tests/**
     exclude:

1-169: Fix YAML formatting issues.

There are several formatting inconsistencies in the file:

  1. Incorrect indentation at lines 28, 40
  2. Trailing spaces at lines 37, 39, 98, 128, 131
  3. Missing newline at end of file

Please run yamllint locally and fix these formatting issues.

🧰 Tools
🪛 yamllint

[warning] 28-28: wrong indentation: expected 2 but found 0

(indentation)


[error] 37-37: trailing spaces

(trailing-spaces)


[error] 39-39: trailing spaces

(trailing-spaces)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)


[error] 98-98: trailing spaces

(trailing-spaces)


[error] 128-128: trailing spaces

(trailing-spaces)


[error] 131-131: trailing spaces

(trailing-spaces)


[error] 169-169: no new line character at the end of file

(new-line-at-end-of-file)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2aa239a and 727367b.

⛔ Files ignored due to path filters (1)
  • nanoFramework.Json.Test/nano.runsettings is excluded by none and included by none
📒 Files selected for processing (2)
  • azure-bootstrap.yml (1 hunks)
  • azure-pipelines.yml (2 hunks)
🧰 Additional context used
🪛 yamllint
azure-bootstrap.yml

[warning] 28-28: wrong indentation: expected 2 but found 0

(indentation)


[error] 37-37: trailing spaces

(trailing-spaces)


[error] 39-39: trailing spaces

(trailing-spaces)


[warning] 40-40: wrong indentation: expected 4 but found 2

(indentation)


[error] 98-98: trailing spaces

(trailing-spaces)


[error] 128-128: trailing spaces

(trailing-spaces)


[error] 131-131: trailing spaces

(trailing-spaces)


[error] 169-169: no new line character at the end of file

(new-line-at-end-of-file)

azure-pipelines.yml

[warning] 34-34: wrong indentation: expected 2 but found 0

(indentation)


[warning] 41-41: wrong indentation: expected 2 but found 0

(indentation)


[warning] 44-44: wrong indentation: expected 4 but found 2

(indentation)


[warning] 53-53: wrong indentation: expected 6 but found 4

(indentation)


[error] 61-61: trailing spaces

(trailing-spaces)


[error] 73-73: trailing spaces

(trailing-spaces)


[warning] 74-74: wrong indentation: expected 4 but found 2

(indentation)


[error] 77-77: trailing spaces

(trailing-spaces)


[error] 78-78: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +73 to +78
- ${{ 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'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve cross-platform compatibility and test validation.

The device test configuration needs improvements to address the path handling issues mentioned in PR comments:

  1. Use forward slashes for cross-platform compatibility
  2. Add test file existence validation
  3. Remove trailing spaces

Apply these changes:

 - ${{ 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'
+        unitTestRunsettings:
+          - 'nanoFramework.Json.Test/nano.runsettings,nanoFramework.Json.Test/bin/$(buildConfiguration)/NFUnitTest.dll'

Add a validation step before running tests:

- task: PowerShell@2
  displayName: 'Validate Test Files'
  inputs:
    targetType: 'inline'
    script: |
      $testPath = "nanoFramework.Json.Test/bin/$(buildConfiguration)/NFUnitTest.dll"
      if (-not (Test-Path $testPath)) {
        Write-Error "Test assembly not found: $testPath"
        exit 1
      }
🧰 Tools
🪛 yamllint

[error] 73-73: trailing spaces

(trailing-spaces)


[warning] 74-74: wrong indentation: expected 4 but found 2

(indentation)


[error] 77-77: trailing spaces

(trailing-spaces)


[error] 78-78: no new line character at the end of file

(new-line-at-end-of-file)

Comment on lines +33 to +39
parameters:
- name: appComponents
displayName: List of capabilities to run the tests on
type: object
default:
- none

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Improve parameter configuration and validation.

The default value of none for appComponents could lead to scenarios where no tests are executed, which aligns with the reported issue in PR comments about catching missing tests.

Consider these improvements:

  1. Add parameter validation to prevent empty or 'none' values
  2. Enhance the parameter description to list valid component options
  3. Add a minimum number of required components

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

Committable suggestion was skipped due to low confidence.

🧰 Tools
🪛 yamllint

[warning] 34-34: wrong indentation: expected 2 but found 0

(indentation)

Comment on lines +4 to +7
# The Pipeline is going to be called by the GitHub action.
# Manual trigger is always possible.
trigger: none
pr: none
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

⚠️ Missing GitHub Action integration for Azure Pipelines

The pipeline is configured to be triggered by a GitHub Action, but no workflow files currently integrate with Azure Pipelines. This could lead to the pipeline never being triggered as intended.

  • .github/workflows/pr-checks.yml only runs package checks
  • .github/workflows/update-dependencies.yml only handles dependency updates
  • No workflow file contains integration with azure-pipelines.yml
🔗 Analysis chain

LGTM! Verify GitHub Action integration.

The trigger configuration is correct for external invocation. The comments clearly explain the pipeline's execution context.

Let's verify the GitHub Action integration:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for GitHub Action workflow files that trigger this pipeline
fd -e yml -e yaml . .github/workflows --exec grep -l "azure-pipelines"

Length of output: 70


Script:

#!/bin/bash
# Let's try a broader search for GitHub workflow files and Azure Pipeline references
# First, find all workflow files
echo "=== GitHub Workflow Files ==="
fd -e yml -e yaml . .github/workflows

# Then, search for any Azure Pipeline related patterns in yaml/yml files
echo -e "\n=== Files referencing Azure Pipelines ==="
rg -l -g "*.{yml,yaml}" -i "azure.?pipeline|azure.?devops" .

Length of output: 388


Script:

#!/bin/bash
# Let's check the content of pr-checks.yml to see if it triggers azure-pipelines
echo "=== Content of pr-checks.yml ==="
cat .github/workflows/pr-checks.yml

# Also check update-dependencies.yml just to be thorough
echo -e "\n=== Content of update-dependencies.yml ==="
cat .github/workflows/update-dependencies.yml

Length of output: 1366

Comment on lines +33 to +38
variables:
AZURE_DEVOPS_ORG: nanoFramework
AZURE_DEVOPS_PROJECT: nanoFramework.Json
AZURE_DEVOPS_PIPELINE_ID: 59
AZURE_POOL_NAME: TestStream

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider parameterizing pipeline configuration.

The hardcoded values for organization, project, pipeline ID, and pool name reduce reusability. Consider moving these to pipeline variables or parameters that can be configured at runtime.

parameters:
  - name: azureDevOpsOrg
    type: string
    default: nanoFramework
  - name: azureDevOpsProject
    type: string
    default: nanoFramework.Json
  - name: pipelineId
    type: number
    default: 59
  - name: poolName
    type: string
    default: TestStream

variables:
  AZURE_DEVOPS_ORG: ${{ parameters.azureDevOpsOrg }}
  AZURE_DEVOPS_PROJECT: ${{ parameters.azureDevOpsProject }}
  AZURE_DEVOPS_PIPELINE_ID: ${{ parameters.pipelineId }}
  AZURE_POOL_NAME: ${{ parameters.poolName }}
🧰 Tools
🪛 yamllint

[error] 37-37: trailing spaces

(trailing-spaces)

branch="${BUILD_SOURCEBRANCH}"

# Encode the PAT
patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Security: Avoid base64 encoding PAT in script.

Base64 encoding the PAT in the script makes it vulnerable to logging. Consider using Azure DevOps predefined variables or a secure task for authentication.

-      patEncoded=$(echo -n ":${AZURE_DEVOPS_PAT}" | base64)
+      # Use System.AccessToken or az devops login

Committable suggestion was skipped due to low confidence.

Comment on lines +65 to +86
# 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add timeout and retry mechanism for API calls.

The API calls to fetch pool information lack timeout and retry mechanisms, which could lead to pipeline hangs or failures due to transient issues.

+      # Function to retry API calls
+      function retry_curl() {
+        local retries=3
+        local wait=5
+        local timeout=30
+        local i=0
+        while [ $i -lt $retries ]; do
+          response=$(curl -s -w "%{http_code}" --connect-timeout $timeout "${headers[@]}" "$@")
+          if [ $? -eq 0 ]; then
+            return 0
+          fi
+          i=$((i+1))
+          [ $i -lt $retries ] && sleep $wait
+        done
+        return 1
+      }
+
       # 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")
+      if ! retry_curl -X GET "$url"; then
+        echo "Failed to get pool ID after retries"
+        exit 1
+      fi

Committable suggestion was skipped due to low confidence.

Comment on lines +132 to +165
- 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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve pipeline monitoring robustness.

The current monitoring implementation has several potential issues:

  1. No maximum wait time could lead to infinite execution
  2. Fixed sleep interval isn't optimal for long-running tests
  3. Basic error handling could miss edge cases
+      # Configuration
+      max_wait_time=7200  # 2 hours
+      start_time=$SECONDS
+      initial_sleep=30
+      max_sleep=300  # 5 minutes
+      current_sleep=$initial_sleep
+
       # Loop to monitor the pipeline run status
       while true; do
+          # Check if maximum wait time exceeded
+          elapsed=$(( SECONDS - start_time ))
+          if [ $elapsed -gt $max_wait_time ]; then
+              echo "Pipeline monitoring timed out after $(( max_wait_time / 60 )) minutes"
+              exit 1
+          fi
+
           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
+              elif [ "$state" == "canceling" ] || [ "$state" == "canceled" ]; then
+                  echo "Pipeline was canceled"
+                  exit 1
               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
+          # Exponential backoff with maximum limit
+          sleep $current_sleep
+          current_sleep=$(( current_sleep * 2 ))
+          [ $current_sleep -gt $max_sleep ] && current_sleep=$max_sleep
       done
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- 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
- 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"
# Configuration
max_wait_time=7200 # 2 hours
start_time=$SECONDS
initial_sleep=30
max_sleep=300 # 5 minutes
current_sleep=$initial_sleep
# Loop to monitor the pipeline run status
while true; do
# Check if maximum wait time exceeded
elapsed=$(( SECONDS - start_time ))
if [ $elapsed -gt $max_wait_time ]; then
echo "Pipeline monitoring timed out after $(( max_wait_time / 60 )) minutes"
exit 1
fi
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
elif [ "$state" == "canceling" ] || [ "$state" == "canceled" ]; then
echo "Pipeline was canceled"
exit 1
fi
else
echo "Failed to get pipeline run status. HTTP Status Code: $http_code"
echo "Response: $content"
exit 1
fi
# Exponential backoff with maximum limit
sleep $current_sleep
current_sleep=$(( current_sleep * 2 ))
[ $current_sleep -gt $max_sleep ] && current_sleep=$max_sleep
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants