Giter Site home page Giter Site logo

iamsandeepkmr / searchsourcecode Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 8 KB

This is a simple project in PowerShell which can scan through your source code to search for a specific text and shows you the results (in console and a text file)

PowerShell 100.00%

searchsourcecode's Introduction

Source code search during build phase

This is a simple project in PowerShell which can scan through your source code to search for a specific text in each source file and shows you the results (in console and a text file report).

The biggest use case for me was to know if my project source code is IPR (Intellectual Property Rights) compliant. IPR header is a proprietary text put on top of each source file in a project (as a comment). If any of the source code file is not IPR compliant, the build pipeline should fail and tell the list of files which are not IPR compliant.

This PowerShell script can be used as a task in DevOps pipeline to scan through the source code and search for a specific text (IPR header in my case) in each file. You can use this script for other similar requirements.

Input to the script

  • Source Code Path: Your source code path to scan. Eg. "D:\SourceCode\ProjectABC". Use "$(System.DefaultWorkingDirectory)" if running the script as a task in DevOps pipeline
  • Text: Text (part or full) to search for in your source code. Text should be a single line. Eg. "COMPANY XYZ PROPRIETARY. This document and its accompanying elements, contain information which is proprietary and confidential"
  • Files to Include: Extension of source code files to consider for scanning. Eg. "*.cs, *.ts, *.html, *.htm"
  • Folders to Exclude: Folders to skip from scanning. Eg. "bin, obj, node_modules, dist"
  • Output File: Path to a file to report the search results. Eg. "D:\SourceCode\ProjectABC\IPRReport.txt". Make use of "$(Build.ArtifactStagingDirectory)" if running the script as a task in DevOps pipeline. Eg. "$(Build.ArtifactStagingDirectory)/IPRReport.txt"

Script

Refer SearchSourceCode.ps1 from the repository

Run the Script

I am going to use this script in my project to find the source code files with missing IPR header.

Use below command to run the script

image

Output

image

This is how the IPR report will look like:

image

Use the Script as a DevOps pipeline task

  • Add a PowerShell task in your pipeline
  • Copy the PowerShell script (Inline). Specify/modify input values
  • Add below code if you want to fail the pipeline in case there are files with missing IPR header
    if($fileCountWithoutText -gt 0) {
        exit 1
    }
    

image

  • Don't forget to publish the report as a pipeline artifact in a separate task (or as a part of an existing publish artifacts task in your pipeline)

  • Run the pipeline

Output

Pipeline task output:

image There are no files with missing IPR header in my source code.

Report in pipeline artifacts:

image

image

searchsourcecode's People

Contributors

iamsandeepkmr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.