0
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.

Murali
  • 1
  • 2
  • I am guessing that the problem is that the CI/CD environment does not do a full clone but instead only a shallow clone with the latest commit, thus attempts to look at the history fails. – hlovdal Jun 13 '23 at 17:47
  • See [this answer](https://stackoverflow.com/a/69752584/23118) and [this blog](https://github.blog/2020-12-21-get-up-to-speed-with-partial-clone-and-shallow-clone/). – hlovdal Jun 13 '23 at 17:52
  • Can you tell me, what is the command to get previous commit in the path of repo and how can i diff the changes of current commit with previous commit? – Murali Jun 14 '23 at 04:29
  • HEAD^ i tried with this, it is not working – Murali Jun 14 '23 at 04:58

0 Answers0