question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set default output of filter if none are matched?

See original GitHub issue

I would like to be able to set the default output if the list is empty.

Using the below as an example, I would like to be able to do two things.

  1. Set a default like with.default: [src, server]
  2. Have an option to use all filters as the default if empty. with.outputAllFilters: true or something like that
jobs:
  tests:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: dorny/paths-filter@v2
      id: filter
      with:
        filters: |
          backend:
            - 'backend/**'
          frontend:
            - 'frontend/**'

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Bearbobscommented, Jul 12, 2021

The common pattern combined with YAML anchors would likely work.

However, there is one more question I have to make sure it would work.

In my common pattern, I would like to include almost all of a top level folder and ignore a specific sublevel folder.

I can do this in on.push/on.pull_request like below.

Is there a way I can do similarly in the common pattern? Or does micromatch only support inclusion not exclusion?

name: Snapshot Tests - Non-US
on:
    push:
        paths:
            # Generic
            - banners/**
            - modals/**
            - server/**
            - src/**
            - tests/functional/spec/*
            - tests/functional/spec/utils/**
            - utils/**
            # Exclude US Files
            - '!banners/US/**'
            - '!modals/US/**'
            - '!server/locale/US/**'
            - '!src/components/modal/content/US*/**'
            - '!tests/functional/spec/US/**'

@merlinpatt you can use same filters in an inverted approach where you seperate out both path to exculde and include under two filter and use if condition in github workflow to make the decision,like:

  changes:
    runs-on: ubuntu-latest
    # Set job outputs to values from filter step
    outputs:
      paths-to-exclude: ${{ steps.filter.outputs.paths-to-exclude }}
      paths-to-include: ${{ steps.filter.outputs.paths-to-include }}
    steps:
      - uses: actions/checkout@v2
      - uses: dorny/paths-filter@v2
        id: filter
        with:
          filters: |
            paths-to-include:
                - banners/**
                - modals/**
                - server/**
                - src/**
                - tests/functional/spec/*
                - tests/functional/spec/utils/**
                - utils/**
            paths-to-exclude: 
                - 'banners/US/**'
                - 'modals/US/**'
                - 'server/locale/US/**'
  run-tests:
    name: Run tests
    needs: [changes]
    if: |
      ${{ (needs.changes.outputs.paths-to-exclude == 'false' && needs.changes.outputs.paths-to-include == 'true') ||  (needs.changes.outputs.paths-to-exclude == 'true' && needs.changes.outputs.paths-to-include == 'true') }}
    #actual workflow
1reaction
merlinpattcommented, Jun 22, 2021

The common pattern combined with YAML anchors would likely work.

However, there is one more question I have to make sure it would work.

In my common pattern, I would like to include almost all of a top level folder and ignore a specific sublevel folder.

I can do this in on.push/on.pull_request like below.

Is there a way I can do similarly in the common pattern? Or does micromatch only support inclusion not exclusion?

name: Snapshot Tests - Non-US
on:
    push:
        paths:
            # Generic
            - banners/**
            - modals/**
            - server/**
            - src/**
            - tests/functional/spec/*
            - tests/functional/spec/utils/**
            - utils/**
            # Exclude US Files
            - '!banners/US/**'
            - '!modals/US/**'
            - '!server/locale/US/**'
            - '!src/components/modal/content/US*/**'
            - '!tests/functional/spec/US/**'
Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Returning default value in method if there are no matches
I have a method that will find an operator and return the new position. But if there are no matches, i want it...
Read more >
FILTER function - Microsoft Support
The FILTER function allows you to filter a range of data based on criteria you define. In the following example we used the...
Read more >
How To Use the Python Filter Function - DigitalOcean
The first argument to filter() is a function, which we use to decide whether to include or filter out each item. The function...
Read more >
Excel FILTER Function – How To Use
The FILTER function is an Excel function that lets you fetch or "filter" a data set based on the criteria supplied via an...
Read more >
Filtering AWS CLI output - AWS Command Line Interface
The service only returns matching results which can speed up HTTP response times for large data sets. Client-side filtering is supported by the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found