Skip to content

Commit

Permalink
Merge pull request #196 from mikemcd3912/githubActions
Browse files Browse the repository at this point in the history
GitHub actions Update - File structure Edge Cases handling + housekeeping items
  • Loading branch information
elamaran11 authored Jan 30, 2024
2 parents 641b035 + c6e95e4 commit d8885f6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 31 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/close-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
paths-ignore:
- 'Validated_Partners/**'
- '.github/**'
- 'docs'
- '.git'

jobs:
merge-master-back-to-dev:
if: github.event.pull_request.merged == false
Expand Down
87 changes: 56 additions & 31 deletions .github/workflows/new-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ jobs:
run:
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr

- if: ${{github.event.action == 'synchronize' }}
name: Sync Pause
run: sleep 120

- name: Parse Namespace data, Create ConfigMap
id: find-namespace-yaml
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')
# Pull file information down into a JSON array
readarray -t files < <(curl -s "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files" | jq -c '.[]')
# Move updated files over to dev branch
git fetch --all
Expand All @@ -34,39 +38,65 @@ jobs:
# fetch most recent update to dev
git checkout developer_branch
git pull
for item in $files; do
git checkout pr -- $item
git add $item
echo "Moving $item"
# Remove Deleted Files, copy over added or modified files
for item in "${files[@]}"; do
status=$(echo "$item" | jq -r '.status')
filename=$(echo "$item" | jq -r '.filename')
if [ "$status" == renamed ]; then
git checkout pr -- $filename
git add $filename
if [ -f $(echo "$item" | jq -r '.previous_filename') ]; then
git rm $(echo "$item" | jq -r '.previous_filename')
fi
echo "Renaming $filename"
elif [ "$status" != removed ]; then
git checkout pr -- $filename
git add $filename
echo "Moving $filename"
else
if [ -f $filename ]; then
echo "Deleting $filename"
git rm $filename
fi
fi
done
# Find Namespace File(s) in uploads list and generate/update configmap for each
for filename in $files
do
echo "Filename = $filename"
# Create ConfigMap for each file's partner folder
for item in "${files[@]}"; do
status=$(echo "$item" | jq -r '.status')
filename=$(echo "$item" | jq -r '.filename')
# Parse namespace data
if [ $(echo "$filename" | grep -c "namespace.yaml") ]; then
if [ "$status" != removed ]; then
# Parse namespace data
subdirectory=$(dirname $filename)
echo "Sub Directory = $subdirectory"
namespace_file_subdirectory=$(dirname $filename)
namespace_file=$(find $namespace_file_subdirectory -name *namespace*)
# 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"
# get namespace from dev branch partner directory
while [ -z "$(find $namespace_file_subdirectory -name '*namespace*')" ]; do
namespace_file_subdirectory=$(dirname $namespace_file_subdirectory)
if [ $(basename $namespace_file_subdirectory) == "Partner" ] || [ $(basename $namespace_file_subdirectory) == "Core" ]; then
echo "No Namespace File Found in Partner Directory"
exit 200
fi
namespace_file=$(find $namespace_file_subdirectory -name "*namespace*")
done
if [ -f $namespace_file ]; then
namespace_file_subdirectory=$(dirname $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"
echo "No Namespace file found"
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
Expand All @@ -80,20 +110,15 @@ jobs:
echo " commitHash: ${{ github.event.pull_request.head.sha }}" >> $config_map_file
echo " deployed: \"$(date +%s)\"" >> $config_map_file
echo " env: $(echo $subdirectory | cut -f1 -d/ | awk -F- '{print $NF}' )" >> $config_map_file
echo $subdirectory
echo $config_map_file
mkdir -p ./$subdirectory/
mv "$config_map_file" ./$subdirectory/
git add .
mkdir -p ./$namespace_file_subdirectory/
mv "$config_map_file" ./$namespace_file_subdirectory/
git add ./$namespace_file_subdirectory/
else
echo "No Namespace found, Invalid namespace file"
exit 100
fi
else
echo "Not a namespace.yaml file"
fi
fi
done
git commit -m "Adding new and changed files for PR_${{ github.event.pull_request.number }}"
Expand Down

0 comments on commit d8885f6

Please sign in to comment.