From 67eccb04e23e6786f72ebcb8be7e93b5a4854a53 Mon Sep 17 00:00:00 2001 From: Mike McDonald <61101829+mikemcd3912@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:51:36 -0700 Subject: [PATCH] GH Actions branch for New PR and Close PR issues (#105) * Sample Workload * Sample Workload * Sample Workload * Sample Workload * GH Actions * GH Actions * Github Workflow * updated branch name * added file removal on unsuccessful Close * Close pull request remove configmap * added file copying * subdirectory check * filecopy using branch checkout * fix branch name * Copy partner Directory * Copy partner Directory update * Moving sample workload * remove unnecessary workflow * workflow fix addition * adding files to commit * GH actions source check * Update cross branch checkout path * Check subdirectory * Add files with ConfigMap * close pull req updates to remove files * remove commented out code * update ghActions file * remove workflow in branch * add gh action workflow * echo directory * update directory reference * update directory reference 2 * add files from Partner * add files from Partner 2 * add files from Partner 3 * add files from Partner 4 * add files from Partner 5 * add files from Partner 6 * Reset new pull * check env state * list files check * foreach fix * update for each syntax * update files variable * subdirectory variable pull * remove escape char * remove brackets * remove quotes and extra dollar sign * add reference to files * file checkout logic added * Fix if else indent * remove extra paren * remove extra path * change checkout to absolute path * adding tracking comments and path edit * recording Commit ID * fix git ID variable * fix git hash command * return to pre-hash recording * align commit messages * align commit messages * list automated Commits from this PR * delete files test * Git log addition * fix namespace extraction * update commits string ID and show hashes only * commit tagging update * git log --all addition * update logging * checkout dev branch * checkout origin dev branch * edit query string * revert query string * remove merge, set back to developer branch * test git logging on PR open * Update podinfo.yaml * Revert "Feature/sample workload test 7.25" * Push prev day changes * Search for existing namespace file * Reupload sample workload files * Looking for existing namespace file * Namespace file searchj * Namespace file search * Revert to working state * Check Dir from updated files * Check Dir from updated files 2 * Check Dir from updated files array * Check Dir from updated files array 2 * test for existing namespace file * test for existing namespace file, fix for statements * test for existing namespace file, fix if statement * test for existing namespace file update * uncomment subdir assignment * Update Logic to find namespace file * Update configMap Message * Update revert logic * Update git log * Update branch checkout * Test Git log * re-order commits * revert instead of delete * revert variable fix * remove dir * fix Commits variable * push git revert * more precise commit reverts * more precise commit reverts, fix hash * back to merge method * reorder new PR file, add directory search * Update time on pod def * New file search logic * lookup namespace file before searching committed files * Add missing quote * Alter directory check * update file search logic * variable test * variable test 2 * step reduction * fix close script * add tag for conformitron bot * fixing echo destination * add rows on new pr * Update Step language to be more descriptive of step being performed * add Hash to ConfigMap * update test * update sha on configmap * Update commit order * Add config mapand updated files for podinfo_PR_16 * Update merge logic * fix bad if statement * Update merge logic * Update merge logic 2 * Update merge logic with if statement * Fix IF statement * Fetch first * infert IF test * Comment out additional merge * Add push * Add config map for podinfo_PR_16 * Checkout dev branch at beginning * Remove ConfirMap from Feature Branch * Change File move commit process * Close PR commit logging * Update podinfo.yaml * Update close workflow * Delete sample workload * Trying to fix Conflict * Workflow Files * Merge removal of Files * add workflow files back in * Updating workflow to work for Net new * Spacing on new IF statement * Spacing on new IF statement 2 * Create Subdirectory if not already in Dev branch * Fix Filepath for ConfigMap file * Fix Filepath for ConfigMap file * Git branch and commit test * Fetch commits not on the runner, list * Massive Simplifying test * add commit * add author * Fix Checkout to do deletions * Spacing on IF statement * Fixing files search * Git sha testing * Git sha testing quote pull * Update git log * Quote * file extension * file name * Git log test * Git log test 2 * Git log test 3 * Git log test 4 * Git log test 4 * Git log test 5 * Git log test 6 * Git log test 7 * Git log test 8 * Git log test 9 * Git log test 10 * Tags * Tags 2 * Cleanup * Tag Reverts * Add Pull * Add Pull to correct spot * remove Long history * Remove Tag on Close * Edit revert command * Use Commit Message Tag and rev-list grep to ID reverts * Fix the rev-list command with HEAD variable * Pull branch history * Comment out tagging * different pull strategy * Check without tag filtering * fetch depth * Update Rev-List adding tag back in * Clear out old commented code in Close PR * Revert work * Add Author before revert * Remove other re-set method * Add Error handling for Revert ops * Fix error handling * check delete * Fixing weird git issue * Delete eks-anywhere-common/Addons/Partner/workload_sample directory * Space added * Fix GH actions rollback * Fix new namespace file search * Fix new namespace file search commentary * Adding then's * adding fi * Fixing branch checkouts * Fixing branch fetch * Move the ConfigMap over to Dev Branch * Update the Addition of ConfigMap file to Dev Branch * Commit new ConfigMap * Commit new ConfigMap author addition * Cleaning Up Merge * Re-order branch checkout * Update ConfigMapFile path * Make Subdirectory * Comment Out Extra Checkout * adding -p option for mkdir * E2E Testing Updates * Cleanup commented Rows * Set feature/e2e as target branch --------- Co-authored-by: Elamaran Shanmugam Co-authored-by: Conformitron Bot --- .github/workflows/close-pull-request.yaml | 32 ++++++++ .github/workflows/new-pull-request.yaml | 98 +++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 .github/workflows/close-pull-request.yaml create mode 100644 .github/workflows/new-pull-request.yaml diff --git a/.github/workflows/close-pull-request.yaml b/.github/workflows/close-pull-request.yaml new file mode 100644 index 00000000..227570e3 --- /dev/null +++ b/.github/workflows/close-pull-request.yaml @@ -0,0 +1,32 @@ +name: PRs to Main +on: + pull_request: + branches: [feature/e2e-feedback-testing] + types: [closed] +jobs: + merge-master-back-to-dev: + if: github.event.pull_request.merged == false + timeout-minutes: 2 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: developer_branch + fetch-depth: 0 + - name: Remove Updates from this PR + run: | + # Get Commits from this PR + TAG=PR_${{ github.event.pull_request.number }} + commits=$(git rev-list HEAD --grep=$TAG) + echo "commits: $commits" + + # Revert Commits or Log that no change was made + git config --local user.email "dev@null" + git config --local user.name "Conformitron Bot" + + for commit in $commits; do + echo $commit + git revert $commit --no-edit || echo "Commit $commit not reverted" + done + git push + diff --git a/.github/workflows/new-pull-request.yaml b/.github/workflows/new-pull-request.yaml new file mode 100644 index 00000000..3b75eb7b --- /dev/null +++ b/.github/workflows/new-pull-request.yaml @@ -0,0 +1,98 @@ +name: Run CI for ISV Addons + +on: + pull_request: + branches: [feature/e2e-feedback-testing] + types: [opened, reopened, synchronize] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + ref: ${{ github.event.pull_request.head.ref }} + + - name: Parse Namespace data, Create ConfigMap and Copy over committed files + 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') + 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 + if [ -n "$namespace_file" ]; then + subdirectory=$(dirname $namespace_file) + echo "Sub Directory = $subdirectory" + 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" + 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 + 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 ${{ github.event.pull_request.head.ref }} -- $item + git add $item + echo $item + done + git commit -m "Adding new and changed files for ${namespace}_PR_${{ github.event.pull_request.number }}" + git push + \ No newline at end of file