Skip to content

Commit

Permalink
Automate release creation (#6)
Browse files Browse the repository at this point in the history
* create krew index pr
  • Loading branch information
dhiller authored Sep 3, 2019
1 parent 30e91ca commit 71fc3c2
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
11 changes: 11 additions & 0 deletions scripts/create-krew-index-pr.sh
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"
4 changes: 3 additions & 1 deletion scripts/create-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ echo $(test_linux_install_on_docker "$1")

echo -e "\nCreating github release:"
echo $(create_github_release "$1")

echo -e "\nRelease page is: https://github.com/dhiller/kubectl-virt-plugin/releases/tag/$1"

echo -e "\nCreating pull request:"
echo $(create_pull_request "$1")
75 changes: 70 additions & 5 deletions scripts/functions
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"
}

0 comments on commit 71fc3c2

Please sign in to comment.