Skip to content

Commit

Permalink
pkg/gh2gcs: Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus committed May 25, 2020
1 parent a5a145f commit 5143dcc
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ filegroup(
"//lib:all-srcs",
"//pkg/command:all-srcs",
"//pkg/gcp:all-srcs",
"//pkg/gh2gcs:all-srcs",
"//pkg/git:all-srcs",
"//pkg/github:all-srcs",
"//pkg/http:all-srcs",
Expand Down
1 change: 1 addition & 0 deletions cmd/gh2gcs/cmd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "k8s.io/release/cmd/gh2gcs/cmd",
visibility = ["//visibility:public"],
deps = [
"//pkg/gh2gcs:go_default_library",
"//pkg/github:go_default_library",
"//pkg/log:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
Expand Down
25 changes: 22 additions & 3 deletions cmd/gh2gcs/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"k8s.io/release/pkg/gh2gcs"
"k8s.io/release/pkg/github"
"k8s.io/release/pkg/log"
)
Expand Down Expand Up @@ -125,11 +126,29 @@ func run(opts *options) error {

// TODO: Support downloading releases via yaml config
// TODO: Support single release or multi-release scenarios
if err := gh.DownloadReleaseAssets(opts.org, opts.repo, opts.tag, opts.outputDir); err != nil {
return err
uploadConfig := &gh2gcs.UploadConfig{}

if opts.tag != "" {
repoConfig := &gh2gcs.RepoConfig{
Org: opts.org,
Name: opts.repo,
ReleaseTags: []string{
opts.tag,
},
}

uploadConfig.RepoConfigs = append(uploadConfig.RepoConfigs, *repoConfig)
}

// TODO: Add GCS upload logic
for _, rc := range uploadConfig.RepoConfigs {
if err := gh2gcs.DownloadReleases(&rc, gh, opts.outputDir); err != nil {
return err
}

if err := gh2gcs.UploadToGCS(&rc, gh, opts.outputDir); err != nil {
return err
}
}

return nil
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/gh2gcs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["config.go"],
importpath = "k8s.io/release/pkg/gh2gcs",
visibility = ["//visibility:public"],
deps = [
"//pkg/github:go_default_library",
"@com_github_sirupsen_logrus//:go_default_library",
],
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
52 changes: 52 additions & 0 deletions pkg/gh2gcs/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package gh2gcs

import (
"github.com/sirupsen/logrus"
"k8s.io/release/pkg/github"
)

type UploadConfig struct {
RepoConfigs []RepoConfig
}

type RepoConfig struct {
Org string
Name string
ReleaseTags []string
GCSBucket string
ReleaseDir string
}

func DownloadReleases(repoCfg *RepoConfig, ghClient *github.GitHub, outputDir string) error {
tags := repoCfg.ReleaseTags

for _, tag := range tags {
if err := ghClient.DownloadReleaseAssets(repoCfg.Org, repoCfg.Name, tag, outputDir); err != nil {
return err
}
}

return nil
}

// TODO: Add GCS upload logic
func UploadToGCS(repoCfg *RepoConfig, ghClient *github.GitHub, outputDir string) error {
logrus.Info("Uploading to GCS...")
return nil
}

0 comments on commit 5143dcc

Please sign in to comment.