-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add support for processing files based on git diff #688
Comments
As a temporary workaround until this feature can be implemented, it might be useful to document filtering files by the git diff information in CI or by using the output from a prior step, like this If that sounds like a good idea, I'd be happy to take a poke at a PR to add that example. |
@michaeltlombardi Absolutely. That would be appreciated. If you want to start a PR, I'd suggest to add a new section to: docs/creating-your-pipeline.md after configuration. |
Another thing to consider is how we handling complex relationships with changed files. While this feature may not resolve this entirely be itself. For example: With the changes files of:
This file may be changed, however is excluded via Really we want to process the whole module directory |
That's a great point. What is probably best practice is to use something like the Sorry for dropping the ball on this, I cleared the notification at some point and never remembered to circle back. For this specific use case (caveat: I have never used bicep, I'm gesturing at correctness here because I lack context), I think something like this would work: name: Analyze templates
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
analyze_arm:
name: Analyze templates
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2 # Retrieve current and preceding commit
# Check for file changes in modules/storage/v1
- name: Analyze File Changes
id: changed-files-modules-storage
uses: tj-actions/[email protected]
with:
files: modules/storage/v1
# Analyze Azure resources using PSRule for Azure only if any files changed
- name: Analyze Azure template files
uses: microsoft/[email protected]
if: steps.changed-files-modules-storage.outputs.any_changed == 'true'
with:
modules: 'PSRule.Rules.Azure' Another example is a hypothetical "All commands in a module must have appropriate reference documentation" requirement. For this repo, that might look like: name: Analyze Command Documentation
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
analyze_cmdlet_docs:
name: Analyze Command Documentation
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2 # Retrieve current and preceding commit
# Check for command source and docs changes
- name: Analyze File Changes
id: changed-files-commands
uses: tj-actions/[email protected]
with:
files: |
src/**/Commands
docs/commands
# Analyze documentation to see if all commands have full documentation
# that matches their implementation details.
- name: Analyze Azure template files
uses: microsoft/[email protected]
if: steps.changed-files-commands.outputs.any_changed == 'true'
with:
modules: 'PSRule.Rules.PSCmdletDocs' # Hypothetical I don't see a way around having to define steps for everything you want to control the changed-file behavior for. Combining these two rules would look like: name: Analyze
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2 # Retrieve current and preceding commit
# Check for command source and docs changes
- name: Analyze Command File Changes
id: changed-files-commands
uses: tj-actions/[email protected]
with:
files: |
src/**/Commands
docs/commands
# Check for file changes in modules/storage/v1
- name: Analyze Azure File Changes
id: changed-files-modules-storage
uses: tj-actions/[email protected]
with:
files: modules/storage/v1
# Analyze documentation to see if all commands have full documentation
# that matches their implementation details.
- name: Analyze Azure template files
uses: microsoft/[email protected]
if: steps.changed-files-commands.outputs.any_changed == 'true'
with:
modules: 'PSRule.Rules.PSCmdletDocs' # Hypothetical
# Analyze Azure resources using PSRule for Azure only if any files changed
- name: Analyze Azure template files
uses: microsoft/[email protected]
if: steps.changed-files-modules-storage.outputs.any_changed == 'true'
with:
modules: 'PSRule.Rules.Azure' More likely, it would be better practice to define multiple jobs or workflows (especially in this case as command docs and the template files aren't related). Given this though, I think I see a path towards defining "files to check for changes" in a rule definition as an optional key but it would likely require implementing the files-changed check logic in PowerShell. |
@michaeltlombardi Some of these might work with the |
Cross referencing #1095 |
@michaeltlombardi Based on your suggestion.
A custom convention might look like this: Export-PSRuleConvention 'AddModuleFiles' -Initialize {
foreach ($inputFile in $PSRule.Repository.GetChangedFiles()) {
if ($inputFile.Extension -eq '.bicep') {
# Get module path
$modulePath = $inputFile.AsFileInfo().Directory;
while (!$modulePath.Name.StartsWith('v')) {
$modulePath = $modulePath.Parent;
}
$moduleVersion = $modulePath.Name;
$moduleName = $modulePath.Parent.Name;
# Add whole module path to input files
$PSRule.Input.Add($modulePath.FullName);
# Add matching docs
$PSRule.Input.Add("docs/modules/$moduleName-$moduleVersion/");
}
}
} |
When a pull request is opened it may be desirable to limit checks to files included in the PR.
This would be desirable when externally new rules have been introduced that now cause existing files already in the repository to fail.
The text was updated successfully, but these errors were encountered: