-
Notifications
You must be signed in to change notification settings - Fork 43
132 lines (115 loc) · 5.51 KB
/
new-pull-request.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: PR Opened - moving new ISV addon to developer_branch for E2E testing
on:
pull_request_target:
branches: [main]
types: [opened, reopened, synchronize]
paths-ignore:
- 'Validated_Partners/**'
- '.github/**'
- 'docs/**'
- '.git/**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Base
uses: actions/checkout@v4
- name: Checkout PR Code
run:
git fetch origin pull/${{ github.event.pull_request.number }}/head:pr
- if: ${{github.event.action == 'synchronize' }}
name: Sync Pause
run: sleep 60
- name: Parse Namespace data, Create ConfigMap
id: find-namespace-yaml
run: |
# 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
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
# 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
# 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')
echo $filename
if [ "$status" != removed ] && [[ $filename != *README.md ]]; then
# Parse namespace data
subdirectory=$(dirname $filename)
namespace_file_subdirectory=$(dirname $filename)
namespace_file=$(find $namespace_file_subdirectory -name *namespace*)
namespace_name=""
partner_name=""
# get namespace from dev branch partner directory. If in Testers directory, re-align to Addons/Partner/{partner}
while [ -z "$(find $namespace_file_subdirectory -name '*namespace*')" ] && [[ -z $namespace_name ]]; do
partner_name=$(basename $namespace_file_subdirectory)
namespace_file_subdirectory=$(dirname $namespace_file_subdirectory)
if [ $(basename $namespace_file_subdirectory) == "Testers" ]; then
namespace_file_subdirectory=$(dirname $namespace_file_subdirectory)
namespace_file_subdirectory=$namespace_file_subdirectory/Addons/Partner/$partner_name
elif [ $(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"
exit 200
fi
if [[ -n $namespace_name ]]; then
namespace=$(echo $namespace_name | xargs echo -n)
config_map_file="config-map-${{ github.event.pull_request.number }}.yml"
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 " deployed: \"$(date +%s)\"" >> $config_map_file
echo " env: $(echo $subdirectory | cut -f1 -d/ | awk -F- '{print $NF}' )" >> $config_map_file
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
fi
done
git commit -m "Adding new and changed files for testing of PR_${{ github.event.pull_request.number }}"
git push