|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -Eeu |
| 3 | + |
| 4 | +SCRIPT_NAME=demo-code-review.sh |
| 5 | +ROOT_DIR=$(dirname $(readlink -f $0))/.. |
| 6 | +BRANCH_NAME="" |
| 7 | + |
| 8 | +function print_help |
| 9 | +{ |
| 10 | + cat <<EOF |
| 11 | +Usage: $SCRIPT_NAME <options> [BRANCH_NAME] |
| 12 | +
|
| 13 | +Script that will makes a branch with commits and pull-request, |
| 14 | +and does the correct reporting of the code review attestations |
| 15 | +
|
| 16 | +Options are: |
| 17 | + -h Print this help menu |
| 18 | +EOF |
| 19 | +} |
| 20 | + |
| 21 | +function check_arguments |
| 22 | +{ |
| 23 | + while getopts "h" opt; do |
| 24 | + case $opt in |
| 25 | + h) |
| 26 | + print_help |
| 27 | + exit 1 |
| 28 | + ;; |
| 29 | + \?) |
| 30 | + echo "Invalid option: -$OPTARG" >&2 |
| 31 | + exit 1 |
| 32 | + ;; |
| 33 | + esac |
| 34 | + done |
| 35 | + |
| 36 | + # Remove options from command line |
| 37 | + shift $((OPTIND-1)) |
| 38 | + |
| 39 | + if [ $# -eq 0 ]; then |
| 40 | + echo "Missing BRANCH_NAME" |
| 41 | + fi |
| 42 | + BRANCH_NAME=$1; shift |
| 43 | +} |
| 44 | + |
| 45 | +function wait_for_github_actions |
| 46 | +{ |
| 47 | + sleep 10 |
| 48 | + echo -n "Waiting for GitHub Actions to complete " |
| 49 | + |
| 50 | + while true; do |
| 51 | + result=$(gh run list --json status) |
| 52 | + # Check if there are any workflows that are not completed |
| 53 | + if echo "$result" | jq -e '.[] | select(.status != "completed")' > /dev/null; then |
| 54 | + echo -n "." |
| 55 | + sleep 2 |
| 56 | + else |
| 57 | + break |
| 58 | + fi |
| 59 | + done |
| 60 | + echo |
| 61 | +} |
| 62 | + |
| 63 | + |
| 64 | +function update_content_file |
| 65 | +{ |
| 66 | + local file=$1; shift |
| 67 | + # Increment the value after counter= in the file |
| 68 | + sed -i -E 's/(counter=)([0-9]+)/echo "\1$((\2+1))"/e' ${file} |
| 69 | + grep "counter=" ${file} | sed "s/counter=//" |
| 70 | +} |
| 71 | + |
| 72 | +main() |
| 73 | +{ |
| 74 | + check_arguments "$@" |
| 75 | + |
| 76 | + echo; echo "*** Create a branch, update source and make a pull-request" |
| 77 | + git checkout -b ${BRANCH_NAME}-demo |
| 78 | + FE_VER=$(update_content_file src/frontend.txt) |
| 79 | + git add src |
| 80 | + git commit -m "${BRANCH_NAME} Updated SW frontend=${FE_VER}" |
| 81 | + FE_VER=$(update_content_file src/frontend.txt) |
| 82 | + git add src |
| 83 | + git commit -m "${BRANCH_NAME} Updated SW frontend=${FE_VER}" |
| 84 | + git push; wait_for_github_actions |
| 85 | + gh pr create --fill |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +# echo; echo "*** Waiting for pull request to do required checks before merge"; wait_for_github_actions |
| 91 | +# gh pr merge --auto --squash --delete-branch; wait_for_github_actions |
| 92 | +# echo; echo "*** Wait for build on main to finish"; wait_for_github_actions |
| 93 | +# make report_all_envs > /dev/null; wait_for_github_actions |
| 94 | +# echo; echo "*** SW is now running in dev. Do a deployment from dev to staging" |
| 95 | +# make deploy_to_staging; wait_for_github_actions |
| 96 | +# make report_all_envs > /dev/null; wait_for_github_actions |
| 97 | +# echo; echo "*** Make a release candidate for SW now running in staging with Jira issue ${JIRA_KEY_1}" |
| 98 | +# make generate_jira_release; wait_for_github_actions |
| 99 | +# |
| 100 | +# echo; echo "*** We assume the product owner found a bug and wanted a new version of the backend" |
| 101 | +# |
| 102 | +# echo; echo "*** Create a branch, update backend app and make a pull-request **" |
| 103 | +# git checkout -b ${JIRA_KEY_2}-demo-2 |
| 104 | +# BE_VER=$(update_content_file apps/backend/backend-content.txt) |
| 105 | +# git add apps/ |
| 106 | +# git commit -m "${JIRA_KEY_2} Updated SW backend=${BE_VER}" |
| 107 | +# git push; wait_for_github_actions |
| 108 | +# gh pr create --fill |
| 109 | +# echo; echo "*** Waiting for pull request to do required checks before merge"; wait_for_github_actions |
| 110 | +# gh pr merge --auto --squash --delete-branch; wait_for_github_actions |
| 111 | +# echo; echo "*** Wait for build on main to finish"; wait_for_github_actions |
| 112 | +# make report_all_envs > /dev/null; wait_for_github_actions |
| 113 | +# echo; echo "*** Updated SW is now running in dev. Do a deployment from dev to staging" |
| 114 | +# make deploy_to_staging; wait_for_github_actions |
| 115 | +# make report_all_envs > /dev/null; wait_for_github_actions |
| 116 | +# echo; echo "*** Update the release candidate for SW now running in staging." |
| 117 | +# echo "*** This will add the second JIRA-KEY ($JIRA_KEY_2) to the Jira release" |
| 118 | +# make generate_jira_release; wait_for_github_actions |
| 119 | +# echo; echo "*** Check if current release candidate has been approved and can be released. This shall fail!" |
| 120 | +# make check_release_to_prod; wait_for_github_actions |
| 121 | +# |
| 122 | +# echo; echo "*** Go to url:" |
| 123 | +# echo "https://kosli-team.atlassian.net/projects/OPS?selectedItem=com.atlassian.jira.jira-projects-plugin%3Arelease-page" |
| 124 | +# echo |
| 125 | +# echo "Press the version you see in the list. It should only be one that is UNRELEASED" |
| 126 | +# echo "On the right hand side press the + next to Approvers" |
| 127 | +# echo "Add your self as an approver" |
| 128 | +# echo "Change the approval from PENDING to APPROVED" |
| 129 | +# echo "After that press 'c' to continue" |
| 130 | +# while :; do |
| 131 | +# read -n 1 key |
| 132 | +# if [[ "$key" == "c" ]]; then |
| 133 | +# echo -e "\nContinuing..." |
| 134 | +# break |
| 135 | +# fi |
| 136 | +# done |
| 137 | +# echo; echo "*** Check if release has been approved" |
| 138 | +# make check_release_to_prod; wait_for_github_actions |
| 139 | +# make report_all_envs > /dev/null; wait_for_github_actions |
| 140 | +# make update_tags |
| 141 | +# echo; echo "*** You can now check kosli UX to see that correct SW is running and that attestations have been done" |
| 142 | +} |
| 143 | + |
| 144 | +main "$@" |
0 commit comments