Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ particular step in a workflow.
<!-- start:links: autogenerated by .scripts/local/update_readme_list.sh -->
- [build-container-image](./build-container-image/README.md)
- [build-product-image](./build-product-image/README.md)
- [detect-changes](./detect-changes/README.md)
- [free-disk-space](./free-disk-space/README.md)
- [publish-helm-chart](./publish-helm-chart/README.md)
- [publish-image](./publish-image/README.md)
Expand Down
25 changes: 25 additions & 0 deletions detect-changes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# `detect-changes`

> Manifest: [detect-changes/action.yml][detect-changes]

This action detects changed files by providing a list of glob patterns.
It can be used in situations where the GHA native path filtering cannot be used.

## Inputs and Outputs

> [!TIP]
> For descriptions of the inputs and outputs, see the complete [detect-changes] action.

### Inputs

| Input | Required | Description |
| ---------- | -------- | --------------------------------------------------------------- |
| `patterns` | No | A list of glob patterns to detect changes in. Defaults to ['*'] |

### Outputs

| Output | Description |
| ----------- | ------------------------------------------------------------------------------------------------ |
| `detected` | `'true'` or `'false'` indicating if any changed files were matched by the provided glob patterns |

[detect-changes]: ./action.yaml
35 changes: 35 additions & 0 deletions detect-changes/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: detect-changes
description: Detect changed files by providing a list of glob patterns
inputs:
patterns:
description: A list of glob patterns to detect changes in. Defaults to ['*'].
default: "['*']"
outputs:
detected:
description: Returns if any changed files were matched by the provided glob patterns.
value: ${{ steps.check.outputs.MATCHED }}
runs:
using: composite
steps:
- name: Check for changed files
id: check
env:
PATTERNS: ${{ inputs.patterns }}
shell: bash
run: |
set -euo pipefail

# This is cursed... we use `.[] | .` to remove quotes and any yaml formatting.
readarray -t GLOBS < <(echo -n "$PATTERNS" | yq '.[] | .')

MATCHED="false"
for GLOB in "${GLOBS[@]}"; do
if ! git diff --exit-code --name-only "${BASE_SHA}.." -- "$GLOB"; then
# When git diff exist with an error, that means there was a diff
# for the glob.
MATCHED="true"
fi
done

echo "MATCHED=$MATCHED" | tee -a "$GITHUB_OUTPUT"