Use plugin library

Migrates this plugin to the drone-plugin-lib. Follows the latest boilr template.
This commit is contained in:
Don
2021-06-16 13:40:07 -07:00
parent 2087ad8457
commit 9cfb4b925b
27 changed files with 827 additions and 1239 deletions
-14
View File
@@ -1,14 +0,0 @@
local pipeline = import 'pipeline.libsonnet';
local name = 'drone-gitea-release';
[
pipeline.test('linux', 'amd64'),
pipeline.build(name, 'linux', 'amd64'),
pipeline.build(name, 'linux', 'arm64'),
pipeline.build(name, 'linux', 'arm'),
pipeline.notifications(depends_on=[
'linux-amd64',
'linux-arm64',
'linux-arm',
]),
]
+342
View File
@@ -0,0 +1,342 @@
def main(ctx):
before = testing(ctx)
stages = [
linux(ctx, "amd64"),
linux(ctx, "arm64"),
linux(ctx, "arm"),
windows(ctx, "1909"),
windows(ctx, "1903"),
windows(ctx, "1809"),
]
after = manifest(ctx) + gitter(ctx)
for b in before:
for s in stages:
s["depends_on"].append(b["name"])
for s in stages:
for a in after:
a["depends_on"].append(s["name"])
return before + stages + after
def testing(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "testing",
"platform": {
"os": "linux",
"arch": "amd64",
},
"steps": [
{
"name": "staticcheck",
"image": "golang:1.15",
"pull": "always",
"commands": [
"go run honnef.co/go/tools/cmd/staticcheck ./...",
],
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
},
{
"name": "lint",
"image": "golang:1.15",
"commands": [
"go run golang.org/x/lint/golint -set_exit_status ./...",
],
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
},
{
"name": "vet",
"image": "golang:1.15",
"commands": [
"go vet ./...",
],
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
},
{
"name": "test",
"image": "golang:1.15",
"commands": [
"go test -cover ./...",
],
"volumes": [
{
"name": "gopath",
"path": "/go",
},
],
},
],
"volumes": [
{
"name": "gopath",
"temp": {},
},
],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
"refs/pull/**",
],
},
}]
def linux(ctx, arch):
if ctx.build.event == "tag":
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-gitea-release ./cmd/drone-gitea-release' % (ctx.build.ref.replace("refs/tags/v", ""), arch),
]
else:
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/linux/%s/drone-gitea-release ./cmd/drone-gitea-release' % (ctx.build.commit[0:8], arch),
]
steps = [
{
"name": "environment",
"image": "golang:1.15",
"pull": "always",
"environment": {
"CGO_ENABLED": "0",
},
"commands": [
"go version",
"go env",
],
},
{
"name": "build",
"image": "golang:1.15",
"environment": {
"CGO_ENABLED": "0",
},
"commands": build,
},
{
"name": "executable",
"image": "golang:1.15",
"commands": [
"./release/linux/%s/drone-gitea-release --help" % (arch),
],
},
]
if ctx.build.event != "pull_request":
steps.append({
"name": "docker",
"image": "plugins/docker",
"settings": {
"dockerfile": "docker/Dockerfile.linux.%s" % (arch),
"repo": "plugins/gitea-release",
"username": {
"from_secret": "docker_username",
},
"password": {
"from_secret": "docker_password",
},
"auto_tag": True,
"auto_tag_suffix": "linux-%s" % (arch),
},
})
return {
"kind": "pipeline",
"type": "docker",
"name": "linux-%s" % (arch),
"platform": {
"os": "linux",
"arch": arch,
},
"steps": steps,
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
"refs/pull/**",
],
},
}
def windows(ctx, version):
docker = [
"echo $env:PASSWORD | docker login --username $env:USERNAME --password-stdin",
]
if ctx.build.event == "tag":
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe ./cmd/drone-gitea-release' % (ctx.build.ref.replace("refs/tags/v", "")),
]
docker = docker + [
"docker build --pull -f docker/Dockerfile.windows.%s -t plugins/gitea-release:%s-windows-%s-amd64 ." % (version, ctx.build.ref.replace("refs/tags/v", ""), version),
"docker run --rm plugins/gitea-release:%s-windows-%s-amd64 --help" % (ctx.build.ref.replace("refs/tags/v", ""), version),
"docker push plugins/gitea-release:%s-windows-%s-amd64" % (ctx.build.ref.replace("refs/tags/v", ""), version),
]
else:
build = [
'go build -v -ldflags "-X main.version=%s" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe ./cmd/drone-gitea-release' % (ctx.build.commit[0:8]),
]
docker = docker + [
"docker build --pull -f docker/Dockerfile.windows.%s -t plugins/gitea-release:windows-%s-amd64 ." % (version, version),
"docker run --rm plugins/gitea-release:windows-%s-amd64 --help" % (version),
"docker push plugins/gitea-release:windows-%s-amd64" % (version),
]
return {
"kind": "pipeline",
"type": "ssh",
"name": "windows-%s" % (version),
"platform": {
"os": "windows",
},
"server": {
"host": {
"from_secret": "windows_server_%s" % (version),
},
"user": {
"from_secret": "windows_username",
},
"password": {
"from_secret": "windows_password",
},
},
"steps": [
{
"name": "environment",
"environment": {
"CGO_ENABLED": "0",
},
"commands": [
"go version",
"go env",
],
},
{
"name": "build",
"environment": {
"CGO_ENABLED": "0",
},
"commands": build,
},
{
"name": "executable",
"commands": [
"./release/windows/amd64/drone-gitea-release.exe --help",
],
},
{
"name": "docker",
"environment": {
"USERNAME": {
"from_secret": "docker_username",
},
"PASSWORD": {
"from_secret": "docker_password",
},
},
"commands": docker,
},
],
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
},
}
def manifest(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "manifest",
"steps": [
{
"name": "manifest",
"image": "plugins/manifest",
"settings": {
"auto_tag": "true",
"username": {
"from_secret": "docker_username",
},
"password": {
"from_secret": "docker_password",
},
"spec": "docker/manifest.tmpl",
"ignore_missing": "true",
},
},
{
"name": "microbadger",
"image": "plugins/webhook",
"settings": {
"urls": {
"from_secret": "microbadger_url",
},
},
},
],
"depends_on": [],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
},
}]
def gitter(ctx):
return [{
"kind": "pipeline",
"type": "docker",
"name": "gitter",
"clone": {
"disable": True,
},
"steps": [
{
"name": "gitter",
"image": "plugins/gitter",
"settings": {
"webhook": {
"from_secret": "gitter_webhook",
},
},
},
],
"depends_on": [
"manifest",
],
"trigger": {
"ref": [
"refs/heads/master",
"refs/tags/**",
],
"status": [
"failure",
],
},
}]
-9
View File
@@ -1,9 +0,0 @@
local pipeline = import 'pipeline.libsonnet';
local name = 'drone-gitea-release';
[
pipeline.test('windows', 'amd64', '1803'),
pipeline.build(name, 'windows', 'amd64', '1803'),
pipeline.build(name, 'windows', 'amd64', '1809'),
pipeline.notifications('windows', 'amd64', '1809', ['windows-1803', 'windows-1809']),
]
-273
View File
@@ -1,273 +0,0 @@
---
kind: pipeline
name: testing
platform:
os: windows
arch: amd64
version: 1803
steps:
- name: vet
pull: always
image: golang:1.13-windowsservercore-1803
commands:
- go vet ./...
environment:
GO111MODULE: on
volumes:
- name: gopath
path: C:\\gopath
- name: test
pull: always
image: golang:1.13-windowsservercore-1803
commands:
- go test -cover ./...
environment:
GO111MODULE: on
volumes:
- name: gopath
path: C:\\gopath
volumes:
- name: gopath
temp: {}
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
---
kind: pipeline
name: windows-1803
platform:
os: windows
arch: amd64
version: 1803
steps:
- name: build-push
pull: always
image: golang:1.13-windowsservercore-1803
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13-windowsservercore-1803
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13-windowsservercore-1803
commands:
- ./release/windows/amd64/drone-gitea-release.exe --help
- name: dryrun
pull: always
image: plugins/docker:windows-1803
settings:
daemon_off: true
dockerfile: docker/Dockerfile.windows.1803
dry_run: true
password:
from_secret: docker_password
repo: plugins/gitea-release
tags: windows-1803
username:
from_secret: docker_username
volumes:
- name: docker_pipe
path: \\\\.\\pipe\\docker_engine
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:windows-1803
settings:
auto_tag: true
auto_tag_suffix: windows-1803
daemon_off: true
dockerfile: docker/Dockerfile.windows.1803
password:
from_secret: docker_password
repo: plugins/gitea-release
username:
from_secret: docker_username
volumes:
- name: docker_pipe
path: \\\\.\\pipe\\docker_engine
when:
event:
exclude:
- pull_request
volumes:
- name: docker_pipe
host:
path: \\\\.\\pipe\\docker_engine
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
depends_on:
- testing
---
kind: pipeline
name: windows-1809
platform:
os: windows
arch: amd64
version: 1809
steps:
- name: build-push
pull: always
image: golang:1.13-windowsservercore-1809
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13-windowsservercore-1809
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/windows/amd64/drone-gitea-release.exe"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13-windowsservercore-1809
commands:
- ./release/windows/amd64/drone-gitea-release.exe --help
- name: dryrun
pull: always
image: plugins/docker:windows-1809
settings:
daemon_off: true
dockerfile: docker/Dockerfile.windows.1809
dry_run: true
password:
from_secret: docker_password
repo: plugins/gitea-release
tags: windows-1809
username:
from_secret: docker_username
volumes:
- name: docker_pipe
path: \\\\.\\pipe\\docker_engine
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:windows-1809
settings:
auto_tag: true
auto_tag_suffix: windows-1809
daemon_off: true
dockerfile: docker/Dockerfile.windows.1809
password:
from_secret: docker_password
repo: plugins/gitea-release
username:
from_secret: docker_username
volumes:
- name: docker_pipe
path: \\\\.\\pipe\\docker_engine
when:
event:
exclude:
- pull_request
volumes:
- name: docker_pipe
host:
path: \\\\.\\pipe\\docker_engine
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
depends_on:
- testing
---
kind: pipeline
name: notifications
platform:
os: windows
arch: amd64
version: 1809
steps:
- name: manifest
pull: always
image: plugins/manifest
settings:
auto_tag: true
ignore_missing: true
password:
from_secret: docker_password
spec: docker/manifest.tmpl
username:
from_secret: docker_username
- name: microbadger
pull: always
image: plugins/webhook
settings:
urls:
from_secret: microbadger_url
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
depends_on:
- windows-1803
- windows-1809
...
-332
View File
@@ -1,332 +0,0 @@
---
kind: pipeline
name: testing
platform:
os: linux
arch: amd64
steps:
- name: vet
pull: always
image: golang:1.13
commands:
- go vet ./...
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
- name: test
pull: always
image: golang:1.13
commands:
- go test -cover ./...
environment:
GO111MODULE: on
volumes:
- name: gopath
path: /go
volumes:
- name: gopath
temp: {}
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
---
kind: pipeline
name: linux-amd64
platform:
os: linux
arch: amd64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/amd64/drone-gitea-release"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/amd64/drone-gitea-release"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/amd64/drone-gitea-release --help
- name: dryrun
pull: always
image: plugins/docker:linux-amd64
settings:
daemon_off: false
dockerfile: docker/Dockerfile.linux.amd64
dry_run: true
password:
from_secret: docker_password
repo: plugins/gitea-release
tags: linux-amd64
username:
from_secret: docker_username
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-amd64
settings:
auto_tag: true
auto_tag_suffix: linux-amd64
daemon_off: false
dockerfile: docker/Dockerfile.linux.amd64
password:
from_secret: docker_password
repo: plugins/gitea-release
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
depends_on:
- testing
---
kind: pipeline
name: linux-arm64
platform:
os: linux
arch: arm64
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm64/drone-gitea-release"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm64/drone-gitea-release"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm64/drone-gitea-release --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm64
settings:
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm64
dry_run: true
password:
from_secret: docker_password
repo: plugins/gitea-release
tags: linux-arm64
username:
from_secret: docker_username
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm64
settings:
auto_tag: true
auto_tag_suffix: linux-arm64
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm64
password:
from_secret: docker_password
repo: plugins/gitea-release
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
depends_on:
- testing
---
kind: pipeline
name: linux-arm
platform:
os: linux
arch: arm
steps:
- name: build-push
pull: always
image: golang:1.13
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_COMMIT_SHA:0:8}\" -a -tags netgo -o release/linux/arm/drone-gitea-release"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
exclude:
- tag
- name: build-tag
pull: always
image: golang:1.13
commands:
- "go build -v -ldflags \"-X main.version=${DRONE_TAG##v}\" -a -tags netgo -o release/linux/arm/drone-gitea-release"
environment:
CGO_ENABLED: 0
GO111MODULE: on
when:
event:
- tag
- name: executable
pull: always
image: golang:1.13
commands:
- ./release/linux/arm/drone-gitea-release --help
- name: dryrun
pull: always
image: plugins/docker:linux-arm
settings:
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm
dry_run: true
password:
from_secret: docker_password
repo: plugins/gitea-release
tags: linux-arm
username:
from_secret: docker_username
when:
event:
- pull_request
- name: publish
pull: always
image: plugins/docker:linux-arm
settings:
auto_tag: true
auto_tag_suffix: linux-arm
daemon_off: false
dockerfile: docker/Dockerfile.linux.arm
password:
from_secret: docker_password
repo: plugins/gitea-release
username:
from_secret: docker_username
when:
event:
exclude:
- pull_request
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
- "refs/pull/**"
depends_on:
- testing
---
kind: pipeline
name: notifications
platform:
os: linux
arch: amd64
steps:
- name: manifest
pull: always
image: plugins/manifest
settings:
auto_tag: true
ignore_missing: true
password:
from_secret: docker_password
spec: docker/manifest.tmpl
username:
from_secret: docker_username
- name: microbadger
pull: always
image: plugins/webhook
settings:
urls:
from_secret: microbadger_url
trigger:
ref:
- refs/heads/master
- "refs/tags/**"
depends_on:
- linux-amd64
- linux-arm64
- linux-arm
...
+6 -2
View File
@@ -1,6 +1,6 @@
repository: repository:
name: drone-gitea-release name: drone-gitea-release
description: Drone plugin for creating and tagging Gitea releases description: Drone plugin for creating and tagging GitHub releases
homepage: http://plugins.drone.io/drone-plugins/drone-gitea-release homepage: http://plugins.drone.io/drone-plugins/drone-gitea-release
topics: drone, drone-plugin topics: drone, drone-plugin
@@ -69,5 +69,9 @@ branches:
- continuous-integration/drone/pr - continuous-integration/drone/pr
enforce_admins: false enforce_admins: false
restrictions: restrictions:
apps:
- renovate
users: [] users: []
teams: [] teams:
- Admins
- Maintainers
+3 -28
View File
@@ -1,30 +1,5 @@
# Compiled Object files, Static and Dynamic libs (Shared Objects) /release/
*.o /drone-gitea-release*
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
release/
vendor/
coverage.out coverage.out
drone-gitea-release .drone.yml
+69
View File
@@ -0,0 +1,69 @@
// Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package main
import (
"github.com/drone-plugins/drone-gitea-release/plugin"
"github.com/urfave/cli/v2"
)
// settingsFlags has the cli.Flags for the plugin.Settings.
func settingsFlags(settings *plugin.Settings) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "api-key",
Usage: "api key to access gitea api",
EnvVars: []string{"PLUGIN_API_KEY", "GITEA_RELEASE_API_KEY", "GITEA_TOKEN"},
Destination: &settings.APIKey,
},
&cli.StringSliceFlag{
Name: "files",
Usage: "list of files to upload",
EnvVars: []string{"PLUGIN_FILES", "GITEA_RELEASE_FILES"},
Destination: &settings.Files,
},
&cli.StringFlag{
Name: "file-exists",
Value: "overwrite",
Usage: "what to do if file already exist",
EnvVars: []string{"PLUGIN_FILE_EXISTS", "GITEA_RELEASE_FILE_EXISTS"},
Destination: &settings.FileExists,
},
&cli.StringSliceFlag{
Name: "checksum",
Usage: "generate specific checksums",
EnvVars: []string{"PLUGIN_CHECKSUM", "GITEA_RELEASE_CHECKSUM"},
Destination: &settings.Checksum},
&cli.BoolFlag{
Name: "draft",
Usage: "create a draft release",
EnvVars: []string{"PLUGIN_DRAFT", "GITEA_RELEASE_DRAFT"},
Destination: &settings.Draft},
&cli.BoolFlag{
Name: "prerelease",
Usage: "set the release as prerelease",
EnvVars: []string{"PLUGIN_PRERELEASE", "GITEA_RELEASE_PRERELEASE"},
Destination: &settings.PreRelease},
&cli.StringFlag{
Name: "base-url",
Usage: "url of the gitea instance",
EnvVars: []string{"PLUGIN_BASE_URL", "GITEA_RELEASE_BASE_URL"},
Destination: &settings.BaseURL},
&cli.StringFlag{
Name: "title",
Value: "",
Usage: "file or string for the title shown in the gitea release",
EnvVars: []string{"PLUGIN_TITLE", "GITEA_RELEASE_TITLE"},
Destination: &settings.Title},
&cli.StringFlag{
Name: "note",
Value: "",
Usage: "file or string with notes for the release (example: changelog)",
EnvVars: []string{"PLUGIN_NOTE", "GITEA_RELEASE_NOTE"},
Destination: &settings.Note},
}
}
+70
View File
@@ -0,0 +1,70 @@
// Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
// DO NOT MODIFY THIS FILE DIRECTLY
package main
import (
"os"
"github.com/drone-plugins/drone-gitea-release/plugin"
"github.com/drone-plugins/drone-plugin-lib/errors"
"github.com/drone-plugins/drone-plugin-lib/urfave"
"github.com/joho/godotenv"
"github.com/urfave/cli/v2"
)
var version = "unknown"
func main() {
settings := &plugin.Settings{}
if _, err := os.Stat("/run/drone/env"); err == nil {
godotenv.Overload("/run/drone/env")
}
app := &cli.App{
Name: "drone-gitea-release",
Usage: "creates a gitea release",
Version: version,
Flags: append(settingsFlags(settings), urfave.Flags()...),
Action: run(settings),
}
if err := app.Run(os.Args); err != nil {
errors.HandleExit(err)
}
}
func run(settings *plugin.Settings) cli.ActionFunc {
return func(ctx *cli.Context) error {
urfave.LoggingFromContext(ctx)
plugin := plugin.New(
*settings,
urfave.PipelineFromContext(ctx),
urfave.NetworkFromContext(ctx),
)
if err := plugin.Validate(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("validation failed: %w", err)
}
if err := plugin.Execute(); err != nil {
if e, ok := err.(errors.ExitCoder); ok {
return e
}
return errors.ExitMessagef("execution failed: %w", err)
}
return nil
}
}
+1 -1
View File
@@ -6,4 +6,4 @@ LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" \
org.label-schema.schema-version="1.0" org.label-schema.schema-version="1.0"
ADD release/linux/amd64/drone-gitea-release /bin/ ADD release/linux/amd64/drone-gitea-release /bin/
ENTRYPOINT ["/bin/drone-gitea-release"] ENTRYPOINT [ "/bin/drone-gitea-release" ]
+1 -1
View File
@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/base:windows-1809 FROM plugins/base:windows-1809-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Gitea Release" ` org.label-schema.name="Drone Gitea Release" `
+10
View File
@@ -0,0 +1,10 @@
# escape=`
FROM plugins/base:windows-1903-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Gitea Release" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-gitea-release.exe C:/bin/drone-gitea-release.exe
ENTRYPOINT [ "C:\\bin\\drone-gitea-release.exe" ]
+10
View File
@@ -0,0 +1,10 @@
# escape=`
FROM plugins/base:windows-1909-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Gitea Release" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-gitea-release.exe C:/bin/drone-gitea-release.exe
ENTRYPOINT [ "C:\\bin\\drone-gitea-release.exe" ]
+10
View File
@@ -0,0 +1,10 @@
# escape=`
FROM plugins/base:windows-2004-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Gitea Release" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-gitea-release.exe C:/bin/drone-gitea-release.exe
ENTRYPOINT [ "C:\\bin\\drone-gitea-release.exe" ]
+18 -11
View File
@@ -1,36 +1,43 @@
image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
{{#if build.tags}} {{#if build.tags}}
tags: tags:
{{#each build.tags}} {{#each build.tags}}
- {{this}} - {{this}}
{{/each}} {{/each}}
{{/if}} {{/if}}
manifests: manifests:
- - image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: linux os: linux
- - image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
platform: platform:
architecture: arm64 architecture: arm64
os: linux os: linux
variant: v8 variant: v8
- - image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
platform: platform:
architecture: arm architecture: arm
os: linux os: linux
variant: v7 variant: v7
- - image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-2004-amd64
image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1803 version: 2004
- - image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809 platform:
architecture: amd64
os: windows
version: 1909
- image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64
platform:
architecture: amd64
os: windows
version: 1903
- image: plugins/gitea-release:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
+4 -8
View File
@@ -1,14 +1,10 @@
module github.com/drone-plugins/drone-gitea-release module github.com/drone-plugins/drone-gitea-release
go 1.14 go 1.15
require ( require (
code.gitea.io/sdk/gitea v0.13.2 code.gitea.io/sdk/gitea v0.14.0
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/drone-plugins/drone-plugin-lib v0.4.0
github.com/joho/godotenv v1.3.0 github.com/joho/godotenv v1.3.0
github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/urfave/cli/v2 v2.3.0
github.com/sirupsen/logrus v1.7.0
github.com/urfave/cli v1.22.5
golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f // indirect
gopkg.in/yaml.v2 v2.3.0 // indirect
) )
+26 -17
View File
@@ -1,39 +1,48 @@
code.gitea.io/sdk/gitea v0.13.2 h1:wAnT/J7Z62q3fJXbgnecoaOBh8CM1Qq0/DakWxiv4yA= code.gitea.io/sdk/gitea v0.14.0 h1:m4J352I3p9+bmJUfS+g0odeQzBY/5OXP91Gv6D4fnJ0=
code.gitea.io/sdk/gitea v0.13.2/go.mod h1:lee2y8LeV3kQb2iK+hHlMqoadL4bp27QOkOV/hawLKg= code.gitea.io/sdk/gitea v0.14.0/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI= github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg= github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.7.0 h1:ShrD1U9pZB12TX0cVy0DtePoCH97K8EtX+mg7ZARUtM= github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f h1:QdHQnPce6K4XQewki9WNbG5KOROuDzqO3NaYjI1cXJ0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/sys v0.0.0-20201211090839-8ad439b19e0f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
-139
View File
@@ -1,139 +0,0 @@
package main
import (
"os"
"github.com/sirupsen/logrus"
"github.com/joho/godotenv"
"github.com/urfave/cli"
)
var (
version = "unknown"
)
func main() {
app := cli.NewApp()
app.Name = "gitea-release plugin"
app.Usage = "gitea-release plugin"
app.Action = run
app.Version = version
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "api-key",
Usage: "api key to access gitea api",
EnvVar: "PLUGIN_API_KEY,GITEA_RELEASE_API_KEY,GITEA_TOKEN",
},
cli.StringSliceFlag{
Name: "files",
Usage: "list of files to upload",
EnvVar: "PLUGIN_FILES,GITEA_RELEASE_FILES",
},
cli.StringFlag{
Name: "file-exists",
Value: "overwrite",
Usage: "what to do if file already exist",
EnvVar: "PLUGIN_FILE_EXISTS,GITEA_RELEASE_FILE_EXISTS",
},
cli.StringSliceFlag{
Name: "checksum",
Usage: "generate specific checksums",
EnvVar: "PLUGIN_CHECKSUM,GITEA_RELEASE_CHECKSUM",
},
cli.BoolFlag{
Name: "draft",
Usage: "create a draft release",
EnvVar: "PLUGIN_DRAFT,GITEA_RELEASE_DRAFT",
},
cli.BoolFlag{
Name: "insecure",
Usage: "visit base-url via insecure https protocol",
EnvVar: "PLUGIN_INSECURE,GITEA_RELEASE_INSECURE",
},
cli.BoolFlag{
Name: "prerelease",
Usage: "set the release as prerelease",
EnvVar: "PLUGIN_PRERELEASE,GITEA_RELEASE_PRERELEASE",
},
cli.StringFlag{
Name: "base-url",
Usage: "url of the gitea instance",
EnvVar: "PLUGIN_BASE_URL,GITEA_RELEASE_BASE_URL",
},
cli.StringFlag{
Name: "note",
Value: "",
Usage: "file or string with notes for the release (example: changelog)",
EnvVar: "PLUGIN_NOTE,GITEA_RELEASE_NOTE",
},
cli.StringFlag{
Name: "title",
Value: "",
Usage: "file or string for the title shown in the gitea release",
EnvVar: "PLUGIN_TITLE,GITEA_RELEASE_TITLE",
},
cli.StringFlag{
Name: "repo.owner",
Usage: "repository owner",
EnvVar: "DRONE_REPO_OWNER",
},
cli.StringFlag{
Name: "repo.name",
Usage: "repository name",
EnvVar: "DRONE_REPO_NAME",
},
cli.StringFlag{
Name: "build.event",
Value: "push",
Usage: "build event",
EnvVar: "DRONE_BUILD_EVENT",
},
cli.StringFlag{
Name: "commit.ref",
Value: "refs/heads/master",
Usage: "git commit ref",
EnvVar: "DRONE_COMMIT_REF",
},
cli.StringFlag{
Name: "env-file",
Usage: "source env file",
},
}
if err := app.Run(os.Args); err != nil {
logrus.Fatal(err)
}
}
func run(c *cli.Context) error {
if c.String("env-file") != "" {
_ = godotenv.Load(c.String("env-file"))
}
plugin := Plugin{
Repo: Repo{
Owner: c.String("repo.owner"),
Name: c.String("repo.name"),
},
Build: Build{
Event: c.String("build.event"),
},
Commit: Commit{
Ref: c.String("commit.ref"),
},
Config: Config{
APIKey: c.String("api-key"),
Files: c.StringSlice("files"),
FileExists: c.String("file-exists"),
Checksum: c.StringSlice("checksum"),
Draft: c.Bool("draft"),
PreRelease: c.Bool("prerelease"),
BaseURL: c.String("base-url"),
Insecure: c.Bool("insecure"),
Title: c.String("title"),
Note: c.String("note"),
},
}
return plugin.Exec()
}
-205
View File
@@ -1,205 +0,0 @@
local windows_pipe = '\\\\\\\\.\\\\pipe\\\\docker_engine';
local windows_pipe_volume = 'docker_pipe';
local test_pipeline_name = 'testing';
local windows(os) = os == 'windows';
local golang_image(os, version) =
'golang:' + '1.11' + if windows(os) then '-windowsservercore-' + version else '';
{
test(os='linux', arch='amd64', version='')::
local is_windows = windows(os);
local golang = golang_image(os, version);
local volumes = if is_windows then [{name: 'gopath', path: 'C:\\\\gopath'}] else [{name: 'gopath', path: '/go',}];
{
kind: 'pipeline',
name: test_pipeline_name,
platform: {
os: os,
arch: arch,
version: if std.length(version) > 0 then version,
},
steps: [
{
name: 'vet',
image: golang,
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'go vet ./...',
],
volumes: volumes,
},
{
name: 'test',
image: golang,
pull: 'always',
environment: {
GO111MODULE: 'on',
},
commands: [
'go test -cover ./...',
],
volumes: volumes,
},
],
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
'refs/pull/**',
],
},
volumes: [{name: 'gopath', temp: {}}]
},
build(name, os='linux', arch='amd64', version='')::
local is_windows = windows(os);
local tag = if is_windows then os + '-' + version else os + '-' + arch;
local file_suffix = std.strReplace(tag, '-', '.');
local volumes = if is_windows then [{ name: windows_pipe_volume, path: windows_pipe }] else [];
local golang = golang_image(os, version);
local plugin_repo = 'plugins/' + std.splitLimit(name, '-', 1)[1];
local extension = if is_windows then '.exe' else '';
{
kind: 'pipeline',
name: tag,
platform: {
os: os,
arch: arch,
version: if std.length(version) > 0 then version,
},
steps: [
{
name: 'build-push',
image: golang,
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/' + os + '/' + arch + '/' + name + extension,
],
when: {
event: {
exclude: ['tag'],
},
},
},
{
name: 'build-tag',
image: golang,
pull: 'always',
environment: {
CGO_ENABLED: '0',
GO111MODULE: 'on',
},
commands: [
'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/' + os + '/' + arch + '/' + name + extension,
],
when: {
event: ['tag'],
},
},
{
name: 'executable',
image: golang,
pull: 'always',
commands: [
'./release/' + os + '/' + arch + '/' + name + extension + ' --help',
],
},
{
name: 'dryrun',
image: 'plugins/docker:' + tag,
pull: 'always',
settings: {
dry_run: true,
tags: tag,
dockerfile: 'docker/Dockerfile.' + file_suffix,
daemon_off: if is_windows then 'true' else 'false',
repo: plugin_repo,
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
},
volumes: if std.length(volumes) > 0 then volumes,
when: {
event: ['pull_request'],
},
},
{
name: 'publish',
image: 'plugins/docker:' + tag,
pull: 'always',
settings: {
auto_tag: true,
auto_tag_suffix: tag,
daemon_off: if is_windows then 'true' else 'false',
dockerfile: 'docker/Dockerfile.' + file_suffix,
repo: plugin_repo,
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
},
volumes: if std.length(volumes) > 0 then volumes,
when: {
event: {
exclude: ['pull_request'],
},
},
},
],
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
'refs/pull/**',
],
},
depends_on: [test_pipeline_name],
volumes: if is_windows then [{ name: windows_pipe_volume, host: { path: windows_pipe } }],
},
notifications(os='linux', arch='amd64', version='', depends_on=[])::
{
kind: 'pipeline',
name: 'notifications',
platform: {
os: os,
arch: arch,
version: if std.length(version) > 0 then version,
},
steps: [
{
name: 'manifest',
image: 'plugins/manifest',
pull: 'always',
settings: {
username: { from_secret: 'docker_username' },
password: { from_secret: 'docker_password' },
spec: 'docker/manifest.tmpl',
ignore_missing: true,
auto_tag: true,
},
},
{
name: 'microbadger',
image: 'plugins/webhook',
pull: 'always',
settings: {
urls: { from_secret: 'microbadger_url' },
},
},
],
trigger: {
ref: [
'refs/heads/master',
'refs/tags/**',
],
},
depends_on: depends_on,
},
}
-172
View File
@@ -1,172 +0,0 @@
package main
import (
"crypto/tls"
"fmt"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"os"
"path/filepath"
"strings"
"code.gitea.io/sdk/gitea"
)
type (
Repo struct {
Owner string
Name string
}
Build struct {
Event string
}
Commit struct {
Ref string
}
Config struct {
APIKey string
Files []string
FileExists string
Checksum []string
Draft bool
PreRelease bool
Insecure bool
BaseURL string
Title string
Note string
}
Plugin struct {
Repo Repo
Build Build
Commit Commit
Config Config
}
)
func (p Plugin) Exec() error {
var (
files []string
)
if p.Build.Event != "tag" {
return fmt.Errorf("The Gitea Release plugin is only available for tags")
}
if p.Config.APIKey == "" {
return fmt.Errorf("You must provide an API key")
}
if !fileExistsValues[p.Config.FileExists] {
return fmt.Errorf("Invalid value for file_exists")
}
if p.Config.BaseURL == "" {
return fmt.Errorf("You must provide a base url.")
}
if !strings.HasSuffix(p.Config.BaseURL, "/") {
p.Config.BaseURL = p.Config.BaseURL + "/"
}
var err error
if p.Config.Note != "" {
if p.Config.Note, err = readStringOrFile(p.Config.Note); err != nil {
return fmt.Errorf("error while reading %s: %v", p.Config.Note, err)
}
}
if p.Config.Title != "" {
if p.Config.Title, err = readStringOrFile(p.Config.Title); err != nil {
return fmt.Errorf("error while reading %s: %v", p.Config.Note, err)
}
}
for _, glob := range p.Config.Files {
globed, err := filepath.Glob(glob)
if err != nil {
return fmt.Errorf("Failed to glob %s. %s", glob, err)
}
if globed != nil {
files = append(files, globed...)
}
}
if len(p.Config.Checksum) > 0 {
var (
err error
)
files, err = writeChecksums(files, p.Config.Checksum)
if err != nil {
return fmt.Errorf("Failed to write checksums. %s", err)
}
}
httpClient := &http.Client{}
if p.Config.Insecure {
cookieJar, _ := cookiejar.New(nil)
httpClient = &http.Client{
Jar: cookieJar,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
}
}
client, err := gitea.NewClient(p.Config.BaseURL, gitea.SetToken(p.Config.APIKey), gitea.SetHTTPClient(httpClient))
if err != nil {
return err
}
rc := releaseClient{
Client: client,
Owner: p.Repo.Owner,
Repo: p.Repo.Name,
Tag: strings.TrimPrefix(p.Commit.Ref, "refs/tags/"),
Draft: p.Config.Draft,
Prerelease: p.Config.PreRelease,
FileExists: p.Config.FileExists,
Title: p.Config.Title,
Note: p.Config.Note,
}
// if the title was not provided via .drone.yml we use the tag instead
// fixes https://github.com/drone-plugins/drone-gitea-release/issues/26
if rc.Title == "" {
rc.Title = rc.Tag
}
release, err := rc.buildRelease()
if err != nil {
return fmt.Errorf("Failed to create the release. %s", err)
}
if err := rc.uploadFiles(release.ID, files); err != nil {
return fmt.Errorf("Failed to upload the files. %s", err)
}
return nil
}
func readStringOrFile(input string) (string, error) {
// Check if input is a file path
if _, err := os.Stat(input); err != nil && os.IsNotExist(err) {
// No file found => use input as result
return input, nil
} else if err != nil {
return "", err
}
result, err := ioutil.ReadFile(input)
if err != nil {
return "", err
}
return string(result), nil
}
+132
View File
@@ -0,0 +1,132 @@
// Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"fmt"
"path/filepath"
"strings"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
)
// Settings for the plugin.
type Settings struct {
APIKey string
Files cli.StringSlice
FileExists string
Checksum cli.StringSlice
Draft bool
PreRelease bool
BaseURL string
Title string
Note string
uploads []string
}
// Validate handles the settings validation of the plugin.
func (p *Plugin) Validate() error {
var err error
if p.pipeline.Build.Event != "tag" {
return fmt.Errorf("gitea release plugin is only available for tags")
}
if p.settings.APIKey == "" {
return fmt.Errorf("no api key provided")
}
if !fileExistsValues[p.settings.FileExists] {
return fmt.Errorf("invalid value for file_exists")
}
if p.settings.BaseURL == "" {
return fmt.Errorf("no base url provided")
}
if !strings.HasSuffix(p.settings.BaseURL, "/") {
p.settings.BaseURL = p.settings.BaseURL + "/"
}
if p.settings.Note != "" {
if p.settings.Note, err = readStringOrFile(p.settings.Note); err != nil {
return fmt.Errorf("error while reading %s: %w", p.settings.Note, err)
}
}
if p.settings.Title != "" {
if p.settings.Title, err = readStringOrFile(p.settings.Title); err != nil {
return fmt.Errorf("error while reading %s: %w", p.settings.Note, err)
}
}
files := p.settings.Files.Value()
for _, glob := range files {
globed, err := filepath.Glob(glob)
if err != nil {
return fmt.Errorf("failed to glob %s: %w", glob, err)
}
if globed != nil {
p.settings.uploads = append(p.settings.uploads, globed...)
}
}
if len(files) > 0 && len(p.settings.uploads) < 1 {
return fmt.Errorf("failed to find any file to release")
}
checksum := p.settings.Checksum.Value()
if len(checksum) > 0 {
p.settings.uploads, err = writeChecksums(files, checksum)
if err != nil {
return fmt.Errorf("failed to write checksums: %w", err)
}
}
return nil
}
// Execute provides the implementation of the plugin.
func (p *Plugin) Execute() error {
client, err := gitea.NewClient(p.settings.BaseURL, gitea.SetToken(p.settings.APIKey), gitea.SetHTTPClient(p.network.Client))
if err != nil {
return err
}
rc := releaseClient{
Client: client,
Owner: p.pipeline.Repo.Owner,
Repo: p.pipeline.Repo.Name,
Tag: strings.TrimPrefix(p.pipeline.Commit.Ref, "refs/tags/"),
Draft: p.settings.Draft,
Prerelease: p.settings.PreRelease,
FileExists: p.settings.FileExists,
Title: p.settings.Title,
Note: p.settings.Note,
}
// When the title was not provided in the config use the tag instead
if rc.Title == "" {
rc.Title = rc.Tag
}
release, err := rc.buildRelease()
if err != nil {
return fmt.Errorf("failed to create the release. %s", err)
}
if err := rc.uploadFiles(release.ID, p.settings.uploads); err != nil {
return fmt.Errorf("failed to upload the files. %s", err)
}
return nil
}
+18
View File
@@ -0,0 +1,18 @@
// Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"testing"
)
func TestValidate(t *testing.T) {
t.Skip()
}
func TestExecute(t *testing.T) {
t.Skip()
}
+26
View File
@@ -0,0 +1,26 @@
// Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"github.com/drone-plugins/drone-plugin-lib/drone"
)
// Plugin implements drone.Plugin to provide the plugin implementation.
type Plugin struct {
settings Settings
pipeline drone.Pipeline
network drone.Network
}
// New initializes a plugin from the given Settings, Pipeline, and Network.
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
return &Plugin{
settings: settings,
pipeline: pipeline,
network: network,
}
}
+14
View File
@@ -0,0 +1,14 @@
// Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import (
"testing"
)
func TestPlugin(t *testing.T) {
t.Skip()
}
+20 -15
View File
@@ -1,4 +1,9 @@
package main // Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import ( import (
"fmt" "fmt"
@@ -35,7 +40,7 @@ func (rc *releaseClient) buildRelease() (*gitea.Release, error) {
release, err = rc.newRelease() release, err = rc.newRelease()
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to retrieve or create a release: %s", err) return nil, fmt.Errorf("failed to retrieve or create a release: %s", err)
} }
return release, nil return release, nil
@@ -49,11 +54,11 @@ func (rc *releaseClient) getRelease() (*gitea.Release, error) {
for _, release := range releases { for _, release := range releases {
if release.TagName == rc.Tag { if release.TagName == rc.Tag {
fmt.Printf("Successfully retrieved %s release\n", rc.Tag) fmt.Printf("successfully retrieved %s release\n", rc.Tag)
return release, nil return release, nil
} }
} }
return nil, fmt.Errorf("Release %s not found", rc.Tag) return nil, fmt.Errorf("release %s not found", rc.Tag)
} }
func (rc *releaseClient) newRelease() (*gitea.Release, error) { func (rc *releaseClient) newRelease() (*gitea.Release, error) {
@@ -67,10 +72,10 @@ func (rc *releaseClient) newRelease() (*gitea.Release, error) {
release, _, err := rc.Client.CreateRelease(rc.Owner, rc.Repo, r) release, _, err := rc.Client.CreateRelease(rc.Owner, rc.Repo, r)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to create release: %s", err) return nil, fmt.Errorf("failed to create release: %s", err)
} }
fmt.Printf("Successfully created %s release\n", rc.Tag) fmt.Printf("successfully created %s release\n", rc.Tag)
return release, nil return release, nil
} }
@@ -78,7 +83,7 @@ func (rc *releaseClient) uploadFiles(releaseID int64, files []string) error {
attachments, _, err := rc.Client.ListReleaseAttachments(rc.Owner, rc.Repo, releaseID, gitea.ListReleaseAttachmentsOptions{}) attachments, _, err := rc.Client.ListReleaseAttachments(rc.Owner, rc.Repo, releaseID, gitea.ListReleaseAttachmentsOptions{})
if err != nil { if err != nil {
return fmt.Errorf("Failed to fetch existing assets: %s", err) return fmt.Errorf("failed to fetch existing assets: %s", err)
} }
var uploadFiles []string var uploadFiles []string
@@ -91,12 +96,12 @@ files:
case "overwrite": case "overwrite":
// do nothing // do nothing
case "fail": case "fail":
return fmt.Errorf("Asset file %s already exists", path.Base(file)) return fmt.Errorf("asset file %s already exists", path.Base(file))
case "skip": case "skip":
fmt.Printf("Skipping pre-existing %s artifact\n", attachment.Name) fmt.Printf("skipping pre-existing %s artifact\n", attachment.Name)
continue files continue files
default: default:
return fmt.Errorf("Internal error, unkown file_exist value %s", rc.FileExists) return fmt.Errorf("internal error, unkown file_exist value %s", rc.FileExists)
} }
} }
} }
@@ -108,24 +113,24 @@ files:
handle, err := os.Open(file) handle, err := os.Open(file)
if err != nil { if err != nil {
return fmt.Errorf("Failed to read %s artifact: %s", file, err) return fmt.Errorf("failed to read %s artifact: %s", file, err)
} }
for _, attachment := range attachments { for _, attachment := range attachments {
if attachment.Name == path.Base(file) { if attachment.Name == path.Base(file) {
if _, err := rc.Client.DeleteReleaseAttachment(rc.Owner, rc.Repo, releaseID, attachment.ID); err != nil { if _, err := rc.Client.DeleteReleaseAttachment(rc.Owner, rc.Repo, releaseID, attachment.ID); err != nil {
return fmt.Errorf("Failed to delete %s artifact: %s", file, err) return fmt.Errorf("failed to delete %s artifact: %s", file, err)
} }
fmt.Printf("Successfully deleted old %s artifact\n", attachment.Name) fmt.Printf("successfully deleted old %s artifact\n", attachment.Name)
} }
} }
if _, _, err = rc.Client.CreateReleaseAttachment(rc.Owner, rc.Repo, releaseID, handle, path.Base(file)); err != nil { if _, _, err = rc.Client.CreateReleaseAttachment(rc.Owner, rc.Repo, releaseID, handle, path.Base(file)); err != nil {
return fmt.Errorf("Failed to upload %s artifact: %s", file, err) return fmt.Errorf("failed to upload %s artifact: %s", file, err)
} }
fmt.Printf("Successfully uploaded %s artifact\n", file) fmt.Printf("successfully uploaded %s artifact\n", file)
} }
return nil return nil
+21 -12
View File
@@ -1,4 +1,9 @@
package main // Copyright (c) 2021, the Drone Plugins project authors.
// Please see the AUTHORS file for details. All rights reserved.
// Use of this source code is governed by an Apache 2.0 license that can be
// found in the LICENSE file.
package plugin
import ( import (
"crypto/md5" "crypto/md5"
@@ -11,9 +16,7 @@ import (
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"os/exec"
"strconv" "strconv"
"strings"
) )
var ( var (
@@ -24,13 +27,19 @@ var (
} }
) )
func execute(cmd *exec.Cmd) error { func readStringOrFile(input string) (string, error) {
fmt.Println("+", strings.Join(cmd.Args, " ")) // Check if input is a file path
if _, err := os.Stat(input); err != nil && os.IsNotExist(err) {
cmd.Stderr = os.Stderr // No file found => use input as result
cmd.Stdin = os.Stdin return input, nil
} else if err != nil {
return cmd.Run() return "", err
}
result, err := ioutil.ReadFile(input)
if err != nil {
return "", err
}
return string(result), nil
} }
func checksum(r io.Reader, method string) (string, error) { func checksum(r io.Reader, method string) (string, error) {
@@ -55,7 +64,7 @@ func checksum(r io.Reader, method string) (string, error) {
return strconv.FormatUint(uint64(crc32.ChecksumIEEE(b)), 10), nil return strconv.FormatUint(uint64(crc32.ChecksumIEEE(b)), 10), nil
} }
return "", fmt.Errorf("Hashing method %s is not supported", method) return "", fmt.Errorf("hashing method %s is not supported", method)
} }
func writeChecksums(files, methods []string) ([]string, error) { func writeChecksums(files, methods []string) ([]string, error) {
@@ -66,7 +75,7 @@ func writeChecksums(files, methods []string) ([]string, error) {
handle, err := os.Open(file) handle, err := os.Open(file)
if err != nil { if err != nil {
return nil, fmt.Errorf("Failed to read %s artifact: %s", file, err) return nil, fmt.Errorf("failed to read %s artifact: %s", file, err)
} }
hash, err := checksum(handle, method) hash, err := checksum(handle, method)
+26
View File
@@ -0,0 +1,26 @@
{
"extends": [
"config:base",
":automergeMinor",
":automergeDigest"
],
"enabledManagers": [
"dockerfile",
"gomod"
],
"dockerfile": {
"fileMatch": [
"docker/Dockerfile\\.linux\\.(arm|arm64|amd64|multiarch)",
"docker/Dockerfile\\.windows\\.(1809|1903|1909|2004)"
],
"pinDigests": true
},
"gomod": {
"postUpdateOptions": [
"gomodTidy"
]
},
"labels": [
"renovate"
]
}