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
- func CreateStatus(ctx context.Context, client *github.Client, ...) (*github.RepoStatus, error)
- func DownloadFile(url string, w io.Writer) error
- func DownloadRepoArchive(ctx context.Context, client *github.Client, w io.Writer, ...) error
- func FindLatestReleaseTag(ctx context.Context, client *github.Client, owner, repo string) (string, error)
- func FindLatestReleaseTagIncudingPrerelease(ctx context.Context, client *github.Client, owner, repo string) (string, error)
- func FindStatus(ctx context.Context, client *github.Client, ...) (*github.RepoStatus, error)
- func GetClient(ctx context.Context) (*github.Client, error)
- func GetClientOrExit(ctx context.Context) *github.Client
- func GetClientWithOrWithoutToken(ctx context.Context) *github.Client
- func GetFilesForChangelogVersion(ctx context.Context, client *github.Client, owner, repo, ref, version string) ([]*github.RepositoryContent, error)
- func GetFilesFromGit(ctx context.Context, client *github.Client, owner, repo, ref, path string) ([]*github.RepositoryContent, error)
- func GetGithubToken() (string, error)
- func GetRawGitFile(ctx context.Context, client *github.Client, content *github.RepositoryContent, ...) ([]byte, error)
- func GetReleaseOrExit(ctx context.Context, client *github.Client, version *versionutils.Version, ...) *github.RepositoryRelease
- func MarkError(ctx context.Context, client *github.Client, ...) (*github.RepoStatus, error)
- func MarkFailure(ctx context.Context, client *github.Client, ...) (*github.RepoStatus, error)
- func MarkInitialPending(ctx context.Context, client *github.Client, ...) (*github.RepoStatus, error)
- func MarkSuccess(ctx context.Context, client *github.Client, ...) (*github.RepoStatus, error)
- func UploadReleaseAssetCli(spec *UploadReleaseAssetSpec)
- type ReleaseAssetSpec
- type RepoClient
- type UploadReleaseAssetSpec
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 ¶
This section is empty.
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 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 GetReleaseOrExit ¶
func GetReleaseOrExit(ctx context.Context, client *github.Client, version *versionutils.Version, spec *UploadReleaseAssetSpec) *github.RepositoryRelease
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 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)
}
func NewRepoClient ¶
func NewRepoClient(client *github.Client, owner, repo string) RepoClient
type UploadReleaseAssetSpec ¶
type UploadReleaseAssetSpec struct {
Owner string
Repo string
Assets []ReleaseAssetSpec
SkipAlreadyExists bool
}
Click to show internal directories.
Click to hide internal directories.