test #28
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Changed files | |
on: | |
push: | |
branches: | |
- Optimize-GH-CI-Workflow | |
jobs: | |
setup-matrix: | |
runs-on: ubuntu-latest | |
name: Setup test matrix scenarios | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup test matrix scenarios | |
id: setup-matrix-scenarios | |
run: | | |
set -eu | |
matrix=$(find $GITHUB_WORKSPACE/scenarios/ -name "*.json" | awk -F'/' '{split($11, file_name, "."); split(file_name[1], cloud_region, "-");region= (length(cloud_region) > 1) ? substr($11, index($11, "-") + 1) : ""; cloud=cloud_region[1]; gsub(".json", "", region); print "{\"cloud\": \"" cloud "\", \"file_name\": \"" file_name[1] "\", " (region != "" ? "\"region\": \"" region "\", " : "") "\"scenario_type\": \"" $8 "\", \"scenario_name\": \"" $9 "\"},"}' | sort | uniq | sed 's/,$/,/') | |
# Remove md, sh and github files from the list | |
file_changes=$(git diff --name-only -r origin/main HEAD | grep -Ev '\.md$|\.sh$|\.github/') | |
echo "file_changes: $file_changes" | |
terraform_module_changes=$(echo "$file_changes" | grep -E '\.tf$' | awk -F'/' '{print $3}' | xargs) | |
echo "terraform_module_changes: $terraform_module_changes" | |
if [ $(echo "$terraform_module_changes" | wc -w) -eq 1 ]; then | |
updated_matrix=$(echo "$matrix" | jq 'any(.cloud == "$cloud")'; echo $?) | |
else | |
updated_matrix=$matrix | |
fi | |
echo "updated_matrix: $updated_matrix" | |
changed_scenario_files=$(echo "$file_changes" | grep -E '^scenarios/') | |
echo "changed_scenario_files: $changed_scenario_files" | |
IFS=' ' read -ra scenario_names <<< "$(echo "$changed_scenario_files" | awk -F'/' '{print $3}')" | |
echo "scenario_names: $scenario_names" | |
filtered_json=$(echo "$updated_matrix" | jq --argjson names '["'"${scenario_names[@]}"'"]' 'map(select(.scenario_name as $name | $names | index($name)))') | |
echo "filtered_json: $filtered_json" |