Convert testJob.yaml to daily Cronjob & Exclude Validated Partners PR's from GH actions workflow runs #424
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: 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/**' | |
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 | |
- 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') | |
# 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 | |
for item in $files; do | |
git checkout pr -- $item | |
git add $item | |
echo "Moving $item" | |
done | |
# 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 |