Added find and find-first.

This commit is contained in:
2025-06-28 21:50:34 -07:00
parent 1efb518fdf
commit bee04ce498
4 changed files with 262 additions and 0 deletions

50
utils/find/action.yaml Normal file
View File

@@ -0,0 +1,50 @@
name: find
description: "Find files matching a specific pattern."
inputs:
path:
description: "Path to search in."
required: false
default: "."
pattern:
description: "Pattern to search for (supports glob patterns)."
required: true
type:
description: "Type of files to find (f=files, d=directories, l=links)."
required: false
default: "f"
maxDepth:
description: "Maximum depth to search."
required: false
default: ""
minDepth:
description: "Minimum depth to search."
required: false
default: ""
size:
description: "Size constraint (e.g., +100k, -1M)."
required: false
default: ""
modified:
description: "Modified time constraint (e.g., -1, +7)."
required: false
default: ""
additionalArgs:
description: "Additional arguments to pass to find command."
required: false
default: ""
outputs:
files:
description: "List of found files (newline separated)."
value: ${{ steps.find.outputs.files }}
count:
description: "Number of files found."
value: ${{ steps.find.outputs.count }}
runs:
using: "composite"
steps:
- name: "Find files."
id: find
run: |
bash "${{ github.action_path }}/find.sh" "${{ inputs.path }}" "${{ inputs.pattern }}" "${{ inputs.type }}" \
"${{ inputs.maxDepth }}" "${{ inputs.minDepth }}" "${{ inputs.size }}" "${{ inputs.modified }}" "${{ inputs.additionalArgs }}"
shell: bash

67
utils/find/find.sh Normal file
View File

@@ -0,0 +1,67 @@
#!/bin/bash
# Get inputs
SEARCH_PATH="$1"
PATTERN="$2"
FILE_TYPE="$3"
MAX_DEPTH="$4"
MIN_DEPTH="$5"
SIZE="$6"
MODIFIED="$7"
ADDITIONAL_ARGS="$8"
if [[ ! -f "$GITHUB_OUTPUT" ]]; then
# Write to stdout if the output file doesn't exist.
GITHUB_OUTPUT="/dev/fd/1"
fi
# Build the find command - start with basic find and path
FIND_CMD="find \"$SEARCH_PATH\""
if [[ -n "$FILE_TYPE" ]]; then
# Add type filter first
FIND_CMD="$FIND_CMD -type $FILE_TYPE"
fi
# Add depth constraints before name pattern
if [[ -n "$MAX_DEPTH" ]]; then
FIND_CMD="$FIND_CMD -maxdepth $MAX_DEPTH"
fi
if [[ -n "$MIN_DEPTH" ]]; then
FIND_CMD="$FIND_CMD -mindepth $MIN_DEPTH"
fi
# Add name pattern
FIND_CMD="$FIND_CMD -name \"$PATTERN\""
if [[ -n "$SIZE" ]]; then
FIND_CMD="$FIND_CMD -size $SIZE"
fi
if [[ -n "$MODIFIED" ]]; then
FIND_CMD="$FIND_CMD -mtime $MODIFIED"
fi
if [[ -n "$ADDITIONAL_ARGS" ]]; then
FIND_CMD="$FIND_CMD $ADDITIONAL_ARGS"
fi
# Execute the command and capture output
OUTPUT=$(eval "$FIND_CMD" 2>/dev/null || true)
RESULT=$?
# Count the number of files found
if [[ -n "$OUTPUT" ]]; then
COUNT=$(echo "$OUTPUT" | wc -l)
echo "files<<EOF" >> "$GITHUB_OUTPUT"
echo "$OUTPUT" >> "$GITHUB_OUTPUT"
echo "EOF" >> "$GITHUB_OUTPUT"
else
COUNT=0
echo "files=" >> "$GITHUB_OUTPUT"
fi
echo "count=$COUNT" >> "$GITHUB_OUTPUT"
exit $RESULT