Skip to content

Commit

Permalink
Updating GH Action to evaluate each file subdirectory for individual …
Browse files Browse the repository at this point in the history
…processing
  • Loading branch information
mikemcd3912 committed Nov 29, 2023
1 parent 4c75526 commit 30933ea
Showing 1 changed file with 63 additions and 76 deletions.
139 changes: 63 additions & 76 deletions .github/workflows/new-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,86 +24,73 @@ jobs:
run: |
# Pull files down into a filename array
files=$(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | jq -r '.[].filename')
echo $files
filearr=($files)
# Find Namespace File in uploads list or in modified file subdirectory
namespace_file=$(echo "$files" | grep "namespace.yaml")
subdirectory=$(dirname ${filearr[0]})
if [ -z $namespace_file ]; then
git fetch --all
git config --local user.email "dev@null"
git config --local user.name "Conformitron Bot"
git checkout developer_branch
git pull
if [ -f "${subdirectory}/namespace.yaml" ]; then
namespace_file="${subdirectory}/namespace.yaml"
echo "namespace file = $namespace_file"
else
echo "No Namespace file found in existing subdirectory"
exit 200
fi
elif [[ -n $namespace_file ]]; then
echo "Namespace File: $namespace_file"
else
echo "No Namespace file found in commit or subdirectory"
fi
# Parse namespace data
namespace_file="${namespace_file}"
if [ -n "$namespace_file" ]; then
subdirectory=$(dirname $namespace_file)
echo "Sub Directory = $subdirectory"
# get namespace from pr
git checkout pr
namespace_name=$(grep -E '^\s*metadata:\s*$|^\s*name:\s*' "$namespace_file" | awk -F':' '{gsub(/ /, "", $2); print $2}')
git fetch --all
git config --local user.email "dev@null"
git config --local user.name "Conformitron Bot"
# fetch most recent update to dev
git checkout developer_branch
git pull
if [[ ! -z $namespace_name ]]; then
echo "$namespace_name"
namespace=$(echo $namespace_name | xargs echo -n)
echo $namespace
config_map_file="config-map-${{ github.event.pull_request.number }}.yml"
echo $config_map_file
echo "apiVersion: v1" >> $config_map_file
echo "kind: ConfigMap" >> $config_map_file
echo "metadata:" >> $config_map_file
echo " name: $namespace-configmap" >> $config_map_file
echo " namespace: $namespace" >> $config_map_file
echo " labels:" >> $config_map_file
echo " bot: conformitron" >> $config_map_file
echo "data:" >> $config_map_file
echo " Namespace: ${namespace}" >> $config_map_file
echo " prNumber: \"${{ github.event.pull_request.number }}\"" >> $config_map_file
echo " commitHash: ${{ github.event.pull_request.head.sha }}" >> $config_map_file
echo $subdirectory
echo $config_map_file
# Move updated files over to dev branch
git fetch --all
git config --local user.email "dev@null"
git config --local user.name "Conformitron Bot"
# fetch most recent update to dev
git checkout developer_branch
git pull
mkdir -p ./$subdirectory/
mv "$config_map_file" ./$subdirectory/
git add .
else
echo "No Namespace found"
exit 100
fi
else
echo "No namespace.yaml file found"
exit 200
fi
# Move updated files over
for item in $files; do
git checkout pr -- $item
git add $item
echo $item
echo "Moving $item"
done
git commit -m "Adding new and changed files for ${namespace}_PR_${{ github.event.pull_request.number }}"
# Find Namespace File(s) in uploads list and generate/update configmap for each
for filename in $files
do
echo "Filename = $filename"
# Parse namespace data
if [ $(echo "$filename" | grep -c "namespace.yaml") ]; then
subdirectory=$(dirname $filename)
echo "Sub Directory = $subdirectory"
# get namespace from dev branch directory where the updated file is being placed
if [ -f "${subdirectory}/namespace.yaml" ]; then
namespace_file="${subdirectory}/namespace.yaml"
echo "namespace file = $namespace_file"
namespace_name=$(grep -E '^\s*metadata:\s*$|^\s*name:\s*' "$namespace_file" | awk -F':' '{gsub(/ /, "", $2); print $2}')
else
echo "No Namespace file found in existing subdirectory"
exit 200
fi
if [[ -n $namespace_name ]]; then
echo "$namespace_name"
namespace=$(echo $namespace_name | xargs echo -n)
echo $namespace
config_map_file="config-map-${{ github.event.pull_request.number }}.yml"
echo $config_map_file
echo "apiVersion: v1" >> $config_map_file
echo "kind: ConfigMap" >> $config_map_file
echo "metadata:" >> $config_map_file
echo " name: $namespace-configmap" >> $config_map_file
echo " namespace: $namespace" >> $config_map_file
echo " labels:" >> $config_map_file
echo " bot: conformitron" >> $config_map_file
echo "data:" >> $config_map_file
echo " Namespace: ${namespace}" >> $config_map_file
echo " prNumber: \"${{ github.event.pull_request.number }}\"" >> $config_map_file
echo " commitHash: ${{ github.event.pull_request.head.sha }}" >> $config_map_file
echo $subdirectory
echo $config_map_file
mkdir -p ./$subdirectory/
mv "$config_map_file" ./$subdirectory/
git add .
else
echo "No Namespace found, Invalid namespace file"
exit 100
fi
else
echo "Not a namespace.yaml file"
fi
done
git commit -m "Adding new and changed files for PR_${{ github.event.pull_request.number }}"
git push

0 comments on commit 30933ea

Please sign in to comment.