From e79e7f293bc8a729b832594ac64dea81ddd57822 Mon Sep 17 00:00:00 2001 From: jackspirou Date: Fri, 15 Jan 2016 10:46:00 -0600 Subject: [PATCH 1/7] adding checksum options --- .drone.sec | 2 +- .drone.yml | 6 +++--- .gitignore | 1 + Makefile | 2 +- checksum.go | 38 ++++++++++++++++++++++++++++++++++++++ main.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ types.go | 1 + 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 checksum.go diff --git a/.drone.sec b/.drone.sec index dbeefaa..3185220 100644 --- a/.drone.sec +++ b/.drone.sec @@ -1 +1 @@ -eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.R-s00gRELUNOzcRuOcoVhqltGWZKP3xQyM-WCqyszETHKr2OVBtN6dfYEEYv1jB5a_4SUs3WDJsjdXieeQsL5sWiDwSzS8cjCeLF3J0XjgmwaPL2EiJn78yHcSOfV-YhHL6fM2zdxKKKgATlKLPGyi6p-O2saL-knl3gnKnO13-ZDWoVIsYVyklFH8UscVEwI4kthGP6rFGLZon46HePvrUxdBcczBZmuqQLGxXmFBr93cX2eJ6QK8K4j6pZwtC5q8ZcrnXwwOoJW_UjZugKuzEHcS_DX_59vb5oJ1MdWhdb8Sm5MBs7nYjRpx900KZzqxG8jzQYuo5PsH4r819GeQ.1BShEZlbixdfZWJB.PuIVYaAJEsbvhqcqTQD7FLQvFDscDvQLorCq7-Gh0LoZBO-5N3XIJVtcEtetW2Dqs6srNhYwEDqryqVp7O3MHlesSuPNy8ulGjCziuqPa5qmCI2ds6gv19RAtXpzot-UobDERID0W9CfL4ZeaiW1AKQmxB52jgNnmTZ3Gqbad4ZPIKBu5BvkIPtAOmbWu7I2SKFvyp8PzD9BMfH_k-Y3_y1f0hrvFYIcl3iuL7z0LW0OAot3aLfeGSuct65Zp5qZuXdUCTCDqYInNPjIcMczZkh3GOKtSm2grRKeEE3ub1_Kmyiw_F8CWGdlYXtOXM47Y9wxmQsKuQFT1WffUW3qdJCXTMvg3ILXJ5AzeuLcX1UkD4cPYg0AfqEEaLAee_0Btfoxpg.Ai8KGIEtc3W1h_vTAZahgg \ No newline at end of file +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.c6isPvujaqNjwxAqXRITLL1l6wgPA-MwKho1OvVLdaQEFeDmhrgqJu8_bVnBrDmFxwFbAc2B7_E7MrhG1q29hvB2GETC2oufCn19n9btwX9zrgQu_M0sAFRAfd7caBRtlEStl2sbAZDIPruwEcIgx1aMNhVUjR4vYhv7kdZ3xIa0zfJJ4zKjaqA2DgtOYP9m_fQgIeyheqryV8P6AZW8l2f2ZUwjpgr3DY4vg8pPpnSJoQKTSjuzV2udNzcCMgNxV9Uu0MpCKP8gABfniUR-A8V2BWhWAXFWhl6i6msarD-ugnIyyUELu7dbagwy6aMWIk5hu4RmYroE6CmfF7I4Bg.NUqxC8J2VPLEH4Fo.Ie-fea-F1Ih185vnwBEyy0pe60cWath-4OOJcb2NHcUSIjN5aD8w6Gads-dUpjdU6uQwDaNJHB6vG5xPGTiy059zKampcJtFWe1lhy4J63l03TkY6LcgDRCot5eml06X69yRv-z1YmAuHvMMJfDATo2oFVNhXgC9CF8zzcScpIJSTKbe5suoSxzLSUNhz94vwgG7hCKZ.Z_R67Wzh1KoOn__PA0Z-VA \ No newline at end of file diff --git a/.drone.yml b/.drone.yml index 18d1f2a..280edd8 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,10 +7,10 @@ build: publish: docker: - username: drone + username: jackspirou password: $$DOCKER_PASS email: $$DOCKER_EMAIL - repo: plugins/drone-github-release + repo: jackspirou/drone-github-release when: branch: master @@ -18,7 +18,7 @@ plugin: name: GitHub Release desc: Publishs files and artifacts to GitHub Releases type: publish - image: plugins/drone-github-release + image: jackspirou/drone-github-release labels: - github - release diff --git a/.gitignore b/.gitignore index 5dc0f42..57507b7 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ _testmain.go *.prof drone-github-release +secrets.yml diff --git a/Makefile b/Makefile index f3d2a4f..23e6cd2 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,4 @@ build: go build -ldflags '-s -w $(LDFLAGS)' docker: - docker build --rm=true -t plugins/drone-github-release . + docker build --rm=true -t jackspirou/drone-github-release . diff --git a/checksum.go b/checksum.go new file mode 100644 index 0000000..786f397 --- /dev/null +++ b/checksum.go @@ -0,0 +1,38 @@ +package main + +import ( + "crypto/md5" + "crypto/sha1" + "crypto/sha256" + "crypto/sha512" + "fmt" + "hash/adler32" + "hash/crc32" + "io" + "io/ioutil" + "strconv" +) + +func checksum(r io.Reader, method string) (string, error) { + b, err := ioutil.ReadAll(r) + if err != nil { + return "", err + } + + switch method { + case "md5": + return fmt.Sprintf("%x", md5.Sum(b)), nil + case "sha1": + return fmt.Sprintf("%x", sha1.Sum(b)), nil + case "sha256": + return fmt.Sprintf("%x", sha256.Sum256(b)), nil + case "sha512": + return fmt.Sprintf("%x", sha512.Sum512(b)), nil + case "adler32": + return strconv.FormatUint(uint64(adler32.Checksum(b)), 10), nil + case "crc32": + return strconv.FormatUint(uint64(crc32.ChecksumIEEE(b)), 10), nil + default: + return "", fmt.Errorf("hashing method %s is not supported", method) + } +} diff --git a/main.go b/main.go index dfe7223..07ce439 100644 --- a/main.go +++ b/main.go @@ -71,6 +71,15 @@ func main() { } } + if len(vargs.Checksums) > 0 { + var err error + files, err = writeChecksums(files, vargs.Checksums) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + } + baseURL, err := url.Parse(vargs.BaseURL) if err != nil { fmt.Printf("Failed to parse base URL\n") @@ -173,3 +182,45 @@ func uploadFiles(client *github.Client, owner string, repo string, id int, files return nil } + +func writeChecksums(files, methods []string) ([]string, error) { + + checksums := make(map[string][]string) + for _, method := range methods { + for _, file := range files { + handle, err := os.Open(file) + if err != nil { + return nil, fmt.Errorf("Failed to read %s artifact: %s", file, err) + } + + hash, err := checksum(handle, method) + if err != nil { + return nil, err + } + + fmt.Println(file) + fmt.Println(method) + fmt.Println(hash) + + checksums[method] = append(checksums[method], hash, file) + } + } + + for method, results := range checksums { + filename := method + "sum.txt" + f, err := os.Create(filename) + if err != nil { + return nil, err + } + + for i := 0; i < len(results); i += 2 { + hash := results[i] + file := results[i+1] + if _, err := f.WriteString(fmt.Sprintf("%s %s\n", hash, file)); err != nil { + return nil, err + } + } + files = append(files, filename) + } + return files, nil +} diff --git a/types.go b/types.go index 9827a6a..2468f67 100644 --- a/types.go +++ b/types.go @@ -6,4 +6,5 @@ type Params struct { UploadURL string `json:"upload_url"` APIKey string `json:"api_key"` Files []string `json:"files"` + Checksums []string `json:"checksums"` } From 5177d35de4886338eb7daf1c0db69bf30d874c24 Mon Sep 17 00:00:00 2001 From: jackspirou Date: Fri, 15 Jan 2016 10:49:37 -0600 Subject: [PATCH 2/7] updating drone sec for docker plugin test --- .drone.sec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.sec b/.drone.sec index 3185220..51b592e 100644 --- a/.drone.sec +++ b/.drone.sec @@ -1 +1 @@ -eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.c6isPvujaqNjwxAqXRITLL1l6wgPA-MwKho1OvVLdaQEFeDmhrgqJu8_bVnBrDmFxwFbAc2B7_E7MrhG1q29hvB2GETC2oufCn19n9btwX9zrgQu_M0sAFRAfd7caBRtlEStl2sbAZDIPruwEcIgx1aMNhVUjR4vYhv7kdZ3xIa0zfJJ4zKjaqA2DgtOYP9m_fQgIeyheqryV8P6AZW8l2f2ZUwjpgr3DY4vg8pPpnSJoQKTSjuzV2udNzcCMgNxV9Uu0MpCKP8gABfniUR-A8V2BWhWAXFWhl6i6msarD-ugnIyyUELu7dbagwy6aMWIk5hu4RmYroE6CmfF7I4Bg.NUqxC8J2VPLEH4Fo.Ie-fea-F1Ih185vnwBEyy0pe60cWath-4OOJcb2NHcUSIjN5aD8w6Gads-dUpjdU6uQwDaNJHB6vG5xPGTiy059zKampcJtFWe1lhy4J63l03TkY6LcgDRCot5eml06X69yRv-z1YmAuHvMMJfDATo2oFVNhXgC9CF8zzcScpIJSTKbe5suoSxzLSUNhz94vwgG7hCKZ.Z_R67Wzh1KoOn__PA0Z-VA \ No newline at end of file +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.ENVLhyifwZ-n9nN_8SKGRRI-esqsXjSfnFmzEAazMFeBWhDln0IXi3EAPGpJUmT9kkqXIqtqUgQ9H_nh2y274RrBcUs2Ch9E4f1wDYHgbenG1b8AkJWED4g5bre-r0huxuq2LhW9UutiZU17Zz7An0U9IKhucGtPAgBd7NIZjR0b2ioUp_jMkrOBnXvKuxzeYjDC2p0m8yvIRKahtlRPhQRvh8raXV890PZuH4vGJOpDymAiX1jZJLMSjN1ODj5U100RLugfIQUKi8b4aCas0hHHSQJcxnZgWDkVZEFiJct-VcWPUahUW99ogyH7v5dwjxIe9GeGHfr0ZO0KL8MxYg.se4-CBJA0XtQYbPO.arFXgGSOO_-UKMx5UnqozPEOkZEuOJyTQkJX9gpoyMeeK22bDJfpi9fl99K9aKRfrOeo37JHpkIyDfqWLo0548G73KaH7WK4U8gTHN6RvwsAvtP6UY3eUgJeQaC1F6zSz0N2tyr0SiH6NxeLNsIzFrUtLXi1kN_ocSUwWgnLEQROw_h9MiH_YWlRt6cB4Gpljs1HF9-g.V6GluvSUzQGIiqJSHXVoLQ \ No newline at end of file From f7b84f74078e4ae4a3fa081a5785412d1a1c8870 Mon Sep 17 00:00:00 2001 From: jackspirou Date: Fri, 15 Jan 2016 11:10:26 -0600 Subject: [PATCH 3/7] fixing upload endpoint bug --- main.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/main.go b/main.go index 07ce439..d101a85 100644 --- a/main.go +++ b/main.go @@ -86,7 +86,7 @@ func main() { os.Exit(1) } - uploadURL, err := url.Parse(vargs.BaseURL) + uploadURL, err := url.Parse(vargs.UploadURL) if err != nil { fmt.Printf("Failed to parse upload URL\n") os.Exit(1) @@ -198,10 +198,6 @@ func writeChecksums(files, methods []string) ([]string, error) { return nil, err } - fmt.Println(file) - fmt.Println(method) - fmt.Println(hash) - checksums[method] = append(checksums[method], hash, file) } } From 0922e8ea4cbd0997f06c24af283c22ebdc11cd3b Mon Sep 17 00:00:00 2001 From: jackspirou Date: Fri, 15 Jan 2016 11:29:12 -0600 Subject: [PATCH 4/7] updating documentation for checksum usage --- .drone.sec | 2 +- .drone.yml | 6 +++--- .gitignore | 1 - DOCS.md | 8 ++++++++ Makefile | 2 +- README.md | 16 ++++++++++++++++ 6 files changed, 29 insertions(+), 6 deletions(-) diff --git a/.drone.sec b/.drone.sec index 51b592e..e9b2e88 100644 --- a/.drone.sec +++ b/.drone.sec @@ -1 +1 @@ -eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.ENVLhyifwZ-n9nN_8SKGRRI-esqsXjSfnFmzEAazMFeBWhDln0IXi3EAPGpJUmT9kkqXIqtqUgQ9H_nh2y274RrBcUs2Ch9E4f1wDYHgbenG1b8AkJWED4g5bre-r0huxuq2LhW9UutiZU17Zz7An0U9IKhucGtPAgBd7NIZjR0b2ioUp_jMkrOBnXvKuxzeYjDC2p0m8yvIRKahtlRPhQRvh8raXV890PZuH4vGJOpDymAiX1jZJLMSjN1ODj5U100RLugfIQUKi8b4aCas0hHHSQJcxnZgWDkVZEFiJct-VcWPUahUW99ogyH7v5dwjxIe9GeGHfr0ZO0KL8MxYg.se4-CBJA0XtQYbPO.arFXgGSOO_-UKMx5UnqozPEOkZEuOJyTQkJX9gpoyMeeK22bDJfpi9fl99K9aKRfrOeo37JHpkIyDfqWLo0548G73KaH7WK4U8gTHN6RvwsAvtP6UY3eUgJeQaC1F6zSz0N2tyr0SiH6NxeLNsIzFrUtLXi1kN_ocSUwWgnLEQROw_h9MiH_YWlRt6cB4Gpljs1HF9-g.V6GluvSUzQGIiqJSHXVoLQ \ No newline at end of file +eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.R-s00gRELUNOzcRuOcoVhqltGWZKP3xQyM-WCqyszETHKr2OVBtN6dfYEEYv1jB5a_4SUs3WDJsjdXieeQsL5sWiDwSzS8cjCeLF3J0XjgmwaPL2EiJn78yHcSOfV-YhHL6fM2zdxKKKgATlKLPGyi6p-O2saL-knl3gnKnO13-ZDWoVIsYVyklFH8UscVEwI4kthGP6rFGLZon46HePvrUxdBcczBZmuqQLGxXmFBr93cX2eJ6QK8K4j6pZwtC5q8ZcrnXwwOoJW_UjZugKuzEHcS_DX_59vb5oJ1MdWhdb8Sm5MBs7nYjRpx900KZzqxG8jzQYuo5PsH4r819GeQ.1BShEZlbixdfZWJB.PuIVYaAJEsbvhqcqTQD7FLQvFDscDvQLorCq7-Gh0LoZBO-5N3XIJVtcEtetW2Dqs6srNhYwEDqryqVp7O3MHlesSuPNy8ulGjCziuqPa5qmCI2ds6gv19RAtXpzot-UobDERID0W9CfL4ZeaiW1AKQmxB52jgNnmTZ3Gqbad4ZPIKBu5BvkIPtAOmbWu7I2SKFvyp8PzD9BMfH_k-Y3_y1f0hrvFYIcl3iuL7z0LW0OAot3aLfeGSuct65Zp5qZuXdUCTCDqYInNPjIcMczZkh3GOKtSm2grRKeEE3ub1_Kmyiw_F8CWGdlYXtOXM47Y9wxmQsKuQFT1WffUW3qdJCXTMvg3ILXJ5AzeuLcX1UkD4cPYg0AfqEEaLAee_0Btfoxpg.Ai8KGIEtc3W1h_vTAZahgg diff --git a/.drone.yml b/.drone.yml index 280edd8..18d1f2a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,10 +7,10 @@ build: publish: docker: - username: jackspirou + username: drone password: $$DOCKER_PASS email: $$DOCKER_EMAIL - repo: jackspirou/drone-github-release + repo: plugins/drone-github-release when: branch: master @@ -18,7 +18,7 @@ plugin: name: GitHub Release desc: Publishs files and artifacts to GitHub Releases type: publish - image: jackspirou/drone-github-release + image: plugins/drone-github-release labels: - github - release diff --git a/.gitignore b/.gitignore index 57507b7..5dc0f42 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,3 @@ _testmain.go *.prof drone-github-release -secrets.yml diff --git a/DOCS.md b/DOCS.md index 7ecd3f7..84537c5 100644 --- a/DOCS.md +++ b/DOCS.md @@ -3,6 +3,7 @@ can override the default configuration with the following parameters: * `api_key` - GitHub oauth token with public_repo or repo permission * `files` - Files to upload to GitHub Release, globs are allowed +* `checksums` - Checksum hashes to include in your GitHub release for all files specified. Supported hash methods include md5, sha1, sha256, sha512, adler32, and crc32. * `base_url` - GitHub base URL, only required for GHE * `upload_url` - GitHub upload URL, only required for GHE @@ -14,4 +15,11 @@ publish: api_key: my_github_api_key files: - dist/* + checksums: + - md5 + - sha1 + - sha256 + - sha512 + - adler32 + - crc32 ``` diff --git a/Makefile b/Makefile index 23e6cd2..91311a8 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,4 @@ build: go build -ldflags '-s -w $(LDFLAGS)' docker: - docker build --rm=true -t jackspirou/drone-github-release . + docker build --rm=true -t drone/drone-github-release . diff --git a/README.md b/README.md index 6f9858f..7c7a579 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,14 @@ Drone plugin for publishing GitHub releases "files": [ "dist/*.txt", "dist/other-file" + ], + "checksums": [ + "md5", + "sha1", + "sha256", + "sha512", + "adler32", + "crc32" ] } } @@ -71,6 +79,14 @@ docker run -i plugins/drone-github-release < Date: Fri, 15 Jan 2016 11:30:36 -0600 Subject: [PATCH 5/7] fix typo --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 91311a8..f3d2a4f 100644 --- a/Makefile +++ b/Makefile @@ -22,4 +22,4 @@ build: go build -ldflags '-s -w $(LDFLAGS)' docker: - docker build --rm=true -t drone/drone-github-release . + docker build --rm=true -t plugins/drone-github-release . From fcfb446e4c88659a14855b7362bfc1a59984d5db Mon Sep 17 00:00:00 2001 From: jackspirou Date: Fri, 15 Jan 2016 15:30:59 -0600 Subject: [PATCH 6/7] updating checksums to checksum and using drone.StringSlice instead of []string --- DOCS.md | 15 +++++++++++++-- README.md | 4 ++-- main.go | 4 ++-- types.go | 12 +++++++----- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/DOCS.md b/DOCS.md index 84537c5..e5badea 100644 --- a/DOCS.md +++ b/DOCS.md @@ -3,7 +3,7 @@ can override the default configuration with the following parameters: * `api_key` - GitHub oauth token with public_repo or repo permission * `files` - Files to upload to GitHub Release, globs are allowed -* `checksums` - Checksum hashes to include in your GitHub release for all files specified. Supported hash methods include md5, sha1, sha256, sha512, adler32, and crc32. +* `checksum` - Checksum takes hash methods to include in your GitHub release for the files specified. Supported hash methods include md5, sha1, sha256, sha512, adler32, and crc32. * `base_url` - GitHub base URL, only required for GHE * `upload_url` - GitHub upload URL, only required for GHE @@ -15,7 +15,18 @@ publish: api_key: my_github_api_key files: - dist/* - checksums: + checksum: sha1 +``` + +or + +```yaml +publish: + github_release: + api_key: my_github_api_key + files: + - dist/* + checksum: - md5 - sha1 - sha256 diff --git a/README.md b/README.md index 7c7a579..56710a4 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Drone plugin for publishing GitHub releases "dist/*.txt", "dist/other-file" ], - "checksums": [ + "checksum": [ "md5", "sha1", "sha256", @@ -80,7 +80,7 @@ docker run -i plugins/drone-github-release < 0 { + if vargs.Checksum.Len() > 0 { var err error - files, err = writeChecksums(files, vargs.Checksums) + files, err = writeChecksums(files, vargs.Checksum.Slice()) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/types.go b/types.go index 2468f67..0dc5e86 100644 --- a/types.go +++ b/types.go @@ -1,10 +1,12 @@ package main +import "github.com/drone/drone-go/drone" + // Params are the parameters that the GitHub Release plugin can parse. type Params struct { - BaseURL string `json:"base_url"` - UploadURL string `json:"upload_url"` - APIKey string `json:"api_key"` - Files []string `json:"files"` - Checksums []string `json:"checksums"` + BaseURL string `json:"base_url"` + UploadURL string `json:"upload_url"` + APIKey string `json:"api_key"` + Files []string `json:"files"` + Checksum drone.StringSlice `json:"checksum"` } From d4f663cf8fd78bf0a0cfd058feee6e48b72e84a0 Mon Sep 17 00:00:00 2001 From: jackspirou Date: Fri, 15 Jan 2016 16:02:12 -0600 Subject: [PATCH 7/7] using StringSlice instead of []string for Files --- DOCS.md | 4 ++-- main.go | 2 +- types.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DOCS.md b/DOCS.md index e5badea..c39d797 100644 --- a/DOCS.md +++ b/DOCS.md @@ -13,8 +13,7 @@ Sample configuration: publish: github_release: api_key: my_github_api_key - files: - - dist/* + files: dist/* checksum: sha1 ``` @@ -26,6 +25,7 @@ publish: api_key: my_github_api_key files: - dist/* + - bin/binary.exe checksum: - md5 - sha1 diff --git a/main.go b/main.go index 7c28b98..67c4b76 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,7 @@ func main() { } var files []string - for _, glob := range vargs.Files { + for _, glob := range vargs.Files.Slice() { globed, err := filepath.Glob(glob) if err != nil { fmt.Printf("Failed to glob %s\n", glob) diff --git a/types.go b/types.go index 0dc5e86..295d5f7 100644 --- a/types.go +++ b/types.go @@ -7,6 +7,6 @@ type Params struct { BaseURL string `json:"base_url"` UploadURL string `json:"upload_url"` APIKey string `json:"api_key"` - Files []string `json:"files"` + Files drone.StringSlice `json:"files"` Checksum drone.StringSlice `json:"checksum"` }