Skip to content

Commit 2dc88d8

Browse files
authored
Merge pull request #19278 from adityasharad/actions/integration-test-filters
Actions: Fix handling of paths-ignore in autobuild scripts, add integration tests for configured path filters
2 parents 11aef70 + 283503b commit 2dc88d8

27 files changed

+145
-22
lines changed

Diff for: actions/extractor/tools/autobuild-impl.ps1

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
if (($null -ne $env:LGTM_INDEX_INCLUDE) -or ($null -ne $env:LGTM_INDEX_EXCLUDE) -or ($null -ne $env:LGTM_INDEX_FILTERS)) {
2-
Write-Output 'Path filters set. Passing them through to the JavaScript extractor.'
3-
} else {
4-
Write-Output 'No path filters set. Using the default filters.'
5-
# Note: We're adding the `reusable_workflows` subdirectories to proactively
6-
# record workflows that were called cross-repo, check them out locally,
7-
# and enable an interprocedural analysis across the workflow files.
8-
# These workflows follow the convention `.github/reusable_workflows/<nwo>/*.ya?ml`
9-
$DefaultPathFilters = @(
10-
'exclude:**/*',
11-
'include:.github/workflows/*.yml',
12-
'include:.github/workflows/*.yaml',
13-
'include:.github/reusable_workflows/**/*.yml',
14-
'include:.github/reusable_workflows/**/*.yaml',
15-
'include:**/action.yml',
16-
'include:**/action.yaml'
17-
)
1+
# Note: We're adding the `reusable_workflows` subdirectories to proactively
2+
# record workflows that were called cross-repo, check them out locally,
3+
# and enable an interprocedural analysis across the workflow files.
4+
# These workflows follow the convention `.github/reusable_workflows/<nwo>/*.ya?ml`
5+
$DefaultPathFilters = @(
6+
'exclude:**/*',
7+
'include:.github/workflows/*.yml',
8+
'include:.github/workflows/*.yaml',
9+
'include:.github/reusable_workflows/**/*.yml',
10+
'include:.github/reusable_workflows/**/*.yaml',
11+
'include:**/action.yml',
12+
'include:**/action.yaml'
13+
)
1814

15+
if ($null -ne $env:LGTM_INDEX_FILTERS) {
16+
Write-Output 'LGTM_INDEX_FILTERS set. Using the default filters together with the user-provided filters, and passing through to the JavaScript extractor.'
17+
# Begin with the default path inclusions only,
18+
# followed by the user-provided filters.
19+
# If the user provided `paths`, those patterns override the default inclusions
20+
# (because `LGTM_INDEX_FILTERS` will begin with `exclude:**/*`).
21+
# If the user provided `paths-ignore`, those patterns are excluded.
22+
$PathFilters = ($DefaultPathFilters -join "`n") + "`n" + $env:LGTM_INDEX_FILTERS
23+
$env:LGTM_INDEX_FILTERS = $PathFilters
24+
} else {
25+
Write-Output 'LGTM_INDEX_FILTERS not set. Using the default filters, and passing through to the JavaScript extractor.'
1926
$env:LGTM_INDEX_FILTERS = $DefaultPathFilters -join "`n"
2027
}
2128

Diff for: actions/extractor/tools/autobuild.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,22 @@ include:**/action.yaml
1717
END
1818
)
1919

20-
if [ -n "${LGTM_INDEX_INCLUDE:-}" ] || [ -n "${LGTM_INDEX_EXCLUDE:-}" ] || [ -n "${LGTM_INDEX_FILTERS:-}" ] ; then
21-
echo "Path filters set. Passing them through to the JavaScript extractor."
20+
if [ -n "${LGTM_INDEX_FILTERS:-}" ]; then
21+
echo "LGTM_INDEX_FILTERS set. Using the default filters together with the user-provided filters, and passing through to the JavaScript extractor."
22+
# Begin with the default path inclusions only,
23+
# followed by the user-provided filters.
24+
# If the user provided `paths`, those patterns override the default inclusions
25+
# (because `LGTM_INDEX_FILTERS` will begin with `exclude:**/*`).
26+
# If the user provided `paths-ignore`, those patterns are excluded.
27+
PATH_FILTERS="$(cat << END
28+
${DEFAULT_PATH_FILTERS}
29+
${LGTM_INDEX_FILTERS}
30+
END
31+
)"
32+
LGTM_INDEX_FILTERS="${PATH_FILTERS}"
33+
export LGTM_INDEX_FILTERS
2234
else
23-
echo "No path filters set. Using the default filters."
35+
echo "LGTM_INDEX_FILTERS not set. Using the default filters, and passing through to the JavaScript extractor."
2436
LGTM_INDEX_FILTERS="${DEFAULT_PATH_FILTERS}"
2537
export LGTM_INDEX_FILTERS
2638
fi

