microsoft / ps-rule

Validate infrastructure as code (IaC) and DevOps repositories using GitHub Actions.
https://github.com/marketplace/actions/psrule
MIT License
74 stars 13 forks source link

Rule Files Not Found #37

Closed DevAlphaKilo closed 3 years ago

DevAlphaKilo commented 3 years ago

Description of the issue

When using the current release of PSRule my rules are no longer found/detected in the .ps-rule directory nested in my .github directory.

Expected behaviour

*.Rule.ps1 files should be detected.

To Reproduce

Steps to reproduce the issue:

Working

Rule file is detected

    - name: Checkout
      uses: actions/checkout@v2

    - name: Check GitHub Community Rules
      uses: Microsoft/ps-rule@v0.2.0
      with:
        source: .github/.ps-rule/
Not Working

Rule file is NOT detected

    - name: Checkout
      uses: actions/checkout@v2

    - name: Check GitHub Community Rules
      uses: Microsoft/ps-rule@main
      with:
        source: .github/.ps-rule/

Error output

Capture any error messages and or run output.

2020-09-18T16:57:34.2793671Z [info] Using Action: Microsoftps-rule
2020-09-18T16:57:34.2882599Z [info] Using PWD: /github/workspace
2020-09-18T16:57:34.2883150Z [info] Using Path: /github/workspace
2020-09-18T16:57:34.2884218Z [info] Using Source: /github/workspace/.github/.ps-rule/
2020-09-18T16:57:34.2884795Z [info] Using InputType: repository
2020-09-18T16:57:34.2885291Z [info] Using InputPath: /github/workspace
2020-09-18T16:57:34.2886346Z [info] Using OutputFormat: Json
2020-09-18T16:57:34.2887120Z [info] Using OutputPath: ./rule-analysis.txt
2020-09-18T16:57:34.3332291Z 
2020-09-18T16:57:34.3333830Z ---
2020-09-18T16:57:35.0057504Z     ____  _____ ____        __
2020-09-18T16:57:35.0057871Z    / __ \/ ___// __ \__  __/ /__
2020-09-18T16:57:35.0058130Z   / /_/ /\__ \/ /_/ / / / / / _ \
2020-09-18T16:57:35.0071629Z  / ____/___/ / _, _/ /_/ / /  __/
2020-09-18T16:57:35.0071961Z /_/    /____/_/ |_|\__,_/_/\___/
2020-09-18T16:57:35.0072134Z 
2020-09-18T16:57:35.0096588Z Using PSRule v0.20.0
2020-09-18T16:57:35.0096815Z 
2020-09-18T16:57:35.1181542Z ##[warning]Target object '.github/.ps-rule/GitHub.Community.Rule.ps1' has not been processed because no matching rules were found.
2020-09-18T16:57:35.1186964Z 
2020-09-18T16:57:35.1187351Z Rules processed: 0, failed: 0, errored: 0

Action version:

Additional context

This format has previously worked for me on other repositories in the past by targeting main but now I have to explicitly target v0.2.0 to have it work correctly as expected.

BernieWhite commented 3 years ago

@DevAlphaKilo Thanks for reporting the issue.

If you are using the binding.targetType in ps-rule.yaml configuration can you please provide this.

Additionally are you able to provide the -Type or -If filter for you rules in .github/.ps-rule/GitHub.Community.Rule.ps1.


There was a number of changes in PSRule release v0.20.0 that improved repository scanning, however the object type for binding is slightly different. Double checking this now, this could be a gap in the documentation, so I will look to address this.

In a nutshell:

Example here: https://github.com/microsoft/PSRule/blob/main/.ps-rule/OpenSource.Rule.ps1

Hope that helps.

BernieWhite commented 3 years ago

@DevAlphaKilo Added upgrade notes. https://github.com/microsoft/ps-rule/blob/main/docs/upgrade-notes.md

DevAlphaKilo commented 3 years ago

The suggestion about updating the binding.targetType fixed the issue. Thank you!

Steps Followed

  1. Changed target branch to 'main'
  2. Committed change of target branch to verify 'System.IO.DirectoryInfo' binding.targetType still caused reported issue 2.1 Issue did occur as reported
  3. Updated binding.targetType to recommended 'PSRule.Data.RepositoryInfo' in GitHub.Community.Rule.ps1
  4. Commited new binding.targetType 4.1 Issue did not occur as reported, rule file was detected and rule executed successfully

"Broken" Rule

Rule 'GitHub.Community' -Type 'System.IO.DirectoryInfo'

Working Rule

Rule 'GitHub.Community' -Type 'PSRule.Data.RepositoryInfo'