Created
January 6, 2022 21:02
-
-
Save rail/024c27ebc0c205fbdf32c753f5b1c767 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
commit 9ddff96937ff110f9319893d465089c5ec2d3138 | |
Author: Rail Aliiev <[email protected]> | |
Date: Thu Jan 6 10:43:55 2022 -0500 | |
week 0 release automation | |
Release note (<category, see below>): <what> <show> <why> | |
release: add pick sha skeleton | |
Release note: None | |
diff --git a/build/release/teamcity-mark-build-qualified.sh b/build/release/teamcity-mark-build-qualified.sh | |
index ca9f00cbbf..3296fbdaf9 100755 | |
--- a/build/release/teamcity-mark-build-qualified.sh | |
+++ b/build/release/teamcity-mark-build-qualified.sh | |
@@ -5,3 +5,4 @@ set -euxo pipefail | |
source "$(dirname "${0}")/teamcity-mark-build.sh" | |
mark_build "qualified" | |
+publish_metadata | |
diff --git a/build/release/teamcity-mark-build.sh b/build/release/teamcity-mark-build.sh | |
index 25acb1da85..1462e60d57 100755 | |
--- a/build/release/teamcity-mark-build.sh | |
+++ b/build/release/teamcity-mark-build.sh | |
@@ -31,3 +31,30 @@ mark_build() { | |
gcloud container images add-tag "${gcr_repository}:${TC_BUILD_BRANCH}" "${gcr_repository}:latest-${release_branch}-${build_label}-build" | |
tc_end_block "Push new docker image tag" | |
} | |
+ | |
+publish_metadata() { | |
+ # TODO: move to a separate file | |
+ tc_start_block "Metadata" | |
+ # ignore master builds | |
+ echo $TC_BUILD_BRANCH | grep -q alpha && return | |
+ # release-21.2 | |
+ release_branch=$(echo $TC_BUILD_BRANCH | awk -F- '{print $1}' | sed 's/^v//' | awk -F. '{print "release-" $1 "." $2}') | |
+ # The tag contains a version number which has to be bumped by 1 | |
+ release_version=$(echo $TC_BUILD_BRANCH | awk -F- '{print $1}' | awk -F. '{print $1 "." $2 "." $3+1}') | |
+ # TODO: create a GCS bucket | |
+ # TODO: create credentials to publish to the bucket above | |
+ timestamp=$(date -u +"%Y-%m-%dT%H:%M:%SZ") | |
+ cat > "$release_version.json" << EOF | |
+{ | |
+ "version": "$release_version", | |
+ "branch": "$release_branch", | |
+ "sha": "$BUILD_VCS_NUMBER", | |
+ "timestamp": "$timestamp", | |
+ "tag": "$TC_BUILD_BRANCH" | |
+} | |
+EOF | |
+ # TODO: set the bucket, dry run bucket | |
+ cat "$release_version.json" | |
+ gsutil cp "$release_version.json" "gs://$gcs_bucket/releases/$release_version.json" | |
+ tc_end_block "Metadata" | |
+} | |
diff --git a/pkg/cmd/release/BUILD.bazel b/pkg/cmd/release/BUILD.bazel | |
new file mode 100644 | |
index 0000000000..ce9d8171a1 | |
--- /dev/null | |
+++ b/pkg/cmd/release/BUILD.bazel | |
@@ -0,0 +1,15 @@ | |
+load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") | |
+ | |
+go_library( | |
+ name = "release_lib", | |
+ srcs = ["main.go"], | |
+ importpath = "github.com/cockroachdb/cockroach/pkg/cmd/release", | |
+ visibility = ["//visibility:private"], | |
+ deps = ["@com_github_spf13_cobra//:cobra"], | |
+) | |
+ | |
+go_binary( | |
+ name = "release", | |
+ embed = [":release_lib"], | |
+ visibility = ["//visibility:public"], | |
+) | |
diff --git a/pkg/cmd/release/main.go b/pkg/cmd/release/main.go | |
new file mode 100644 | |
index 0000000000..87679883b9 | |
--- /dev/null | |
+++ b/pkg/cmd/release/main.go | |
@@ -0,0 +1,70 @@ | |
+package main | |
+ | |
+import ( | |
+ "fmt" | |
+ | |
+ "github.com/spf13/cobra" | |
+) | |
+ | |
+func main() { | |
+ cmdPickSHA := &cobra.Command{ | |
+ Use: "pick-sha qualify-url publish-url", | |
+ Short: "Pick release git sha for a particular version and communicate the decision", | |
+ Long: `Pick release sha, send email, create Jira ticket, etc.`, | |
+ Args: cobra.ExactArgs(2), | |
+ RunE: func(cmd *cobra.Command, args []string) error { | |
+ return pickSHA(args[0], args[1]) | |
+ }, | |
+ } | |
+ rootCmd := &cobra.Command{Use: "release"} | |
+ rootCmd.AddCommand(cmdPickSHA) | |
+ err := rootCmd.Execute() | |
+ if err != nil { | |
+ panic(err) | |
+ } | |
+} | |
+ | |
+func pickSHA(url string, publishTo string) error { | |
+ meta, err := fetchVersionJSON(url) | |
+ // TODO: copy the metadata to a stable location where it's not overwritten by qualify build | |
+ // TODO: before copying check if it's already there and bail if exists, can be forced by -f | |
+ if err != nil { | |
+ return err | |
+ } | |
+ if err := sendEmail(meta); err != nil { | |
+ // TODO: combine errors | |
+ // TODO: add flag to skip this step | |
+ return err | |
+ } | |
+ if err := postToJira(meta); err != nil { | |
+ // TODO: combine errors | |
+ // TODO: add flag to skip this step | |
+ return err | |
+ } | |
+ return nil | |
+} | |
+func fetchVersionJSON(url string) (metadata, error) { | |
+ // TODO: add retry | |
+ fmt.Println("version", url) | |
+ return metadata{}, nil | |
+} | |
+ | |
+func publishJSON(meta metadata) error { | |
+ return nil | |
+} | |
+ | |
+type metadata struct { | |
+ Version string `json:"version"` | |
+ Tag string `json:"tag"` | |
+ Branch string `json:"branch"` | |
+ SHA string `json:"sha"` | |
+ Timestamp string `json:"timestamp"` | |
+} | |
+ | |
+func sendEmail(meta metadata) error { | |
+ return nil | |
+} | |
+ | |
+func postToJira(meta metadata) error { | |
+ return nil | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment