Skip to content

Commit

Permalink
Merge pull request #5 from DecipherNow/new_one
Browse files Browse the repository at this point in the history
add functionality to add-assets, fix token parsing bug
  • Loading branch information
Justin Ely authored Jan 9, 2019
2 parents c2f43e5 + d7fd47b commit 7e8d4f8
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 4 deletions.
32 changes: 32 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: 2

defaults: &defaults
working_directory: /go/src/github.com/deciphernow/releaser
docker:
- image: golang:1.10

jobs:
build:
<<: *defaults
steps:
- checkout
- run: apt-get update && apt-get install -y ca-certificates git
- run: go get -u github.com/golang/dep/cmd/dep
- run: dep ensure -v
- run: go build
- run:
name: Release
command: |
export $(cat VERSION | grep VERSION)
./releaser github --token $GITHUB_TOKEN --semver $VERSION --organization deciphernow --asset releaser,CHANGELOG.md,README.md
workflows:
version: 2
build-and-release:
jobs:
- build:
filters:
tags:
ignore: /.*/
branches:
only: master
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.3.0 (Jan 8th, 2018)
### Added
- Option to add release assets to existing release ID

### Fixed
- Bug in parsing github token


## 0.2.1 (October 16th, 2018)
### Fixed
- Bug in splitting source docker tag off before re-tagging
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ OPTIONS:
#### Github Release

```bash
justin@mal:~/go/src/github.com/deciphernow/releaser$ ./releaser help github
>>$ ./releaser help github
NAME:
releaser github - Do the github release

Expand All @@ -53,6 +53,24 @@ OPTIONS:
--asset value File[s] to be uploaded to the github release
```

##### Adding release asset
```bash
>>$ ./releaser help add-asset
NAME:
releaser add-asset - Add an asset to an existing github release

USAGE:
releaser add-asset [command options] [arguments...]

OPTIONS:
--token value Access token for github releases
--organization value Organization for github releases
--username value Username for cmd operations
--password value Password for cmd operations
--asset value File[s] to be uploaded to the github release
--releaseID value Release to upload assets to. Must already exist.
```

### semver tagging/push docker images
`releaser docker --semver v1.3.4 --image deciphernow/gm-proxy:latest --username $DOCKER_USER --password $DOCKER_PASS`

Expand Down
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION=0.3.0
4 changes: 2 additions & 2 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
)

// UploadReleaseAsset takes a file and uploads it to a specific github release.
func uploadReleaseAsset(client gh_client.Client, releaseID int64, organization, repository, filename string) error {
func UploadReleaseAsset(client gh_client.Client, releaseID int64, organization, repository, filename string) error {
fmt.Printf("Uploading %s to %s/%s at release ID %d\n", filename, organization, repository, releaseID)
file, err := os.Open(filename)
if err != nil {
Expand Down Expand Up @@ -83,7 +83,7 @@ func PrepareGithubRelease(client gh_client.Client, semver, organization, asset s
allAssets := strings.Split(asset, ",")

for _, filename := range allAssets {
uploadReleaseAsset(client, *releaseResp.ID, organization, repository, filename)
UploadReleaseAsset(client, *releaseResp.ID, organization, repository, filename)
}
}

Expand Down
50 changes: 49 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
app := cli.NewApp()
app.Name = "Releaser"
app.Usage = "Facilitate the release process of artifacts"
app.Version = "0.2.2"
app.Version = "0.3.0"

// Declare flags common to commands, and pass them in Flags below.
verFlag := cli.StringFlag{
Expand Down Expand Up @@ -63,6 +63,12 @@ func main() {
Usage: "Organization for github releases",
}

releaseIDFlag := cli.StringFlag{
Name: "releaseID",
Value: "",
Usage: "Release to upload assets to. Must already exist.",
}

assetFlag := cli.StringFlag{
Name: "asset",
Value: "",
Expand Down Expand Up @@ -133,6 +139,48 @@ func main() {
fmt.Println(msg)
}

return nil
},
},
{
Name: "add-asset",
Usage: "Add an asset to an existing github release",
Flags: []cli.Flag{githubTokenFlag, githubOrgFlag, usernameFlag, passwordFlag, assetFlag, releaseIDFlag},
Action: func(clictx *cli.Context) error {

client := gh_client.NewClient(&http.Client{})
if clictx.String("token") != "" {
fmt.Println("Using token auth")
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: clictx.String("token")},
)
tc := oauth2.NewClient(ctx, ts)
client = gh_client.NewClient(tc)
} else {
fmt.Println("Using Username/Password auth")
auth := gh_client.BasicAuthTransport{
Username: clictx.String("username"),
Password: clictx.String("password"),
}
client = gh_client.NewClient(&http.Client{Transport: &auth})
}

repository, err := utils.ParseRepoName()
fmt.Println("Uploading asset to:", repository)
fmt.Println("Uploading asset to release:", clictx.Int64("releaseID"))
err = github.UploadReleaseAsset(
*client,
clictx.Int64("releaseID"),
clictx.String("organization"),
repository,
clictx.String("asset"),
)

if err != nil {
fmt.Println("Error uploading release asset:", err)
}

return nil
},
},
Expand Down

0 comments on commit 7e8d4f8

Please sign in to comment.