githubutils

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 21 Imported by: 17

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/solo-io/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: "solo-io",
		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"

	// https://docs.github.com/en/rest/guides/traversing-with-pagination#changing-the-number-of-items-received
	MAX_GITHUB_RESULTS_PER_PAGE = 100
	MIN_GITHUB_PAGE_NUM         = 1
)

Variables

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

Functions

func CreateIssue added in v0.21.11

func CreateIssue(ctx context.Context, client *github.Client, owner, repo string, ir *github.IssueRequest) (*github.Issue, error)

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 FilterReleases added in v0.21.10

func FilterReleases(releases []*github.RepositoryRelease, constraint *semver.Constraints) []*github.RepositoryRelease

Filters slice of github releases by providing a constraint on the release semver does not modify input slice, returns the filtered list. If we are unable to parse a release version, we do not include it in the filtered list Deprecated: use FilterRepositoryReleases

func FilterRepositoryReleases added in v0.21.16

func FilterRepositoryReleases(releases []*github.RepositoryRelease, predicate RepositoryReleasePredicate) []*github.RepositoryRelease

func FindLatestReleaseBySemver added in v0.21.1

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

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 GetAllIssues added in v0.21.11

func GetAllIssues(ctx context.Context, client *github.Client, owner, repo string, listOpts *github.IssueListByRepoOptions) ([]*github.Issue, error)

Gets all issues from a repo in order from newest to oldest

func GetAllRepoIssuesWithMax added in v0.21.11

func GetAllRepoIssuesWithMax(ctx context.Context, client *github.Client, owner, repo string, maxIssues int, listOpts *github.IssueListByRepoOptions) ([]*github.Issue, error)

Gets all issues from a repo in order from newest to oldest, up to a maxIssues number of issues

func GetAllRepoReleases added in v0.21.7

func GetAllRepoReleases(ctx context.Context, client *github.Client, owner, repo string) ([]*github.RepositoryRelease, error)

func GetAllRepoReleasesWithMax added in v0.21.7

func GetAllRepoReleasesWithMax(ctx context.Context, client *github.Client, owner, repo string, maxReleases int) ([]*github.RepositoryRelease, 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 GetRepoReleasesWithPredicateAndMax added in v0.21.16

func GetRepoReleasesWithPredicateAndMax(ctx context.Context, client *github.Client, owner, repo string, predicate RepositoryReleasePredicate, maxReleases int) ([]*github.RepositoryRelease, 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 SortReleasesBySemver added in v0.21.1

func SortReleasesBySemver(releases []*github.RepositoryRelease)

Sorts github release array in place by semver, from most recent release to least (v2.8.0, v1.7.0, v1.6.0...)

func UpdateIssue added in v0.21.11

func UpdateIssue(ctx context.Context, client *github.Client, owner, repo string, issueNumber int, ir *github.IssueRequest) error

func UploadReleaseAssetCli

func UploadReleaseAssetCli(spec *UploadReleaseAssetSpec)

Types

type AllReleasesPredicate added in v0.21.16

type AllReleasesPredicate struct {
}

func (*AllReleasesPredicate) Apply added in v0.21.16

type NoReleasesPredicate added in v0.21.27

type NoReleasesPredicate struct {
}

func (*NoReleasesPredicate) Apply added in v0.21.27

type PRSpec added in v0.9.7

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 RepositoryReleasePredicate added in v0.21.16

type RepositoryReleasePredicate interface {
	Apply(release *github.RepositoryRelease) bool
}

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