on:
push:
branches:
- main
paths:
- 'src/model/**/*.mdl'
- 'Code/tests/03-Impl/01_Unittest/**/*.tpt'
jobs:
build:
runs-on: self-hosted
steps:
- uses: actions/checkout@v2
- name: Run batch files for .tpt files
shell: bash
run: |
shopt -s globstar
base_path="code/tests/03-Impl/01_Unittest"
# Fetch units based on directories under base_path
units=("$base_path"/*)
for unit_path in "${units[@]}"; do
# Skip if not a directory
if [ ! -d "$unit_path" ]; then
continue
fi
# Check if the unit contains modified .tpt files
modified_files=$(git diff --name-only HEAD~1 "$unit_path" | grep -E "\.tpt$")
if [ -z "$modified_files" ]; then
echo "Skipping unit: $unit_path"
continue
fi
# Process batch files
for batch_file in "$unit_path"/*.bat; do
if [ -f "$batch_file" ]; then
echo "Running batch file: $batch_file"
cmd.exe /C start /b "$batch_file"
fi
done
# Process modified .tpt files
for file in $modified_files; do
echo "Triggering batch file for unit: $unit_path"
unit_name=$(basename "$unit_path")
new_file_name="TR_CM_${unit_name}.bat"
if [ -f "$unit_path/$new_file_name" ]; then
echo "Running $new_file_name"
cmd.exe /C start /b "$unit_path/$new_file_name"
fi
done
done
This is the script I am trying to implement. When a commit happens to the paths, the workflow will be triggered. The script should compare the commit changes with the last commit ID and fetch the files. If there are new changes in .mdl or .tpt files, the corresponding batch file in the .tpt directory should run. I have tried using this script. If you have any scripts or suggestions, please provide them. It would be greatly helpful to me. Thanks in advance!
If you have any scripts or suggestions, please provide them.