├── .dockerignore ├── .drone.star ├── .drone.yml ├── .github ├── issue_template.md ├── pull_request_template.md └── settings.yml ├── .gitignore ├── .harness ├── eventPR.yaml ├── eventPush.yaml ├── eventTag.yaml └── harness.yaml ├── LICENSE ├── README.md ├── cmd └── drone-github-release │ ├── config.go │ └── main.go ├── docker ├── Dockerfile.linux.amd64 ├── Dockerfile.linux.arm64 ├── Dockerfile.windows.1809 ├── Dockerfile.windows.ltsc2022 └── manifest.tmpl ├── go.mod ├── go.sum ├── plugin ├── impl.go ├── impl_test.go ├── plugin.go ├── plugin_test.go ├── release.go └── utils.go └── renovate.json /.dockerignore: -------------------------------------------------------------------------------- 1 | * 2 | !release/ 3 | -------------------------------------------------------------------------------- /.drone.star: -------------------------------------------------------------------------------- 1 | def main(ctx): 2 | before = testing(ctx) 3 | 4 | stages = [ 5 | linux(ctx, "amd64"), 6 | linux(ctx, "arm64"), 7 | windows(ctx, "1909"), 8 | windows(ctx, "1903"), 9 | windows(ctx, "1809"), 10 | ] 11 | 12 | after = manifest(ctx) 13 | 14 | for b in before: 15 | for s in stages: 16 | s["depends_on"].append(b["name"]) 17 | 18 | for s in stages: 19 | for a in after: 20 | a["depends_on"].append(s["name"]) 21 | 22 | return before + stages + after 23 | 24 | def testing(ctx): 25 | return [{ 26 | "kind": "pipeline", 27 | "type": "docker", 28 | "name": "testing", 29 | "platform": { 30 | "os": "linux", 31 | "arch": "amd64", 32 | }, 33 | "steps": [ 34 | { 35 | "name": "staticcheck", 36 | "image": "golang:1.18", 37 | "pull": "always", 38 | "commands": [ 39 | "go get honnef.co/go/tools/cmd/staticcheck", 40 | "go run honnef.co/go/tools/cmd/staticcheck ./...", 41 | ], 42 | "volumes": [ 43 | { 44 | "name": "gopath", 45 | "path": "/go", 46 | }, 47 | ], 48 | }, 49 | { 50 | "name": "lint", 51 | "image": "golang:1.18", 52 | "commands": [ 53 | "go get golang.org/x/lint/golint", 54 | "go run golang.org/x/lint/golint -set_exit_status ./...", 55 | ], 56 | "volumes": [ 57 | { 58 | "name": "gopath", 59 | "path": "/go", 60 | }, 61 | ], 62 | }, 63 | { 64 | "name": "vet", 65 | "image": "golang:1.18", 66 | "commands": [ 67 | "go vet ./...", 68 | ], 69 | "volumes": [ 70 | { 71 | "name": "gopath", 72 | "path": "/go", 73 | }, 74 | ], 75 | }, 76 | { 77 | "name": "test", 78 | "image": "golang:1.18", 79 | "commands": [ 80 | "go test -cover ./...", 81 | ], 82 | "volumes": [ 83 | { 84 | "name": "gopath", 85 | "path": "/go", 86 | }, 87 | ], 88 | }, 89 | ], 90 | "volumes": [ 91 | { 92 | "name": "gopath", 93 | "temp": {}, 94 | }, 95 | ], 96 | "trigger": { 97 | "ref": [ 98 | "refs/heads/master", 99 | "refs/tags/**", 100 | "refs/pull/**", 101 | ], 102 | }, 103 | }] 104 | 105 | def linux(ctx, arch): 106 | if ctx.build.event == "tag": 107 | build = [ 108 | 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-github-release ./cmd/drone-github-release' % (ctx.build.ref.replace("refs/tags/v", ""), arch), 109 | ] 110 | else: 111 | build = [ 112 | 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-github-release ./cmd/drone-github-release' % (ctx.build.commit[0:8], arch), 113 | ] 114 | 115 | steps = [ 116 | { 117 | "name": "environment", 118 | "image": "golang:1.18", 119 | "pull": "always", 120 | "environment": { 121 | "CGO_ENABLED": "0", 122 | }, 123 | "commands": [ 124 | "go version", 125 | "go env", 126 | ], 127 | }, 128 | { 129 | "name": "build", 130 | "image": "golang:1.18", 131 | "environment": { 132 | "CGO_ENABLED": "0", 133 | }, 134 | "commands": build, 135 | }, 136 | { 137 | "name": "executable", 138 | "image": "golang:1.18", 139 | "commands": [ 140 | "./release/linux/%s/drone-github-release --help" % (arch), 141 | ], 142 | }, 143 | ] 144 | 145 | if ctx.build.event != "pull_request": 146 | steps.append({ 147 | "name": "docker", 148 | "image": "plugins/docker", 149 | "settings": { 150 | "dockerfile": "docker/Dockerfile.linux.%s" % (arch), 151 | "repo": "plugins/github-release", 152 | "username": { 153 | "from_secret": "docker_username", 154 | }, 155 | "password": { 156 | "from_secret": "docker_password", 157 | }, 158 | "auto_tag": True, 159 | "auto_tag_suffix": "linux-%s" % (arch), 160 | }, 161 | }) 162 | 163 | return { 164 | "kind": "pipeline", 165 | "type": "docker", 166 | "name": "linux-%s" % (arch), 167 | "platform": { 168 | "os": "linux", 169 | "arch": arch, 170 | }, 171 | "steps": steps, 172 | "depends_on": [], 173 | "trigger": { 174 | "ref": [ 175 | "refs/heads/master", 176 | "refs/tags/**", 177 | "refs/pull/**", 178 | ], 179 | }, 180 | } 181 | 182 | def windows(ctx, version): 183 | docker = [ 184 | "echo $env:PASSWORD | docker login --username $env:USERNAME --password-stdin", 185 | ] 186 | 187 | if ctx.build.event == "tag": 188 | build = [ 189 | 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release' % (ctx.build.ref.replace("refs/tags/v", "")), 190 | ] 191 | 192 | docker = docker + [ 193 | "docker build --pull -f docker/Dockerfile.windows.%s -t plugins/github-release:%s-windows-%s-amd64 ." % (version, ctx.build.ref.replace("refs/tags/v", ""), version), 194 | "docker run --rm plugins/github-release:%s-windows-%s-amd64 --help" % (ctx.build.ref.replace("refs/tags/v", ""), version), 195 | "docker push plugins/github-release:%s-windows-%s-amd64" % (ctx.build.ref.replace("refs/tags/v", ""), version), 196 | ] 197 | else: 198 | build = [ 199 | 'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release' % (ctx.build.commit[0:8]), 200 | ] 201 | 202 | docker = docker + [ 203 | "docker build --pull -f docker/Dockerfile.windows.%s -t plugins/github-release:windows-%s-amd64 ." % (version, version), 204 | "docker run --rm plugins/github-release:windows-%s-amd64 --help" % (version), 205 | "docker push plugins/github-release:windows-%s-amd64" % (version), 206 | ] 207 | 208 | return { 209 | "kind": "pipeline", 210 | "type": "ssh", 211 | "name": "windows-%s" % (version), 212 | "platform": { 213 | "os": "windows", 214 | }, 215 | "server": { 216 | "host": { 217 | "from_secret": "windows_server_%s" % (version), 218 | }, 219 | "user": { 220 | "from_secret": "windows_username", 221 | }, 222 | "password": { 223 | "from_secret": "windows_password", 224 | }, 225 | }, 226 | "steps": [ 227 | { 228 | "name": "environment", 229 | "environment": { 230 | "CGO_ENABLED": "0", 231 | }, 232 | "commands": [ 233 | "go version", 234 | "go env", 235 | ], 236 | }, 237 | { 238 | "name": "build", 239 | "environment": { 240 | "CGO_ENABLED": "0", 241 | }, 242 | "commands": build, 243 | }, 244 | { 245 | "name": "executable", 246 | "commands": [ 247 | "./release/windows/amd64/drone-github-release.exe --help", 248 | ], 249 | }, 250 | { 251 | "name": "docker", 252 | "environment": { 253 | "USERNAME": { 254 | "from_secret": "docker_username", 255 | }, 256 | "PASSWORD": { 257 | "from_secret": "docker_password", 258 | }, 259 | }, 260 | "commands": docker, 261 | }, 262 | ], 263 | "depends_on": [], 264 | "trigger": { 265 | "ref": [ 266 | "refs/heads/master", 267 | "refs/tags/**", 268 | ], 269 | }, 270 | } 271 | 272 | def manifest(ctx): 273 | return [{ 274 | "kind": "pipeline", 275 | "type": "docker", 276 | "name": "manifest", 277 | "steps": [ 278 | { 279 | "name": "manifest", 280 | "image": "plugins/manifest", 281 | "settings": { 282 | "auto_tag": "true", 283 | "username": { 284 | "from_secret": "docker_username", 285 | }, 286 | "password": { 287 | "from_secret": "docker_password", 288 | }, 289 | "spec": "docker/manifest.tmpl", 290 | "ignore_missing": "true", 291 | }, 292 | }, 293 | ], 294 | "depends_on": [], 295 | "trigger": { 296 | "ref": [ 297 | "refs/heads/master", 298 | "refs/tags/**", 299 | ], 300 | }, 301 | }] 302 | -------------------------------------------------------------------------------- /.drone.yml: -------------------------------------------------------------------------------- 1 | kind: pipeline 2 | type: vm 3 | name: testing 4 | platform: 5 | os: linux 6 | arch: amd64 7 | pool: 8 | use: ubuntu 9 | 10 | steps: 11 | - name: lint 12 | image: golang:1.20 13 | pull: always 14 | commands: 15 | - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 16 | - golangci-lint version 17 | - golangci-lint run 18 | volumes: 19 | - name: gopath 20 | path: "/go" 21 | - name: test 22 | image: golang:1.20 23 | commands: 24 | - go test -cover ./... 25 | volumes: 26 | - name: gopath 27 | path: "/go" 28 | volumes: 29 | - name: gopath 30 | temp: {} 31 | trigger: 32 | ref: 33 | - refs/heads/master 34 | - refs/tags/** 35 | - refs/pull/** 36 | 37 | --- 38 | kind: pipeline 39 | type: vm 40 | name: linux-amd64 41 | platform: 42 | os: linux 43 | arch: amd64 44 | pool: 45 | use: ubuntu 46 | 47 | steps: 48 | - name: environment 49 | image: golang:1.20 50 | pull: always 51 | environment: 52 | CGO_ENABLED: "0" 53 | commands: 54 | - go version 55 | - go env 56 | - name: build 57 | image: golang:1.20 58 | environment: 59 | CGO_ENABLED: "0" 60 | commands: 61 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-github-release ./cmd/drone-github-release 62 | - name: executable 63 | image: golang:1.20 64 | commands: 65 | - ./release/linux/amd64/drone-github-release --help 66 | - name: docker 67 | image: plugins/docker 68 | settings: 69 | dockerfile: docker/Dockerfile.linux.amd64 70 | repo: plugins/github-release 71 | username: 72 | from_secret: docker_username 73 | password: 74 | from_secret: docker_password 75 | auto_tag: true 76 | auto_tag_suffix: linux-amd64 77 | when: 78 | ref: 79 | - refs/heads/master 80 | - refs/tags/** 81 | depends_on: 82 | - testing 83 | trigger: 84 | ref: 85 | - refs/heads/master 86 | - refs/tags/** 87 | - refs/pull/** 88 | 89 | --- 90 | kind: pipeline 91 | type: vm 92 | name: linux-arm64 93 | platform: 94 | os: linux 95 | arch: amd64 96 | pool: 97 | use: ubuntu_arm64 98 | 99 | steps: 100 | - name: environment 101 | image: golang:1.20 102 | pull: always 103 | environment: 104 | CGO_ENABLED: "0" 105 | commands: 106 | - go version 107 | - go env 108 | - name: build 109 | image: golang:1.20 110 | environment: 111 | CGO_ENABLED: "0" 112 | commands: 113 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-github-release ./cmd/drone-github-release 114 | - name: executable 115 | image: golang:1.20 116 | commands: 117 | - ./release/linux/arm64/drone-github-release --help 118 | - name: docker 119 | image: plugins/docker 120 | settings: 121 | dockerfile: docker/Dockerfile.linux.arm64 122 | repo: plugins/github-release 123 | username: 124 | from_secret: docker_username 125 | password: 126 | from_secret: docker_password 127 | auto_tag: true 128 | auto_tag_suffix: linux-arm64 129 | when: 130 | ref: 131 | - refs/heads/master 132 | - refs/tags/** 133 | depends_on: 134 | - testing 135 | trigger: 136 | ref: 137 | - refs/heads/master 138 | - refs/tags/** 139 | - refs/pull/** 140 | 141 | --- 142 | kind: pipeline 143 | type: vm 144 | name: windows-1809 145 | platform: 146 | os: windows 147 | arch: amd64 148 | pool: 149 | use: windows 150 | 151 | steps: 152 | - name: environment 153 | image: golang:1.20 154 | pull: always 155 | environment: 156 | CGO_ENABLED: "0" 157 | commands: 158 | - go version 159 | - go env 160 | - name: build 161 | image: golang:1.20 162 | environment: 163 | CGO_ENABLED: "0" 164 | commands: 165 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release 166 | - name: executable 167 | image: golang:1.20 168 | commands: 169 | - ./release/windows/amd64/drone-github-release.exe --help 170 | - name: docker 171 | image: plugins/docker 172 | settings: 173 | dockerfile: docker/Dockerfile.windows.1809 174 | repo: plugins/github-release 175 | username: 176 | from_secret: docker_username 177 | password: 178 | from_secret: docker_password 179 | auto_tag: true 180 | auto_tag_suffix: windows-1809-amd64 181 | daemon_off: true 182 | purge: false 183 | when: 184 | ref: 185 | - refs/heads/master 186 | - refs/tags/** 187 | depends_on: 188 | - testing 189 | trigger: 190 | ref: 191 | - refs/heads/master 192 | - refs/tags/** 193 | - refs/pull/** 194 | 195 | --- 196 | kind: pipeline 197 | type: vm 198 | name: windows-ltsc2022 199 | platform: 200 | os: windows 201 | arch: amd64 202 | pool: 203 | use: windows-2022 204 | 205 | steps: 206 | - name: environment 207 | image: golang:1.20 208 | pull: always 209 | environment: 210 | CGO_ENABLED: "0" 211 | commands: 212 | - go version 213 | - go env 214 | - name: build 215 | image: golang:1.20 216 | environment: 217 | CGO_ENABLED: "0" 218 | commands: 219 | - go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release 220 | - name: executable 221 | image: golang:1.20 222 | commands: 223 | - ./release/windows/amd64/drone-github-release.exe --help 224 | - name: docker 225 | image: plugins/docker 226 | settings: 227 | dockerfile: docker/Dockerfile.windows.ltsc2022 228 | repo: plugins/github-release 229 | username: 230 | from_secret: docker_username 231 | password: 232 | from_secret: docker_password 233 | auto_tag: true 234 | auto_tag_suffix: windows-ltsc2022-amd64 235 | daemon_off: true 236 | purge: false 237 | when: 238 | ref: 239 | - refs/heads/master 240 | - refs/tags/** 241 | depends_on: 242 | - testing 243 | trigger: 244 | ref: 245 | - refs/heads/master 246 | - refs/tags/** 247 | - refs/pull/** 248 | 249 | --- 250 | kind: pipeline 251 | type: vm 252 | name: manifest 253 | platform: 254 | os: linux 255 | arch: amd64 256 | pool: 257 | use: ubuntu 258 | 259 | steps: 260 | - name: manifest 261 | image: plugins/manifest 262 | settings: 263 | auto_tag: "true" 264 | username: 265 | from_secret: docker_username 266 | password: 267 | from_secret: docker_password 268 | spec: docker/manifest.tmpl 269 | ignore_missing: true 270 | depends_on: 271 | - linux-amd64 272 | - linux-arm64 273 | - windows-1809 274 | - windows-ltsc2022 275 | trigger: 276 | ref: 277 | - refs/heads/master 278 | - refs/tags/** 279 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | 10 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/drone-plugins/drone-github-release/f2907e9c78cac301d3847a3f8638f6e2dc7e1072/.github/pull_request_template.md -------------------------------------------------------------------------------- /.github/settings.yml: -------------------------------------------------------------------------------- 1 | repository: 2 | name: drone-github-release 3 | description: Drone plugin for creating and tagging GitHub releases 4 | homepage: http://plugins.drone.io/drone-plugins/drone-github-release 5 | topics: drone, drone-plugin 6 | 7 | private: false 8 | has_issues: true 9 | has_wiki: false 10 | has_downloads: false 11 | 12 | default_branch: master 13 | 14 | allow_squash_merge: true 15 | allow_merge_commit: true 16 | allow_rebase_merge: true 17 | 18 | labels: 19 | - name: bug 20 | color: d73a4a 21 | description: Something isn't working 22 | - name: duplicate 23 | color: cfd3d7 24 | description: This issue or pull request already exists 25 | - name: enhancement 26 | color: a2eeef 27 | description: New feature or request 28 | - name: good first issue 29 | color: 7057ff 30 | description: Good for newcomers 31 | - name: help wanted 32 | color: 008672 33 | description: Extra attention is needed 34 | - name: invalid 35 | color: e4e669 36 | description: This doesn't seem right 37 | - name: question 38 | color: d876e3 39 | description: Further information is requested 40 | - name: renovate 41 | color: e99695 42 | description: Automated action from Renovate 43 | - name: wontfix 44 | color: ffffff 45 | description: This will not be worked on 46 | 47 | teams: 48 | - name: Admins 49 | permission: admin 50 | - name: Captain 51 | permission: admin 52 | - name: Maintainers 53 | permission: push 54 | 55 | branches: 56 | - name: master 57 | protection: 58 | required_pull_request_reviews: 59 | required_approving_review_count: 1 60 | dismiss_stale_reviews: false 61 | require_code_owner_reviews: false 62 | dismissal_restrictions: 63 | teams: 64 | - Admins 65 | - Captain 66 | required_status_checks: 67 | strict: true 68 | contexts: 69 | - continuous-integration/drone/pr 70 | enforce_admins: false 71 | restrictions: 72 | apps: 73 | - renovate 74 | users: [] 75 | teams: 76 | - Admins 77 | - Maintainers 78 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /release/ 2 | /drone-github-release* 3 | 4 | coverage.out 5 | -------------------------------------------------------------------------------- /.harness/eventPR.yaml: -------------------------------------------------------------------------------- 1 | inputSet: 2 | name: event-PR 3 | identifier: eventPR 4 | orgIdentifier: default 5 | projectIdentifier: Drone_Plugins 6 | pipeline: 7 | identifier: dronegithubreleaseharness 8 | properties: 9 | ci: 10 | codebase: 11 | build: 12 | type: PR 13 | spec: 14 | number: <+trigger.prNumber> 15 | -------------------------------------------------------------------------------- /.harness/eventPush.yaml: -------------------------------------------------------------------------------- 1 | inputSet: 2 | name: event-Push 3 | identifier: eventPush 4 | orgIdentifier: default 5 | projectIdentifier: Drone_Plugins 6 | pipeline: 7 | identifier: dronegithubreleaseharness 8 | properties: 9 | ci: 10 | codebase: 11 | build: 12 | type: branch 13 | spec: 14 | branch: <+trigger.branch> 15 | -------------------------------------------------------------------------------- /.harness/eventTag.yaml: -------------------------------------------------------------------------------- 1 | inputSet: 2 | name: event-Tag 3 | identifier: eventTag 4 | orgIdentifier: default 5 | projectIdentifier: Drone_Plugins 6 | pipeline: 7 | identifier: dronegithubreleaseharness 8 | properties: 9 | ci: 10 | codebase: 11 | build: 12 | type: tag 13 | spec: 14 | tag: <+trigger.tag> 15 | -------------------------------------------------------------------------------- /.harness/harness.yaml: -------------------------------------------------------------------------------- 1 | pipeline: 2 | name: drone-github-release-harness 3 | identifier: dronegithubreleaseharness 4 | projectIdentifier: Drone_Plugins 5 | orgIdentifier: default 6 | tags: {} 7 | properties: 8 | ci: 9 | codebase: 10 | connectorRef: GitHub_Drone_Plugins_Org 11 | repoName: drone-github-release 12 | build: <+input> 13 | sparseCheckout: [] 14 | stages: 15 | - stage: 16 | name: Testing Stage 17 | identifier: Testing_Stage 18 | type: CI 19 | spec: 20 | cloneCodebase: true 21 | caching: 22 | enabled: false 23 | paths: [] 24 | platform: 25 | os: Linux 26 | arch: Amd64 27 | runtime: 28 | type: Cloud 29 | spec: {} 30 | execution: 31 | steps: 32 | - step: 33 | type: Run 34 | name: Lint 35 | identifier: Lint 36 | spec: 37 | connectorRef: Plugins_Docker_Hub_Connector 38 | image: golang:1.20 39 | shell: Sh 40 | command: |- 41 | go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 42 | golangci-lint version 43 | golangci-lint run 44 | - step: 45 | type: Run 46 | name: Test 47 | identifier: Run_1 48 | spec: 49 | connectorRef: Plugins_Docker_Hub_Connector 50 | image: golang:1.20 51 | shell: Sh 52 | command: go test -cover ./... 53 | - step: 54 | name: Build and test binaries 55 | identifier: Build_test_binaries 56 | type: Run 57 | spec: 58 | connectorRef: Plugins_Docker_Hub_Connector 59 | image: golang:1.20 60 | shell: Sh 61 | command: |- 62 | # force go modules 63 | export GOPATH="" 64 | 65 | # disable cgo 66 | export CGO_ENABLED=0 67 | 68 | set -e 69 | set -x 70 | 71 | # linux 72 | export GOOS=linux GOARCH=amd64 73 | go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-github-release ./cmd/drone-github-release 74 | ./release/linux/amd64/drone-github-release --help 75 | description: "" 76 | - parallel: 77 | - stage: 78 | name: linux-amd64 79 | identifier: linuxamd64 80 | type: CI 81 | spec: 82 | cloneCodebase: true 83 | caching: 84 | enabled: false 85 | paths: [] 86 | platform: 87 | os: Linux 88 | arch: Amd64 89 | runtime: 90 | type: Cloud 91 | spec: {} 92 | execution: 93 | steps: 94 | - step: 95 | name: Build binaries 96 | identifier: Build_binaries 97 | type: Run 98 | spec: 99 | connectorRef: Plugins_Docker_Hub_Connector 100 | image: golang:1.20 101 | shell: Sh 102 | command: |- 103 | # force go modules 104 | export GOPATH="" 105 | 106 | # disable cgo 107 | export CGO_ENABLED=0 108 | 109 | set -e 110 | set -x 111 | 112 | # linux 113 | export GOOS=linux GOARCH=amd64 114 | go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/amd64/drone-github-release ./cmd/drone-github-release 115 | when: 116 | stageStatus: Success 117 | - step: 118 | type: Plugin 119 | name: BuildAndPushDockerPlugin 120 | identifier: BuildAndPushDockerPlugin 121 | spec: 122 | connectorRef: Plugins_Docker_Hub_Connector 123 | image: plugins/docker 124 | settings: 125 | username: drone 126 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 127 | repo: plugins/github-release 128 | dockerfile: docker/Dockerfile.linux.amd64 129 | auto_tag: "true" 130 | auto_tag_suffix: linux-amd64 131 | when: 132 | stageStatus: Success 133 | condition: <+codebase.build.type> == "tag" 134 | - step: 135 | type: BuildAndPushDockerRegistry 136 | name: BuildAndPushDockerRegistry 137 | identifier: BuildAndPushDockerRegistry 138 | spec: 139 | connectorRef: Plugins_Docker_Hub_Connector 140 | repo: plugins/github-release 141 | tags: 142 | - linux-amd64 143 | caching: false 144 | dockerfile: docker/Dockerfile.linux.amd64 145 | when: 146 | stageStatus: Success 147 | condition: | 148 | <+codebase.build.type> == "branch" 149 | description: "" 150 | - stage: 151 | name: linux-arm64 152 | identifier: linuxarm64 153 | type: CI 154 | spec: 155 | cloneCodebase: true 156 | caching: 157 | enabled: false 158 | paths: [] 159 | platform: 160 | os: Linux 161 | arch: Arm64 162 | runtime: 163 | type: Cloud 164 | spec: {} 165 | execution: 166 | steps: 167 | - step: 168 | name: Build binaries 169 | identifier: Build_binaries 170 | type: Run 171 | spec: 172 | connectorRef: Plugins_Docker_Hub_Connector 173 | image: golang:1.20 174 | shell: Sh 175 | command: |- 176 | # force go modules 177 | export GOPATH="" 178 | 179 | # disable cgo 180 | export CGO_ENABLED=0 181 | 182 | set -e 183 | set -x 184 | 185 | # linux 186 | export GOOS=linux GOARCH=arm64 187 | go build -v -ldflags "-X main.version=" -a -tags netgo -o release/linux/arm64/drone-github-release ./cmd/drone-github-release 188 | when: 189 | stageStatus: Success 190 | - step: 191 | type: Plugin 192 | name: BuildAndPushDockerPlugin 193 | identifier: BuildAndPushDockerPlugin 194 | spec: 195 | connectorRef: Plugins_Docker_Hub_Connector 196 | image: plugins/docker 197 | settings: 198 | username: drone 199 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 200 | repo: plugins/github-release 201 | dockerfile: docker/Dockerfile.linux.arm64 202 | auto_tag: "true" 203 | auto_tag_suffix: linux-arm64 204 | when: 205 | stageStatus: Success 206 | condition: <+codebase.build.type> == "tag" 207 | - step: 208 | type: BuildAndPushDockerRegistry 209 | name: BuildAndPushDockerRegistry 210 | identifier: BuildAndPushDockerRegistry 211 | spec: 212 | connectorRef: Plugins_Docker_Hub_Connector 213 | repo: plugins/github-release 214 | tags: 215 | - linux-arm64 216 | caching: false 217 | dockerfile: docker/Dockerfile.linux.arm64 218 | when: 219 | stageStatus: Success 220 | condition: | 221 | <+codebase.build.type> == "branch" 222 | description: "" 223 | - stage: 224 | name: windows-1809-amd64 225 | identifier: windows1809amd64 226 | type: CI 227 | spec: 228 | cloneCodebase: true 229 | caching: 230 | enabled: false 231 | paths: [] 232 | execution: 233 | steps: 234 | - step: 235 | name: Build binaries 236 | identifier: Build_binaries 237 | type: Run 238 | spec: 239 | connectorRef: Plugins_Docker_Hub_Connector 240 | image: golang:1.20 241 | shell: Sh 242 | command: |- 243 | # force go modules 244 | export GOPATH="" 245 | 246 | # disable cgo 247 | export CGO_ENABLED=0 248 | 249 | set -e 250 | set -x 251 | 252 | # Windows 253 | GOOS=windows 254 | go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release 255 | when: 256 | stageStatus: Success 257 | - step: 258 | type: Plugin 259 | name: BuildAndPushDockerPlugin 260 | identifier: BuildAndPushDockerPlugin 261 | spec: 262 | connectorRef: Plugins_Docker_Hub_Connector 263 | image: plugins/docker 264 | settings: 265 | username: drone 266 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 267 | repo: plugins/github-release 268 | dockerfile: docker/Dockerfile.windows.1809 269 | auto_tag: "true" 270 | auto_tag_suffix: windows-1809-amd64 271 | when: 272 | stageStatus: Success 273 | condition: <+codebase.build.type> == "tag" 274 | - step: 275 | type: BuildAndPushDockerRegistry 276 | name: BuildAndPushDockerRegistry 277 | identifier: BuildAndPushDockerRegistry 278 | spec: 279 | connectorRef: Plugins_Docker_Hub_Connector 280 | repo: plugins/github-release 281 | tags: 282 | - windows-1809-amd64 283 | caching: false 284 | dockerfile: docker/Dockerfile.windows.1809 285 | when: 286 | stageStatus: Success 287 | condition: | 288 | <+codebase.build.type> == "branch" 289 | infrastructure: 290 | type: VM 291 | spec: 292 | type: Pool 293 | spec: 294 | poolName: windows-2019 295 | os: Windows 296 | description: "" 297 | delegateSelectors: 298 | - windows-vm 299 | - stage: 300 | name: windows-ltsc2022-amd64 301 | identifier: windowsltsc2022amd64 302 | type: CI 303 | spec: 304 | cloneCodebase: true 305 | caching: 306 | enabled: false 307 | paths: [] 308 | platform: 309 | os: Windows 310 | arch: Amd64 311 | runtime: 312 | type: Cloud 313 | spec: {} 314 | execution: 315 | steps: 316 | - step: 317 | name: Build binaries 318 | identifier: Build_binaries 319 | type: Run 320 | spec: 321 | connectorRef: Plugins_Docker_Hub_Connector 322 | image: golang:1.20 323 | shell: Sh 324 | command: |- 325 | # force go modules 326 | export GOPATH="" 327 | 328 | # disable cgo 329 | export CGO_ENABLED=0 330 | 331 | set -e 332 | set -x 333 | 334 | # Windows 335 | GOOS=windows 336 | go build -v -ldflags "-X main.version=" -a -tags netgo -o release/windows/amd64/drone-github-release.exe ./cmd/drone-github-release 337 | - step: 338 | type: Plugin 339 | name: BuildAndPushDockerPlugin 340 | identifier: BuildAndPushDockerPlugin 341 | spec: 342 | connectorRef: Plugins_Docker_Hub_Connector 343 | image: plugins/docker 344 | settings: 345 | username: drone 346 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 347 | repo: plugins/github-release 348 | dockerfile: docker/Dockerfile.windows.ltsc2022 349 | auto_tag: "true" 350 | auto_tag_suffix: windows-ltsc2022-amd64 351 | when: 352 | stageStatus: Success 353 | condition: <+codebase.build.type> == "tag" 354 | - step: 355 | type: BuildAndPushDockerRegistry 356 | name: BuildAndPushDockerRegistry 357 | identifier: BuildAndPushDockerRegistry 358 | spec: 359 | connectorRef: Plugins_Docker_Hub_Connector 360 | repo: plugins/github-release 361 | tags: 362 | - windows-ltsc2022-amd64 363 | caching: false 364 | dockerfile: docker/Dockerfile.windows.ltsc2022 365 | when: 366 | stageStatus: Success 367 | condition: | 368 | <+codebase.build.type> == "branch" 369 | description: "" 370 | - stage: 371 | name: Manifest 372 | identifier: Manifest 373 | type: CI 374 | spec: 375 | cloneCodebase: true 376 | caching: 377 | enabled: false 378 | paths: [] 379 | platform: 380 | os: Linux 381 | arch: Amd64 382 | runtime: 383 | type: Cloud 384 | spec: {} 385 | execution: 386 | steps: 387 | - step: 388 | type: Plugin 389 | name: Manifest 390 | identifier: Manifest 391 | spec: 392 | connectorRef: Plugins_Docker_Hub_Connector 393 | image: plugins/manifest 394 | settings: 395 | username: drone 396 | password: <+secrets.getValue("Plugins_Docker_Hub_Pat")> 397 | auto_tag: "true" 398 | ignore_missing: "true" 399 | spec: docker/manifest.tmpl 400 | when: 401 | stageStatus: Success 402 | condition: | 403 | <+codebase.build.type> == "tag" || <+codebase.build.type> == "branch" 404 | description: "" 405 | allowStageExecutions: true 406 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # drone-github-release 2 | 3 | 4 | [![Build Status](http://harness.drone.io/api/badges/drone-plugins/drone-github-release/status.svg)](http://harness.drone.io/drone-plugins/drone-github-release) 5 | [![Slack](https://img.shields.io/badge/slack-drone-orange.svg?logo=slack)](https://join.slack.com/t/harnesscommunity/shared_invite/zt-y4hdqh7p-RVuEQyIl5Hcx4Ck8VCvzBw) 6 | [![Join the discussion at https://community.harness.io](https://img.shields.io/badge/discourse-forum-orange.svg)](https://community.harness.io) 7 | [![Drone questions at https://stackoverflow.com](https://img.shields.io/badge/drone-stackoverflow-orange.svg)](https://stackoverflow.com/questions/tagged/drone.io) 8 | [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-github-release?status.svg)](http://godoc.org/github.com/drone-plugins/drone-github-release) 9 | [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-github-release)](https://goreportcard.com/report/github.com/drone-plugins/drone-github-release) 10 | 11 | Drone plugin to publish files and artifacts to GitHub Release. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-github-release/). 12 | 13 | ## Build 14 | 15 | Build the binary with the following command: 16 | 17 | ```console 18 | export GOOS=linux 19 | export GOARCH=amd64 20 | export CGO_ENABLED=0 21 | export GO111MODULE=on 22 | 23 | go build -v -a -tags netgo -o release/linux/amd64/drone-github-release 24 | ``` 25 | 26 | ## Docker 27 | 28 | Build the Docker image with the following command: 29 | 30 | ```console 31 | docker build \ 32 | --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ 33 | --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ 34 | --file docker/Dockerfile.linux.amd64 --tag plugins/github-release . 35 | ``` 36 | 37 | ## Usage 38 | 39 | ```console 40 | docker run --rm \ 41 | -e DRONE_BUILD_EVENT=tag \ 42 | -e DRONE_REPO_OWNER=octocat \ 43 | -e DRONE_REPO_NAME=foo \ 44 | -e DRONE_COMMIT_REF=refs/heads/master \ 45 | -e PLUGIN_API_KEY=${HOME}/.ssh/id_rsa \ 46 | -e PLUGIN_FILES=master \ 47 | -v $(pwd):$(pwd) \ 48 | -w $(pwd) \ 49 | plugins/github-release 50 | ``` 51 | -------------------------------------------------------------------------------- /cmd/drone-github-release/config.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package main 7 | 8 | import ( 9 | "github.com/drone-plugins/drone-github-release/plugin" 10 | "github.com/urfave/cli/v2" 11 | ) 12 | 13 | // settingsFlags has the cli.Flags for the plugin.Settings. 14 | func settingsFlags(settings *plugin.Settings) []cli.Flag { 15 | return []cli.Flag{ 16 | &cli.StringFlag{ 17 | Name: "github-url", 18 | Usage: "github url, defaults to current scm", 19 | EnvVars: []string{"PLUGIN_GITHUB_URL", "DRONE_REPO_LINK"}, 20 | Destination: &settings.GitHubURL, 21 | }, 22 | &cli.StringFlag{ 23 | Name: "api-key", 24 | Usage: "api key to access github api", 25 | EnvVars: []string{"PLUGIN_API_KEY", "GITHUB_RELEASE_API_KEY", "GITHUB_TOKEN"}, 26 | Destination: &settings.APIKey, 27 | }, 28 | &cli.StringSliceFlag{ 29 | Name: "files", 30 | Usage: "list of files to upload", 31 | EnvVars: []string{"PLUGIN_FILES", "GITHUB_RELEASE_FILES"}, 32 | Destination: &settings.Files, 33 | }, 34 | &cli.StringFlag{ 35 | Name: "file-exists", 36 | Value: "overwrite", 37 | Usage: "what to do if file already exist", 38 | EnvVars: []string{"PLUGIN_FILE_EXISTS", "GITHUB_RELEASE_FILE_EXISTS"}, 39 | Destination: &settings.FileExists, 40 | }, 41 | &cli.StringSliceFlag{ 42 | Name: "checksum", 43 | Usage: "generate specific checksums", 44 | EnvVars: []string{"PLUGIN_CHECKSUM", "GITHUB_RELEASE_CHECKSUM"}, 45 | Destination: &settings.Checksum, 46 | }, 47 | &cli.StringFlag{ 48 | Name: "checksum-file", 49 | Usage: "name used for checksum file. \"CHECKSUM\" is replaced with the chosen method", 50 | EnvVars: []string{"PLUGIN_CHECKSUM_FILE"}, 51 | Value: "CHECKSUMsum.txt", 52 | Destination: &settings.ChecksumFile, 53 | }, 54 | &cli.BoolFlag{ 55 | Name: "checksum-flatten", 56 | Usage: "include only the basename of the file in the checksum file", 57 | EnvVars: []string{"PLUGIN_CHECKSUM_FLATTEN"}, 58 | Destination: &settings.ChecksumFlatten, 59 | }, 60 | &cli.BoolFlag{ 61 | Name: "draft", 62 | Usage: "create a draft release", 63 | EnvVars: []string{"PLUGIN_DRAFT", "GITHUB_RELEASE_DRAFT"}, 64 | Destination: &settings.Draft, 65 | }, 66 | &cli.BoolFlag{ 67 | Name: "prerelease", 68 | Usage: "set the release as prerelease", 69 | EnvVars: []string{"PLUGIN_PRERELEASE", "GITHUB_RELEASE_PRERELEASE"}, 70 | Destination: &settings.Prerelease, 71 | }, 72 | &cli.StringFlag{ 73 | Name: "base-url", 74 | Usage: "api url, needs to be changed for ghe", 75 | EnvVars: []string{"PLUGIN_BASE_URL", "GITHUB_RELEASE_BASE_URL"}, 76 | Destination: &settings.BaseURL, 77 | }, 78 | &cli.StringFlag{ 79 | Name: "upload-url", 80 | Usage: "upload url, needs to be changed for ghe", 81 | EnvVars: []string{"PLUGIN_UPLOAD_URL", "GITHUB_RELEASE_UPLOAD_URL"}, 82 | Destination: &settings.UploadURL, 83 | }, 84 | &cli.StringFlag{ 85 | Name: "title", 86 | Usage: "file or string for the title shown in the github release", 87 | EnvVars: []string{"PLUGIN_TITLE", "GITHUB_RELEASE_TITLE"}, 88 | Destination: &settings.Title, 89 | }, 90 | &cli.StringFlag{ 91 | Name: "note", 92 | Usage: "file or string with notes for the release (example: changelog)", 93 | EnvVars: []string{"PLUGIN_NOTE", "GITHUB_RELEASE_NOTE"}, 94 | Destination: &settings.Note, 95 | }, 96 | &cli.BoolFlag{ 97 | Name: "overwrite", 98 | Usage: "force overwrite existing release informations e.g. title or note", 99 | EnvVars: []string{"PLUGIN_OVERWRITE", "GITHUB_RELEASE_OVERWRIDE"}, 100 | Destination: &settings.Overwrite, 101 | }, 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /cmd/drone-github-release/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | // DO NOT MODIFY THIS FILE DIRECTLY 7 | 8 | package main 9 | 10 | import ( 11 | "os" 12 | 13 | "github.com/drone-plugins/drone-github-release/plugin" 14 | "github.com/drone-plugins/drone-plugin-lib/errors" 15 | "github.com/drone-plugins/drone-plugin-lib/urfave" 16 | "github.com/joho/godotenv" 17 | "github.com/urfave/cli/v2" 18 | ) 19 | 20 | var version = "unknown" 21 | 22 | func main() { 23 | settings := &plugin.Settings{} 24 | 25 | if _, err := os.Stat("/run/drone/env"); err == nil { 26 | _ = godotenv.Overload("/run/drone/env") 27 | } 28 | 29 | app := &cli.App{ 30 | Name: "drone-github-release", 31 | Usage: "creates a github release", 32 | Version: version, 33 | Flags: append(settingsFlags(settings), urfave.Flags()...), 34 | Action: run(settings), 35 | } 36 | 37 | if err := app.Run(os.Args); err != nil { 38 | errors.HandleExit(err) 39 | } 40 | } 41 | 42 | func run(settings *plugin.Settings) cli.ActionFunc { 43 | return func(ctx *cli.Context) error { 44 | urfave.LoggingFromContext(ctx) 45 | 46 | plugin := plugin.New( 47 | *settings, 48 | urfave.PipelineFromContext(ctx), 49 | urfave.NetworkFromContext(ctx), 50 | ) 51 | 52 | if err := plugin.Validate(); err != nil { 53 | if e, ok := err.(errors.ExitCoder); ok { 54 | return e 55 | } 56 | 57 | return errors.ExitMessagef("validation failed: %w", err) 58 | } 59 | 60 | if err := plugin.Execute(); err != nil { 61 | if e, ok := err.(errors.ExitCoder); ok { 62 | return e 63 | } 64 | 65 | return errors.ExitMessagef("execution failed: %w", err) 66 | } 67 | 68 | return nil 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.amd64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch@sha256:61f243abf3f1ea407faae94ab4698b51c4cc38b9e734e30ae16e8ec7e6250f6b 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone GitHub Release" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/amd64/drone-github-release /bin/ 9 | ENTRYPOINT [ "/bin/drone-github-release" ] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.linux.arm64: -------------------------------------------------------------------------------- 1 | FROM plugins/base:multiarch@sha256:61f243abf3f1ea407faae94ab4698b51c4cc38b9e734e30ae16e8ec7e6250f6b 2 | 3 | LABEL maintainer="Drone.IO Community " \ 4 | org.label-schema.name="Drone GitHub Release" \ 5 | org.label-schema.vendor="Drone.IO Community" \ 6 | org.label-schema.schema-version="1.0" 7 | 8 | ADD release/linux/arm64/drone-github-release /bin/ 9 | ENTRYPOINT [ "/bin/drone-github-release" ] 10 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.1809: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-1809-amd64@sha256:61095306fa56d51adc841f2b0f93f511efb5792d12f2549bb2eb1cbce02c1f05 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone GitHub Release" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-github-release.exe C:/bin/drone-github-release.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-github-release.exe" ] 11 | -------------------------------------------------------------------------------- /docker/Dockerfile.windows.ltsc2022: -------------------------------------------------------------------------------- 1 | # escape=` 2 | FROM plugins/base:windows-ltsc2022-amd64@sha256:0f90d5bceb432f1ee6f93cf44eed6a38c322834edd55df8a6648c9e6f15131f4 3 | 4 | LABEL maintainer="Drone.IO Community " ` 5 | org.label-schema.name="Drone GitHub Release" ` 6 | org.label-schema.vendor="Drone.IO Community" ` 7 | org.label-schema.schema-version="1.0" 8 | 9 | ADD release/windows/amd64/drone-github-release.exe C:/bin/drone-github-release.exe 10 | ENTRYPOINT [ "C:\\bin\\drone-github-release.exe" ] 11 | -------------------------------------------------------------------------------- /docker/manifest.tmpl: -------------------------------------------------------------------------------- 1 | image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} 2 | 3 | {{#if build.tags}} 4 | tags: 5 | {{#each build.tags}} 6 | - {{this}} 7 | {{/each}} 8 | {{/if}} 9 | 10 | manifests: 11 | - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 12 | platform: 13 | architecture: amd64 14 | os: linux 15 | - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 16 | platform: 17 | architecture: arm64 18 | os: linux 19 | variant: v8 20 | - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64 21 | platform: 22 | architecture: amd64 23 | os: windows 24 | version: 1809 25 | - image: plugins/github-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64 26 | platform: 27 | architecture: amd64 28 | os: windows 29 | version: ltsc2022 -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/drone-plugins/drone-github-release 2 | 3 | go 1.20 4 | 5 | require ( 6 | github.com/drone-plugins/drone-plugin-lib v0.4.1 7 | github.com/google/go-github/v53 v53.0.0 8 | github.com/joho/godotenv v1.5.1 9 | github.com/urfave/cli/v2 v2.25.5 10 | golang.org/x/oauth2 v0.8.0 11 | ) 12 | 13 | require ( 14 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect 15 | github.com/cloudflare/circl v1.3.3 // indirect 16 | github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect 17 | github.com/golang/protobuf v1.5.2 // indirect 18 | github.com/google/go-querystring v1.1.0 // indirect 19 | github.com/russross/blackfriday/v2 v2.1.0 // indirect 20 | github.com/sirupsen/logrus v1.9.0 // indirect 21 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect 22 | golang.org/x/crypto v0.7.0 // indirect 23 | golang.org/x/net v0.10.0 // indirect 24 | golang.org/x/sys v0.8.0 // indirect 25 | google.golang.org/appengine v1.6.7 // indirect 26 | google.golang.org/protobuf v1.28.0 // indirect 27 | ) 28 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 h1:wPbRQzjjwFc0ih8puEVAOFGELsn1zoIIYdxvML7mDxA= 2 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8/go.mod h1:I0gYDMZ6Z5GRU7l58bNFSkPTFN6Yl12dsUlAZ8xy98g= 3 | github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0= 4 | github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= 5 | github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= 6 | github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= 7 | github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w= 8 | github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= 9 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 10 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 11 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/drone-plugins/drone-plugin-lib v0.4.1 h1:47rZlmcMpr1hSp+6Gl+1Z4t+efi/gMQU3lxukC1Yg64= 13 | github.com/drone-plugins/drone-plugin-lib v0.4.1/go.mod h1:KwCu92jFjHV3xv2hu5Qg/8zBNvGwbhoJDQw/EwnTvoM= 14 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 15 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 16 | github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= 17 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 18 | github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 19 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 20 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 21 | github.com/google/go-github/v53 v53.0.0 h1:T1RyHbSnpHYnoF0ZYKiIPSgPtuJ8G6vgc0MKodXsQDQ= 22 | github.com/google/go-github/v53 v53.0.0/go.mod h1:XhFRObz+m/l+UCm9b7KSIC3lT3NWSXGt7mOsAWEloao= 23 | github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= 24 | github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= 25 | github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= 26 | github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= 27 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 28 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 29 | github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 30 | github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 31 | github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= 32 | github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 33 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 34 | github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= 35 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 36 | github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc= 37 | github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc= 38 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU= 39 | github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8= 40 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 41 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 42 | golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= 43 | golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= 44 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 45 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 46 | golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= 47 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 48 | golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8= 49 | golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE= 50 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 51 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 52 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 53 | golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 54 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 55 | golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= 56 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 57 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 58 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 59 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 60 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 61 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 62 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 63 | google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= 64 | google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 65 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 66 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 67 | google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= 68 | google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 69 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 70 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 71 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 72 | -------------------------------------------------------------------------------- /plugin/impl.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "net/url" 12 | "path/filepath" 13 | "strings" 14 | 15 | "github.com/google/go-github/v53/github" 16 | "github.com/urfave/cli/v2" 17 | "golang.org/x/oauth2" 18 | ) 19 | 20 | // Settings for the plugin. 21 | type Settings struct { 22 | GitHubURL string 23 | APIKey string 24 | Files cli.StringSlice 25 | FileExists string 26 | Checksum cli.StringSlice 27 | ChecksumFile string 28 | ChecksumFlatten bool 29 | Draft bool 30 | Prerelease bool 31 | BaseURL string 32 | UploadURL string 33 | Title string 34 | Note string 35 | Overwrite bool 36 | GenerateReleaseNotes bool 37 | 38 | baseURL *url.URL 39 | uploadURL *url.URL 40 | uploads []string 41 | } 42 | 43 | // Validate handles the settings validation of the plugin. 44 | func (p *Plugin) Validate() error { 45 | var err error 46 | 47 | if p.pipeline.Build.Event != "tag" { 48 | return fmt.Errorf("github release plugin is only available for tags") 49 | } 50 | 51 | if p.settings.APIKey == "" { 52 | return fmt.Errorf("no api key provided") 53 | } 54 | 55 | if !fileExistsValues[p.settings.FileExists] { 56 | return fmt.Errorf("invalid value for file_exists") 57 | } 58 | 59 | if p.settings.BaseURL != "" && p.settings.UploadURL != "" { 60 | fmt.Printf("Both base_url and upload_url are deprecated. Please remove them from your config!") 61 | 62 | if !strings.HasSuffix(p.settings.BaseURL, "/") { 63 | p.settings.BaseURL = p.settings.BaseURL + "/" 64 | } 65 | p.settings.baseURL, err = url.Parse(p.settings.BaseURL) 66 | if err != nil { 67 | return fmt.Errorf("failed to parse base url: %w", err) 68 | } 69 | 70 | if !strings.HasSuffix(p.settings.UploadURL, "/") { 71 | p.settings.UploadURL = p.settings.UploadURL + "/" 72 | } 73 | p.settings.uploadURL, err = url.Parse(p.settings.UploadURL) 74 | if err != nil { 75 | return fmt.Errorf("failed to parse upload url: %w", err) 76 | } 77 | } else { 78 | p.settings.baseURL, p.settings.uploadURL, err = gitHubURLs(p.settings.GitHubURL) 79 | if err != nil { 80 | return fmt.Errorf("failed to get GitHub urls: %w", err) 81 | } 82 | } 83 | 84 | if p.settings.Note != "" { 85 | if p.settings.Note, err = readStringOrFile(p.settings.Note); err != nil { 86 | return fmt.Errorf("error while reading %s: %w", p.settings.Note, err) 87 | } 88 | } 89 | 90 | if p.settings.Title != "" { 91 | if p.settings.Title, err = readStringOrFile(p.settings.Title); err != nil { 92 | return fmt.Errorf("error while reading %s: %w", p.settings.Note, err) 93 | } 94 | } 95 | 96 | files := p.settings.Files.Value() 97 | for _, glob := range files { 98 | globed, err := filepath.Glob(glob) 99 | 100 | if err != nil { 101 | return fmt.Errorf("failed to glob %s: %w", glob, err) 102 | } 103 | 104 | if globed != nil { 105 | p.settings.uploads = append(p.settings.uploads, globed...) 106 | } 107 | } 108 | 109 | if len(files) > 0 && len(p.settings.uploads) < 1 { 110 | return fmt.Errorf("failed to find any file to release") 111 | } 112 | 113 | checksum := p.settings.Checksum.Value() 114 | if len(checksum) > 0 { 115 | p.settings.uploads, err = writeChecksums(p.settings.uploads, checksum, p.settings.ChecksumFile, p.settings.ChecksumFlatten) 116 | 117 | if err != nil { 118 | return fmt.Errorf("failed to write checksums: %w", err) 119 | } 120 | } 121 | 122 | return nil 123 | } 124 | 125 | // Execute provides the implementation of the plugin. 126 | func (p *Plugin) Execute() error { 127 | ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: p.settings.APIKey}) 128 | tc := oauth2.NewClient( 129 | context.WithValue(context.Background(), oauth2.HTTPClient, p.network.Client), 130 | ts, 131 | ) 132 | 133 | client := github.NewClient(tc) 134 | 135 | client.BaseURL = p.settings.baseURL 136 | client.UploadURL = p.settings.uploadURL 137 | 138 | rc := releaseClient{ 139 | Client: client, 140 | Context: p.network.Context, 141 | Owner: p.pipeline.Repo.Owner, 142 | Repo: p.pipeline.Repo.Name, 143 | Tag: strings.TrimPrefix(p.pipeline.Commit.Ref, "refs/tags/"), 144 | Draft: p.settings.Draft, 145 | Prerelease: p.settings.Prerelease, 146 | FileExists: p.settings.FileExists, 147 | Title: p.settings.Title, 148 | Note: p.settings.Note, 149 | Overwrite: p.settings.Overwrite, 150 | GenerateReleaseNotes: p.settings.GenerateReleaseNotes, 151 | } 152 | 153 | release, err := rc.buildRelease() 154 | 155 | if err != nil { 156 | return fmt.Errorf("failed to create the release: %w", err) 157 | } 158 | 159 | if err := rc.uploadFiles(*release.ID, p.settings.uploads); err != nil { 160 | return fmt.Errorf("failed to upload the files: %w", err) 161 | } 162 | 163 | return nil 164 | } 165 | 166 | func gitHubURLs(gh string) (*url.URL, *url.URL, error) { 167 | uri, err := url.Parse(gh) 168 | if err != nil { 169 | return nil, nil, fmt.Errorf("could not parse GitHub link") 170 | } 171 | 172 | // Remove the path in the case that DRONE_REPO_LINK was passed in 173 | uri.Path = "" 174 | 175 | if uri.Hostname() != "github.com" { 176 | relBaseURL, _ := url.Parse("./api/v3/") 177 | relUploadURL, _ := url.Parse("./api/v3/upload/") 178 | 179 | return uri.ResolveReference(relBaseURL), uri.ResolveReference(relUploadURL), nil 180 | } 181 | 182 | baseURL, _ := url.Parse("https://api.github.com/") 183 | uploadURL, _ := url.Parse("https://uploads.github.com/") 184 | 185 | return baseURL, uploadURL, nil 186 | } 187 | -------------------------------------------------------------------------------- /plugin/impl_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestValidate(t *testing.T) { 13 | t.Skip() 14 | } 15 | 16 | func TestExecute(t *testing.T) { 17 | t.Skip() 18 | } 19 | 20 | func TestGitHubURLs(t *testing.T) { 21 | // GitHub case 22 | actualBaseURL, actualUploadURL, _ := gitHubURLs("https://github.com/drone-plugins/drone-release-download") 23 | expectedBaseURL := "https://api.github.com/" 24 | if actualBaseURL.String() != expectedBaseURL { 25 | t.Errorf("Unexpected base API URL (Got: %s, Expected: %s", actualBaseURL.String(), expectedBaseURL) 26 | } 27 | expectedUploadURL := "https://uploads.github.com/" 28 | if actualUploadURL.String() != expectedUploadURL { 29 | t.Errorf("Unexpected upload API URL (Got: %s, Expected: %s", actualUploadURL.String(), expectedUploadURL) 30 | } 31 | 32 | // GitHub Enterprise case 33 | actualBaseURL, actualUploadURL, _ = gitHubURLs("https://github.enterprise.drone.io/drone-plugins/drone-release-download") 34 | expectedBaseURL = "https://github.enterprise.drone.io/api/v3/" 35 | if actualBaseURL.String() != expectedBaseURL { 36 | t.Errorf("Unexpected base API URL (Got: %s, Expected: %s", actualBaseURL.String(), expectedBaseURL) 37 | } 38 | expectedUploadURL = "https://github.enterprise.drone.io/api/v3/upload/" 39 | if actualUploadURL.String() != expectedUploadURL { 40 | t.Errorf("Unexpected upload API URL (Got: %s, Expected: %s", actualUploadURL.String(), expectedUploadURL) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /plugin/plugin.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "github.com/drone-plugins/drone-plugin-lib/drone" 10 | ) 11 | 12 | // Plugin implements drone.Plugin to provide the plugin implementation. 13 | type Plugin struct { 14 | settings Settings 15 | pipeline drone.Pipeline 16 | network drone.Network 17 | } 18 | 19 | // New initializes a plugin from the given Settings, Pipeline, and Network. 20 | func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin { 21 | return &Plugin{ 22 | settings: settings, 23 | pipeline: pipeline, 24 | network: network, 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /plugin/plugin_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestReadStringOrFileSelf(t *testing.T) { 13 | contents, err := readStringOrFile("./plugin/plugin_test.go") 14 | 15 | if err != nil { 16 | t.Error(err) 17 | return 18 | } 19 | if len(contents) == 0 { 20 | t.Errorf("Expected this file to have length > 0, was %d", len(contents)) 21 | } 22 | } 23 | 24 | func TestReadStringOrFileLongString(t *testing.T) { 25 | s := "if the string is extremely long it will still try to ask the OS to read this as a file which in some cases will not be allowed because of the length of the file name however the plugin might try this anyways but most file systems only allow a maximum of 255 chars for a file name but up to 4096 for a full path thats a lot of characters" 26 | contents, err := readStringOrFile(s) 27 | 28 | if err != nil { 29 | t.Error(err) 30 | return 31 | } 32 | 33 | if contents != s { 34 | t.Error("Expected readStringOrFile to return input for a long string") 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /plugin/release.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "context" 10 | "fmt" 11 | "os" 12 | "path" 13 | 14 | "github.com/google/go-github/v53/github" 15 | ) 16 | 17 | // Release holds ties the drone env data and github client together. 18 | type releaseClient struct { 19 | *github.Client 20 | context.Context 21 | Owner string 22 | Repo string 23 | Tag string 24 | Draft bool 25 | Prerelease bool 26 | FileExists string 27 | Title string 28 | Note string 29 | Overwrite bool 30 | GenerateReleaseNotes bool 31 | } 32 | 33 | func (rc *releaseClient) buildRelease() (*github.RepositoryRelease, error) { 34 | // first attempt to get a release by that tag 35 | release, err := rc.getRelease() 36 | 37 | if err != nil { 38 | return nil, fmt.Errorf("failed to retrieve a release: %w", err) 39 | } 40 | 41 | if release == nil { 42 | // if no release was found by that tag, create a new one 43 | release, err = rc.newRelease() 44 | } else { 45 | // update release if exists 46 | release, err = rc.editRelease(*release) 47 | } 48 | 49 | if err != nil { 50 | return nil, fmt.Errorf("failed to create or edit a release: %w", err) 51 | } 52 | 53 | return release, nil 54 | } 55 | 56 | func (rc *releaseClient) getRelease() (*github.RepositoryRelease, error) { 57 | 58 | listOpts := &github.ListOptions{PerPage: 10} 59 | 60 | for { 61 | // get list of releases (10 releases per page) 62 | releases, resp, err := rc.Client.Repositories.ListReleases(rc.Context, rc.Owner, rc.Repo, listOpts) 63 | if err != nil { 64 | return nil, fmt.Errorf("failed to list releases: %w", err) 65 | } 66 | 67 | // browse through current release page 68 | for _, release := range releases { 69 | 70 | // return release associated to the given tag (can only be one) 71 | if release.GetTagName() == rc.Tag { 72 | fmt.Printf("Found release %d for tag %s\n", release.GetID(), release.GetTagName()) 73 | return release, nil 74 | } 75 | } 76 | 77 | // end of list found without finding a matching release 78 | if resp.NextPage == 0 { 79 | fmt.Println("no existing release (draft) found for the given tag") 80 | return nil, nil 81 | } 82 | 83 | // go to next page in the next iteration 84 | listOpts.Page = resp.NextPage 85 | } 86 | } 87 | 88 | func (rc *releaseClient) editRelease(targetRelease github.RepositoryRelease) (*github.RepositoryRelease, error) { 89 | sourceRelease := &github.RepositoryRelease{} 90 | 91 | if rc.Overwrite { 92 | sourceRelease.Name = &rc.Title 93 | sourceRelease.Body = &rc.Note 94 | } 95 | 96 | // only potentially change the draft value, if it's a draft right now 97 | // i.e. a drafted release will be published, but a release won't be unpublished 98 | if targetRelease.GetDraft() { 99 | fmt.Printf("DRAFT: %+v\n", rc.Draft) 100 | if !rc.Draft { 101 | fmt.Println("Publishing a release draft") 102 | } 103 | sourceRelease.Draft = &rc.Draft 104 | } 105 | 106 | modifiedRelease, _, err := rc.Client.Repositories.EditRelease(rc.Context, rc.Owner, rc.Repo, targetRelease.GetID(), sourceRelease) 107 | 108 | if err != nil { 109 | return nil, fmt.Errorf("failed to update release: %w", err) 110 | } 111 | 112 | fmt.Printf("Successfully updated %s release\n", rc.Tag) 113 | return modifiedRelease, nil 114 | } 115 | 116 | func (rc *releaseClient) newRelease() (*github.RepositoryRelease, error) { 117 | rr := &github.RepositoryRelease{ 118 | TagName: github.String(rc.Tag), 119 | Draft: &rc.Draft, 120 | Prerelease: &rc.Prerelease, 121 | Name: &rc.Title, 122 | Body: &rc.Note, 123 | GenerateReleaseNotes: &rc.GenerateReleaseNotes, 124 | } 125 | 126 | if *rr.Prerelease { 127 | fmt.Printf("Release %s identified as a pre-release\n", rc.Tag) 128 | } else { 129 | fmt.Printf("Release %s identified as a full release\n", rc.Tag) 130 | } 131 | 132 | if *rr.Draft { 133 | fmt.Printf("Release %s will be created as draft (unpublished) release\n", rc.Tag) 134 | } else { 135 | fmt.Printf("Release %s will be created and published\n", rc.Tag) 136 | } 137 | 138 | if *rr.GenerateReleaseNotes { 139 | fmt.Printf("Release notes for %s will be automatically generated\n", rc.Tag) 140 | } 141 | 142 | release, _, err := rc.Client.Repositories.CreateRelease(rc.Context, rc.Owner, rc.Repo, rr) 143 | 144 | if err != nil { 145 | return nil, fmt.Errorf("failed to create release: %w", err) 146 | } 147 | 148 | fmt.Printf("Successfully created %s release\n", rc.Tag) 149 | return release, nil 150 | } 151 | 152 | func (rc *releaseClient) uploadFiles(id int64, files []string) error { 153 | var assets []*github.ReleaseAsset 154 | listOpts := &github.ListOptions{PerPage: 10} 155 | for { 156 | a, resp, err := rc.Client.Repositories.ListReleaseAssets(rc.Context, rc.Owner, rc.Repo, id, listOpts) 157 | if err != nil { 158 | return fmt.Errorf("failed to fetch existing assets: %w", err) 159 | } 160 | assets = append(assets, a...) 161 | 162 | // stop iteration if there is no next page 163 | if resp.NextPage == 0 { 164 | break 165 | } 166 | 167 | listOpts.Page = resp.NextPage 168 | } 169 | 170 | var uploadFiles []string 171 | 172 | files: 173 | for _, file := range files { 174 | for _, asset := range assets { 175 | if *asset.Name == path.Base(file) { 176 | switch rc.FileExists { 177 | case "overwrite": 178 | // do nothing 179 | case "fail": 180 | return fmt.Errorf("asset file %s already exists", path.Base(file)) 181 | case "skip": 182 | fmt.Printf("Skipping pre-existing %s artifact\n", *asset.Name) 183 | continue files 184 | default: 185 | return fmt.Errorf("internal error, unknown file_exist value %s", rc.FileExists) 186 | } 187 | } 188 | } 189 | 190 | uploadFiles = append(uploadFiles, file) 191 | } 192 | 193 | for _, file := range uploadFiles { 194 | handle, err := os.Open(file) 195 | 196 | if err != nil { 197 | return fmt.Errorf("failed to read %s artifact: %w", file, err) 198 | } 199 | 200 | for _, asset := range assets { 201 | if *asset.Name == path.Base(file) { 202 | if _, err := rc.Client.Repositories.DeleteReleaseAsset(rc.Context, rc.Owner, rc.Repo, *asset.ID); err != nil { 203 | return fmt.Errorf("failed to delete %s artifact: %w", file, err) 204 | } 205 | 206 | fmt.Printf("Successfully deleted old %s artifact\n", *asset.Name) 207 | } 208 | } 209 | 210 | uo := &github.UploadOptions{Name: path.Base(file)} 211 | 212 | if _, _, err = rc.Client.Repositories.UploadReleaseAsset(rc.Context, rc.Owner, rc.Repo, id, uo, handle); err != nil { 213 | return fmt.Errorf("failed to upload %s artifact: %w", file, err) 214 | } 215 | 216 | fmt.Printf("Successfully uploaded %s artifact\n", file) 217 | } 218 | 219 | return nil 220 | } 221 | -------------------------------------------------------------------------------- /plugin/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, the Drone Plugins project authors. 2 | // Please see the AUTHORS file for details. All rights reserved. 3 | // Use of this source code is governed by an Apache 2.0 license that can be 4 | // found in the LICENSE file. 5 | 6 | package plugin 7 | 8 | import ( 9 | "crypto/md5" 10 | "crypto/sha1" 11 | "crypto/sha256" 12 | "crypto/sha512" 13 | "fmt" 14 | "hash/adler32" 15 | "hash/crc32" 16 | "io" 17 | "os" 18 | "path/filepath" 19 | "strconv" 20 | "strings" 21 | ) 22 | 23 | var ( 24 | fileExistsValues = map[string]bool{ 25 | "overwrite": true, 26 | "fail": true, 27 | "skip": true, 28 | } 29 | ) 30 | 31 | func readStringOrFile(input string) (string, error) { 32 | if len(input) > 255 { 33 | return input, nil 34 | } 35 | // Check if input is a file path 36 | if _, err := os.Stat(input); err != nil && os.IsNotExist(err) { 37 | // No file found => use input as result 38 | return input, nil 39 | } else if err != nil { 40 | return "", err 41 | } 42 | result, err := os.ReadFile(input) 43 | if err != nil { 44 | return "", err 45 | } 46 | return string(result), nil 47 | } 48 | 49 | func checksum(r io.Reader, method string) (string, error) { 50 | b, err := io.ReadAll(r) 51 | 52 | if err != nil { 53 | return "", err 54 | } 55 | 56 | switch method { 57 | case "md5": 58 | return fmt.Sprintf("%x", md5.Sum(b)), nil 59 | case "sha1": 60 | return fmt.Sprintf("%x", sha1.Sum(b)), nil 61 | case "sha256": 62 | return fmt.Sprintf("%x", sha256.Sum256(b)), nil 63 | case "sha512": 64 | return fmt.Sprintf("%x", sha512.Sum512(b)), nil 65 | case "adler32": 66 | return strconv.FormatUint(uint64(adler32.Checksum(b)), 10), nil 67 | case "crc32": 68 | return strconv.FormatUint(uint64(crc32.ChecksumIEEE(b)), 10), nil 69 | } 70 | 71 | return "", fmt.Errorf("hashing method %s is not supported", method) 72 | } 73 | 74 | func writeChecksums(files, methods []string, format string, flatten bool) ([]string, error) { 75 | checksums := make(map[string][]string) 76 | 77 | for _, method := range methods { 78 | for _, file := range files { 79 | handle, err := os.Open(file) 80 | 81 | if err != nil { 82 | return nil, fmt.Errorf("failed to read %s artifact: %w", file, err) 83 | } 84 | 85 | hash, err := checksum(handle, method) 86 | 87 | if err != nil { 88 | return nil, err 89 | } 90 | 91 | checksums[method] = append(checksums[method], hash, file) 92 | } 93 | } 94 | 95 | for method, results := range checksums { 96 | filename := strings.Replace(format, "CHECKSUM", method, -1) 97 | f, err := os.Create(filename) 98 | 99 | if err != nil { 100 | return nil, err 101 | } 102 | 103 | for i := 0; i < len(results); i += 2 { 104 | hash := results[i] 105 | file := results[i+1] 106 | 107 | if flatten { 108 | file = filepath.Base(file) 109 | } 110 | 111 | if _, err := f.WriteString(fmt.Sprintf("%s %s\n", hash, file)); err != nil { 112 | return nil, err 113 | } 114 | } 115 | 116 | files = append(files, filename) 117 | } 118 | 119 | return files, nil 120 | } 121 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base", 4 | ":automergeMinor", 5 | ":automergeDigest" 6 | ], 7 | "enabledManagers": [ 8 | "dockerfile", 9 | "gomod" 10 | ], 11 | "dockerfile": { 12 | "fileMatch": [ 13 | "docker/Dockerfile\\.linux\\.(arm|arm64|amd64|multiarch)", 14 | "docker/Dockerfile\\.windows\\.(1809|1903|1909|2004)" 15 | ], 16 | "pinDigests": true 17 | }, 18 | "gomod": { 19 | "postUpdateOptions": [ 20 | "gomodTidy" 21 | ] 22 | }, 23 | "labels": [ 24 | "renovate" 25 | ] 26 | } 27 | --------------------------------------------------------------------------------