githubutils

package
v0.0.0-...-c4d1043 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

README

Uploading Release Assets to Github

To upload release assets to Github, follow these steps (requires go-utils 0.2.10+).

Create a Go script

Create a script upload_github_release_asset.go, like this:

package main

import (
	"github.com/wx-chevalier/go-utils/githubutils"
)

func main() {
	assets := make([]githubutils.ReleaseAssetSpec, 2)
	assets[0] = githubutils.ReleaseAssetSpec{
		Name: "hello",
		ParentPath: "_output",
		UploadSHA: true,
	}
	assets[1] = githubutils.ReleaseAssetSpec{
		Name: "my-resource.yaml",
		ParentPath: "namespace",
	}
	spec := githubutils.UploadReleaseAssetSpec{
		Owner: "wx-chevalier",
		Repo: "testrepo",
		Assets: assets,
		SkipAlreadyExists: true,
	}
	githubutils.UploadReleaseAssetCli(&spec)
}

Create a Make target

#----------------------------------------------------------------------------------
# Github Assets
#----------------------------------------------------------------------------------

.PHONY: upload-github-release-assets
upload-github-release-assets: hello
	go run upload_github_release_assets.go

Update cloudbuild.yaml to call this target

steps:
- name: 'gcr.io/solo-corp/go-mod-make:0.1.1'
  args: [..., 'upload-github-release-assets', ...]
  secretEnv: ['GITHUB_TOKEN']
  env:
  - 'TAGGED_VERSION=$TAG_NAME'

Make sure GITHUB_TOKEN and TAGGED_VERSION are in the environment.

Notes

  • On each asset, a flag UploadSHA can be set to true to upload a SHA256 hash file.
  • Set SkipAlreadyExists=true to not fail when trying to upload an asset that already exists.

Documentation

Index

Constants

View Source
const (
	GITHUB_TOKEN = "GITHUB_TOKEN"

	STATUS_SUCCESS = "success"
	STATUS_FAILURE = "failure"
	STATUS_ERROR   = "error"
	STATUS_PENDING = "pending"

	COMMIT_FILE_STATUS_ADDED    = "added"
	COMMIT_FILE_STATUS_MODIFIED = "modified"
	COMMIT_FILE_STATUS_DELETED  = "deleted"

	CONTENT_TYPE_FILE      = "file"
	CONTENT_TYPE_DIRECTORY = "dir"
)

Variables

View Source
var NoReleaseBeforeShaFound = errors.Errorf("no release found before sha")

Functions

func CreateStatus

func CreateStatus(ctx context.Context, client *github.Client, owner, repo, sha, description, label, state string) (*github.RepoStatus, error)

func DownloadFile

func DownloadFile(url string, w io.Writer) error

func DownloadRepoArchive

func DownloadRepoArchive(ctx context.Context, client *github.Client, w io.Writer, owner, repo, sha string) error

This function writes directly to a writer, so the user is required to close the writer manually

func FindLatestReleaseTag

func FindLatestReleaseTag(ctx context.Context, client *github.Client, owner, repo string) (string, error)

func FindLatestReleaseTagIncudingPrerelease

func FindLatestReleaseTagIncudingPrerelease(ctx context.Context, client *github.Client, owner, repo string) (string, error)

func FindStatus

func FindStatus(ctx context.Context, client *github.Client, statusLabel, owner, repo, sha string) (*github.RepoStatus, error)

func GetClient

func GetClient(ctx context.Context) (*github.Client, error)

func GetClientOrExit

func GetClientOrExit(ctx context.Context) *github.Client

func GetClientWithOrWithoutToken

func GetClientWithOrWithoutToken(ctx context.Context) *github.Client

func GetFilesForChangelogVersion

func GetFilesForChangelogVersion(ctx context.Context, client *github.Client, owner, repo, ref, version string) ([]*github.RepositoryContent, error)

func GetFilesFromGit

func GetFilesFromGit(ctx context.Context, client *github.Client, owner, repo, ref, path string) ([]*github.RepositoryContent, error)

func GetGithubToken

func GetGithubToken() (string, error)

func GetRawGitFile

func GetRawGitFile(ctx context.Context, client *github.Client, content *github.RepositoryContent, owner, repo, ref string) ([]byte, error)

func MarkError

func MarkError(ctx context.Context, client *github.Client, owner, repo, sha, description, label string) (*github.RepoStatus, error)

func MarkFailure

func MarkFailure(ctx context.Context, client *github.Client, owner, repo, sha, description, label string) (*github.RepoStatus, error)

func MarkInitialPending

func MarkInitialPending(ctx context.Context, client *github.Client, owner, repo, sha, description, label string) (*github.RepoStatus, error)

func MarkSuccess

func MarkSuccess(ctx context.Context, client *github.Client, owner, repo, sha, description, label string) (*github.RepoStatus, error)

func UploadReleaseAssetCli

func UploadReleaseAssetCli(spec *UploadReleaseAssetSpec)

Types

type PRSpec

type PRSpec struct {
	Message string
}

type ReleaseAssetSpec

type ReleaseAssetSpec struct {
	Name       string
	ParentPath string
	UploadSHA  bool
}

type RepoClient

type RepoClient interface {
	FindLatestReleaseTagIncudingPrerelease(ctx context.Context) (string, error)
	CompareCommits(ctx context.Context, base, sha string) (*github.CommitsComparison, error)
	DirectoryExists(ctx context.Context, sha, directory string) (bool, error)
	FileExists(ctx context.Context, sha, path string) (bool, error)
	CreateBranch(ctx context.Context, branchName string) (*github.Reference, error)
	CreatePR(ctx context.Context, branchName string, spec PRSpec) error
	GetShaForTag(ctx context.Context, tag string) (string, error)
	GetPR(ctx context.Context, num int) (*github.PullRequest, error)
	UpdateRelease(ctx context.Context, release *github.RepositoryRelease) (*github.RepositoryRelease, error)
	GetCommit(ctx context.Context, sha string) (*github.RepositoryCommit, error)
	FindStatus(ctx context.Context, statusLabel, sha string) (*github.RepoStatus, error)
	CreateStatus(ctx context.Context, sha string, status *github.RepoStatus) (*github.RepoStatus, error)
	CreateComment(ctx context.Context, pr int, comment *github.IssueComment) (*github.IssueComment, error)
	DeleteComment(ctx context.Context, commentId int64) error
	FindLatestTagIncludingPrereleaseBeforeSha(ctx context.Context, sha string) (string, error)
}

func NewRepoClient

func NewRepoClient(client *github.Client, owner, repo string) RepoClient

type UploadReleaseAssetSpec

type UploadReleaseAssetSpec struct {
	Owner             string
	Repo              string
	Assets            []ReleaseAssetSpec
	SkipAlreadyExists bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL