-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* create krew index pr
- Loading branch information
Showing
3 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
# shellcheck source=scripts/functions.sh | ||
source "$(dirname "${BASH_SOURCE[0]}")/functions" | ||
|
||
[ "$#" -eq 0 ] && usage "version must be provided!" | ||
[ -z "$1" ] && usage "version must be provided!" | ||
|
||
create_pull_request "$1" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,9 @@ EOF | |
function get_download_dir() { | ||
local result | ||
if [ "$#" -gt 0 ]; then | ||
result="$BASE_DIR/out/download/$1/" | ||
result="$(get_output_dir)/download/$1/" | ||
else | ||
result="$BASE_DIR/out/download/" | ||
result="$(get_output_dir)/download/" | ||
fi | ||
echo "$result" | ||
} | ||
|
@@ -35,10 +35,14 @@ function get_release_dir() { | |
echo "parameter version missing" | ||
exit 1 | ||
) | ||
local result="$BASE_DIR/out/release/$1" | ||
local result="$(get_output_dir)/release/$1" | ||
echo "$result" | ||
} | ||
|
||
function get_output_dir() { | ||
echo "$BASE_DIR/out" | ||
} | ||
|
||
# $1: version to download | ||
function download_virtctl_binaries() { | ||
local version | ||
|
@@ -195,7 +199,7 @@ function create_github_release() { | |
version="$1" | ||
|
||
release_response=$( | ||
curl --silent --fail -u "dhiller:$GH_KUBECTL_VIRT_PLUGIN_TOKEN" -X POST \ | ||
curl --silent --fail -u "$(get_github_auth)" -X POST \ | ||
"https://api.github.com/repos/dhiller/kubectl-virt-plugin/releases" \ | ||
-H 'Content-Type: text/json; charset=utf-8' \ | ||
--data @- 2>&1 << EOF | ||
|
@@ -216,9 +220,70 @@ EOF | |
for file in $(get_release_packages $version); do | ||
platform_filename=$(basename $file) | ||
target_upload_url=$(echo $upload_url | sed 's/{.*/?name='"$platform_filename"'\&label='"$platform_filename"'/') | ||
curl -v --fail -u "dhiller:$GH_KUBECTL_VIRT_PLUGIN_TOKEN" -X POST \ | ||
curl -v --fail -u "$(get_github_auth)" -X POST \ | ||
-H 'Content-Type: application/gzip' \ | ||
"$target_upload_url" \ | ||
--data-binary "@$file" | ||
done | ||
} | ||
|
||
function create_pull_request() { | ||
title="Update virt (KubeVirt virtctl plugin package) to $1" | ||
branch_name="bump-virtctl-to-$1" | ||
|
||
( | ||
cd "$(get_output_dir)" || (echo "Failed to cd into $(get_output_dir)"; exit 1) | ||
|
||
repo_dir="$(get_output_dir)/krew-index" | ||
[ -d "$repo_dir" ] && rm -rf "$repo_dir" | ||
|
||
origin='github.com/kubernetes-sigs/krew-index.git' | ||
git clone "https://$origin" | ||
|
||
cd "$repo_dir" || (echo "Failed to cd into $repo_dir"; exit 1) | ||
git config user.email "[email protected]" | ||
git config user.name "Daniel Hiller" | ||
|
||
fork='github.com/dhiller/krew-index.git' | ||
git remote add fork "https://$fork" | ||
|
||
git checkout -b "$branch_name" | ||
|
||
cp "$(get_release_dir "$1")/virt.yaml" "$repo_dir" | ||
git add virt.yaml | ||
|
||
git commit -m "$title" | ||
git push "https://$(get_github_auth)@$fork" || exit 1 | ||
) | ||
|
||
pr_response=$( | ||
curl --silent --fail -u "$(get_github_auth)" -X POST \ | ||
-H 'Content-Type: text/json; charset=utf-8' \ | ||
-H 'Accept: application/vnd.github.shadow-cat-preview+json' \ | ||
"https://api.github.com/repos/kubernetes-sigs/krew-index/pulls" \ | ||
--data @- 2>&1 << EOF | ||
{ | ||
"title": "${title}", | ||
"head": "dhiller:${branch_name}", | ||
"base": "master", | ||
"body": "See https://github.com/kubevirt/kubevirt/releases/tag/${1}", | ||
"maintainer_can_modify": true, | ||
"draft": true | ||
} | ||
EOF | ||
) | ||
pr_url=$(echo "$pr_response" | jq -r ._links.html.href) | ||
echo "$pr_url" | ||
} | ||
|
||
function get_github_auth() { | ||
echo "$(get_github_username):$(get_github_token)" | ||
} | ||
|
||
function get_github_username() { | ||
echo "dhiller" | ||
} | ||
|
||
function get_github_token() { | ||
echo "$GH_KUBECTL_VIRT_PLUGIN_TOKEN" | ||
} |