Browse Source

Fix PR comments, add error checking for push.

xmkb
CrossR 4 years ago
parent
commit
550c35db23
  1. 23
      docs/static/setup.ps1
  2. 32
      docs/static/setup.sh

23
docs/static/setup.ps1 vendored

@ -16,7 +16,7 @@ function Get-Choice-From-Options {
if ($selection -eq $Options.length + 1) { if ($selection -eq $Options.length + 1) {
Write-Host "Goodbye!" Write-Host "Goodbye!"
exit exit 1
} }
elseif ($selection -le $Options.length) { elseif ($selection -le $Options.length) {
$choice = $($selection - 1) $choice = $($selection - 1)
@ -40,7 +40,7 @@ function Test-Git-Config {
if ($lastExitCode -ne 0) { if ($lastExitCode -ne 0) {
Write-Host $ErrMsg Write-Host $ErrMsg
exit exit 1
} }
} }
@ -49,7 +49,7 @@ try {
} }
catch [System.Management.Automation.CommandNotFoundException] { catch [System.Management.Automation.CommandNotFoundException] {
Write-Host "Git is not installed, and is required for this script!" Write-Host "Git is not installed, and is required for this script!"
exit exit 1
} }
Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'" Test-Git-Config -Option "user.name" -ErrMsg "Git username not set!`nRun: git config --global user.name 'My Name'"
@ -134,7 +134,7 @@ $do_it = Read-Host "Continue? [Yn]"
if ($do_it -ne "" -and $do_it -ne "Y" -and $do_it -ne "y") { if ($do_it -ne "" -and $do_it -ne "Y" -and $do_it -ne "y") {
Write-Host "Aborting..." Write-Host "Aborting..."
exit exit 1
} }
git clone --single-branch "$repo_path" "$repo_name" git clone --single-branch "$repo_path" "$repo_name"
@ -167,10 +167,23 @@ git commit -m "Initial User Config."
if ($github_repo -ne "") { if ($github_repo -ne "") {
git remote add origin "$github_repo" git remote add origin "$github_repo"
git push --set-upstream origin $(git symbolic-ref --short HEAD) git push --set-upstream origin $(git symbolic-ref --short HEAD)
# If push failed, assume that the origin was incorrect and give instructions on fixing.
if ($lastExitCode -ne 0) {
Write-Host "Remote repository $github_repo not found..."
Write-Host "Check GitHub URL, and try adding again."
Write-Host "Run the following: "
Write-Host " git remote rm origin"
Write-Host " git remote add origin FIXED_URL"
Write-Host " git push --set-upstream origin $(git symbolic-ref --short HEAD)"
Write-Host "Once pushed, your firmware should be availalbe from GitHub Actions at: $actions"
exit 1
}
if ($github_repo -imatch "https") { if ($github_repo -imatch "https") {
$actions = "$($github_repo.substring(0, $github_repo.length - 4))/actions" $actions = "$($github_repo.substring(0, $github_repo.length - 4))/actions"
Write-Host "Your firmware should be availalbe from the GitHub Actions shortly: $actions" Write-Host "Your firmware should be availalbe from GitHub Actions shortly: $actions"
} }
} }

32
docs/static/setup.sh vendored

@ -2,21 +2,21 @@
set -e set -e
CheckExists() { check_exists() {
command_to_run=$1 command_to_run=$1
error_message=$2 error_message=$2
if ! eval "$command_to_run" &> /dev/null; then if ! eval "$command_to_run" &> /dev/null; then
printf "%s\n" "$error_message" printf "%s\n" "$error_message"
exit exit 1
fi fi
} }
CheckExists "command -v git" "git is not installed, and is required for this script!" check_exists "command -v git" "git is not installed, and is required for this script!"
CheckExists "command -v curl" "curl is not installed, and is required for this script!" check_exists "command -v curl" "curl is not installed, and is required for this script!"
CheckExists "git config user.name" "Git username not set!\nRun: git config --global user.name 'My Name'" check_exists "git config user.name" "Git username not set!\nRun: git config --global user.name 'My Name'"
CheckExists "git config user.email" "Git email not set!\nRun: git config --global user.email 'example@myemail.com'" check_exists "git config user.email" "Git email not set!\nRun: git config --global user.email 'example@myemail.com'"
repo_path="https://github.com/zmkfirmware/zmk-config-split-template.git" repo_path="https://github.com/zmkfirmware/zmk-config-split-template.git"
title="ZMK Config Setup:" title="ZMK Config Setup:"
@ -36,7 +36,7 @@ select opt in "${options[@]}" "Quit"; do
2 ) board="proton_c"; break;; 2 ) board="proton_c"; break;;
3 ) board="bluemicro840_v1"; break;; 3 ) board="bluemicro840_v1"; break;;
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit;; $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;;
*) echo "Invalid option. Try another one."; continue;; *) echo "Invalid option. Try another one."; continue;;
esac esac
@ -65,7 +65,7 @@ select opt in "${options[@]}" "Quit"; do
# Add link to docs on adding your own custom shield in your ZMK config! # Add link to docs on adding your own custom shield in your ZMK config!
# $(( ${#options[@]}+1 )) ) echo "Other!"; break;; # $(( ${#options[@]}+1 )) ) echo "Other!"; break;;
$(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit;; $(( ${#options[@]}+1 )) ) echo "Goodbye!"; exit 1;;
*) echo "Invalid option. Try another one.";continue;; *) echo "Invalid option. Try another one.";continue;;
esac esac
@ -111,7 +111,7 @@ read -r -p "Continue? [Yn]: " do_it
if [ -n "$do_it" ] && [ "$do_it" != "y" ] && [ "$do_it" != "Y" ]; then if [ -n "$do_it" ] && [ "$do_it" != "y" ] && [ "$do_it" != "Y" ]; then
echo "Aborting..." echo "Aborting..."
exit exit 1
fi fi
git clone --single-branch $repo_path ${repo_name} git clone --single-branch $repo_path ${repo_name}
@ -149,8 +149,20 @@ if [ -n "$github_repo" ]; then
git remote add origin "$github_repo" git remote add origin "$github_repo"
git push --set-upstream origin "$(git symbolic-ref --short HEAD)" git push --set-upstream origin "$(git symbolic-ref --short HEAD)"
# If push failed, assume that the origin was incorrect and give instructions on fixing.
if [ $? -ne 0 ] {
echo "Remote repository $github_repo not found..."
echo "Check GitHub URL, and try adding again."
echo "Run the following: "
echo " git remote rm origin"
echo " git remote add origin FIXED_URL"
echo " git push --set-upstream origin $(git symbolic-ref --short HEAD)"
echo "Once pushed, your firmware should be availalbe from GitHub Actions at: ${github_repo%.git}/actions"
exit 1
}
# TODO: Support determing the actions URL when non-https:// repo URL is used. # TODO: Support determing the actions URL when non-https:// repo URL is used.
if [ "${github_repo}" != "${github_repo#https://}" ]; then if [ "${github_repo}" != "${github_repo#https://}" ]; then
echo "Your firmware should be available from the GitHub Actions shortly: ${github_repo%.git}/actions" echo "Your firmware should be available from GitHub Actions shortly: ${github_repo%.git}/actions"
fi fi
fi fi

Loading…
Cancel
Save