Diff for: actions/ql/integration-tests/filters-default/test.py

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| src/.github/action.yaml:1:1:11:32 | name: ' ... action' |
2+
| src/.github/actions/action-name/action.yml:1:1:11:32 | name: ' ... action' |
3+
| src/.github/workflows/workflow.yml:1:1:12:33 | name: A workflow |
4+
| src/action.yml:1:1:11:32 | name: ' ... action' |
5+
| src/excluded/action.yml:1:1:11:32 | name: ' ... action' |
6+
| src/included/action.yml:1:1:11:32 | name: ' ... action' |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| src/included/action.yml:1:1:11:32 | name: ' ... action' |
2+
| src/included/unreachable-workflow.yml:1:1:12:33 | name: A ... orkflow |

Diff for: actions/ql/integration-tests/filters-default/actions.expected renamed to actions/ql/integration-tests/filters/actions.paths-ignore-only.expected

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| src/.github/actions/action-name/action.yml:1:1:11:32 | name: ' ... action' |
33
| src/.github/workflows/workflow.yml:1:1:12:33 | name: A workflow |
44
| src/action.yml:1:1:11:32 | name: ' ... action' |
5+
| src/included/action.yml:1:1:11:32 | name: ' ... action' |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| src/included/action.yml:1:1:11:32 | name: ' ... action' |
2+
| src/included/unreachable-workflow.yml:1:1:12:33 | name: A ... orkflow |

Diff for: actions/ql/integration-tests/filters/actions.ql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import actions
2+
3+
from AstNode n
4+
where n instanceof Workflow or n instanceof CompositeAction
5+
select n
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
paths:
2+
- 'included'
3+
paths-ignore:
4+
- 'excluded'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
paths-ignore:
2+
- 'excluded'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
paths:
2+
- 'included'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
src/.github/action.yaml
2+
src/.github/actions/action-name/action.yml
3+
src/.github/workflows/workflow.yml
4+
src/action.yml
5+
src/excluded/action.yml
6+
src/included/action.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src/included/action.yml
2+
src/included/not-an-action.yml
3+
src/included/unreachable-workflow.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
src/.github/action.yaml
2+
src/.github/actions/action-name/action.yml
3+
src/.github/workflows/workflow.yml
4+
src/action.yml
5+
src/included/action.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
src/included/action.yml
2+
src/included/not-an-action.yml
3+
src/included/unreachable-workflow.yml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'A composite action'
2+
description: 'Do something'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Print
7+
run: echo "Hello world"
8+
shell: bash
9+
10+
- name: Checkout
11+
uses: actions/checkout@v4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: 'A composite action'
2+
description: 'Do something'
3+
runs:
4+
using: "composite"
5+
steps:
6+
- name: Print
7+
run: echo "Hello world"
8+
shell: bash
9+
10+
- name: Checkout
11+
uses: actions/checkout@v4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: 'Not an action, just a YAML file'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: An unreachable workflow
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
job:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: An unreachable workflow
2+
on:
3+
push:
4+
branches:
5+
- main
6+
7+
jobs:
8+
job:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4

Diff for: actions/ql/integration-tests/filters/test.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
@pytest.mark.ql_test(expected=".default-filters.expected")
4+
def test_default_filters(codeql, actions, check_source_archive):
5+
check_source_archive.expected_suffix = ".default-filters.expected"
6+
codeql.database.create(source_root="src")
7+
8+
@pytest.mark.ql_test(expected=".paths-only.expected")
9+
def test_config_paths_only(codeql, actions):
10+
codeql.database.create(source_root="src", codescanning_config="codeql-config.paths-only.yml")
11+
12+
@pytest.mark.ql_test(expected=".paths-ignore-only.expected")
13+
def test_config_paths_ignore_only(codeql, actions):
14+
codeql.database.create(source_root="src", codescanning_config="codeql-config.paths-ignore-only.yml")
15+
16+
@pytest.mark.ql_test(expected=".paths-and-paths-ignore.expected")
17+
def test_config_paths_and_paths_ignore(codeql, actions):
18+
codeql.database.create(source_root="src", codescanning_config="codeql-config.paths-and-paths-ignore.yml")

0 commit comments

Comments
 (0)