tasks/github.min
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
#!/usr/bin/env min ; Read files ".env.yml" fread from-yaml :vars "min.yml" fread from-yaml :config "next-release.md" fread escape :release-body "tasks/templates/draft-release.json" fread :draft-release-template config /version :min-version vars /github-token :token draft-release-template ("version" min-version "body" release-body) =% :draft-release-body ; Helper symbols {} "application/vnd.github.v3+json" %Accept "token $#" (token) =% %Authorization :headers ( response to-json "response.json" fwrite response /body from-json :body response /status :status (status 300 >) ( body /message :message status string @status "Error $#: $#" (status message) =% error status int exit ) when ) :handle-errors ( :data data /endpoint :endpoint "api" :subdomain "https://api.github.com/repos/h3rald/min$#" (endpoint) =% :url {} url %url data /method %method (data ?headers) (data /headers %headers) (headers %headers) if (data ?body) (data /body %body) when request :response response /status :status response /body :body handle-errors body from-json ) :gh-req ; Module symbols ( {} "/releases" %endpoint "POST" %method draft-release-body %body gh-req /id string :id ; Save Release ID to min.yml config id %id to-yaml "min.yml" fwrite "Draft release v$# ($#) created successfully" (min-version id) =% notice ) %draft ( config /id :id {} "/releases/$#" (id) =% %endpoint "PATCH" %method draft-release-body %body gh-req /id string :id "Draft release v$# ($#) updated successfully" (min-version id) =% notice ) %update ( config /id :id {} "/releases/$#/assets" (id) =% %endpoint "GET" %method gh-req =assets assets size :total "There are $# assets in release $#" (total min-version) =% notice assets ("- $#" swap cons % notice) foreach assets ) %assets ( config /id :id . ls ("\.zip$" match) filter ( filename :file "Uploading: $#" (file) =% notice file fread :body headers "application/zip" %Content-Type :asset-headers {} "/releases/$#/assets" (id) =% %endpoint asset-headers %headers "POST" %method body %body gh-req ) foreach ) %upload +github-tasks |