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oVIsYVyklFH8UscVEwI4kthGP6rFGLZon46HePvrUxdBcczBZmuqQLGxXmFBr93cX2eJ6QK8K4j6pZwtC5q8ZcrnXwwOoJW_UjZugKuzEHcS_DX_59vb5oJ1MdWhdb8Sm5MBs7nYjRpx900KZzqxG8jzQYuo5PsH4r819GeQ.1BShEZlbixdfZWJB.PuIVYaAJEsbvhqcqTQD7FLQvFDscDvQLorCq7-Gh0LoZBO-5N3XIJVtcEtetW2Dqs6srNhYwEDqryqVp7O3MHlesSuPNy8ulGjCziuqPa5qmCI2ds6gv19RAtXpzot-UobDERID0W9CfL4ZeaiW1AKQmxB52jgNnmTZ3Gqbad4ZPIKBu5BvkIPtAOmbWu7I2SKFvyp8PzD9BMfH_k-Y3_y1f0hrvFYIcl3iuL7z0LW0OAot3aLfeGSuct65Zp5qZuXdUCTCDqYInNPjIcMczZkh3GOKtSm2grRKeEE3ub1_Kmyiw_F8CWGdlYXtOXM47Y9wxmQsKuQFT1WffUW3qdJCXTMvg3ILXJ5AzeuLcX1UkD4cPYg0AfqEEaLAee_0Btfoxpg.Ai8KGIEtc3W1h_vTAZahgg
|
||||||
|
19
DOCS.md
19
DOCS.md
@ -3,15 +3,34 @@ can override the default configuration with the following parameters:
|
|||||||
|
|
||||||
* `api_key` - GitHub oauth token with public_repo or repo permission
|
* `api_key` - GitHub oauth token with public_repo or repo permission
|
||||||
* `files` - Files to upload to GitHub Release, globs are allowed
|
* `files` - Files to upload to GitHub Release, globs are allowed
|
||||||
|
* `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
|
* `base_url` - GitHub base URL, only required for GHE
|
||||||
* `upload_url` - GitHub upload URL, only required for GHE
|
* `upload_url` - GitHub upload URL, only required for GHE
|
||||||
|
|
||||||
Sample configuration:
|
Sample configuration:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
publish:
|
||||||
|
github_release:
|
||||||
|
api_key: my_github_api_key
|
||||||
|
files: dist/*
|
||||||
|
checksum: sha1
|
||||||
|
```
|
||||||
|
|
||||||
|
or
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
publish:
|
publish:
|
||||||
github_release:
|
github_release:
|
||||||
api_key: my_github_api_key
|
api_key: my_github_api_key
|
||||||
files:
|
files:
|
||||||
- dist/*
|
- dist/*
|
||||||
|
- bin/binary.exe
|
||||||
|
checksum:
|
||||||
|
- md5
|
||||||
|
- sha1
|
||||||
|
- sha256
|
||||||
|
- sha512
|
||||||
|
- adler32
|
||||||
|
- crc32
|
||||||
```
|
```
|
||||||
|
16
README.md
16
README.md
@ -31,6 +31,14 @@ Drone plugin for publishing GitHub releases
|
|||||||
"files": [
|
"files": [
|
||||||
"dist/*.txt",
|
"dist/*.txt",
|
||||||
"dist/other-file"
|
"dist/other-file"
|
||||||
|
],
|
||||||
|
"checksum": [
|
||||||
|
"md5",
|
||||||
|
"sha1",
|
||||||
|
"sha256",
|
||||||
|
"sha512",
|
||||||
|
"adler32",
|
||||||
|
"crc32"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,6 +79,14 @@ docker run -i plugins/drone-github-release <<EOF
|
|||||||
"files": [
|
"files": [
|
||||||
"dist/*.txt",
|
"dist/*.txt",
|
||||||
"dist/other-file"
|
"dist/other-file"
|
||||||
|
],
|
||||||
|
"checksum": [
|
||||||
|
"md5",
|
||||||
|
"sha1",
|
||||||
|
"sha256",
|
||||||
|
"sha512",
|
||||||
|
"adler32",
|
||||||
|
"crc32"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
checksum.go
Normal file
38
checksum.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
51
main.go
51
main.go
@ -60,7 +60,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var files []string
|
var files []string
|
||||||
for _, glob := range vargs.Files {
|
for _, glob := range vargs.Files.Slice() {
|
||||||
globed, err := filepath.Glob(glob)
|
globed, err := filepath.Glob(glob)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to glob %s\n", glob)
|
fmt.Printf("Failed to glob %s\n", glob)
|
||||||
@ -71,13 +71,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if vargs.Checksum.Len() > 0 {
|
||||||
|
var err error
|
||||||
|
files, err = writeChecksums(files, vargs.Checksum.Slice())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
baseURL, err := url.Parse(vargs.BaseURL)
|
baseURL, err := url.Parse(vargs.BaseURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to parse base URL\n")
|
fmt.Printf("Failed to parse base URL\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadURL, err := url.Parse(vargs.BaseURL)
|
uploadURL, err := url.Parse(vargs.UploadURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to parse upload URL\n")
|
fmt.Printf("Failed to parse upload URL\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -173,3 +182,41 @@ func uploadFiles(client *github.Client, owner string, repo string, id int, files
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
11
types.go
11
types.go
@ -1,9 +1,12 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
import "github.com/drone/drone-go/drone"
|
||||||
|
|
||||||
// Params are the parameters that the GitHub Release plugin can parse.
|
// Params are the parameters that the GitHub Release plugin can parse.
|
||||||
type Params struct {
|
type Params struct {
|
||||||
BaseURL string `json:"base_url"`
|
BaseURL string `json:"base_url"`
|
||||||
UploadURL string `json:"upload_url"`
|
UploadURL string `json:"upload_url"`
|
||||||
APIKey string `json:"api_key"`
|
APIKey string `json:"api_key"`
|
||||||
Files []string `json:"files"`
|
Files drone.StringSlice `json:"files"`
|
||||||
|
Checksum drone.StringSlice `json:"checksum"`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user