This commit is contained in:
parent
699948052d
commit
e473763538
18 changed files with 558 additions and 2 deletions
21
.drone.yml
Normal file
21
.drone.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- go build
|
||||||
|
- go test ./...
|
||||||
|
|
||||||
|
- name: publish
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
auto_tag: true
|
||||||
|
dockerfile: docker/Dockerfile
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
60
.drone.yml.multiarch
Normal file
60
.drone.yml.multiarch
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
# if you want to publish a multi-architecture image, replace the
|
||||||
|
# contents of the .drone.yml file with the contents of this file
|
||||||
|
|
||||||
|
kind: pipeline
|
||||||
|
type: docker
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: golang
|
||||||
|
commands:
|
||||||
|
- go build
|
||||||
|
- go test ./...
|
||||||
|
|
||||||
|
- name: publish
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-amd64
|
||||||
|
dockerfile: docker/Dockerfile
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
|
||||||
|
- name: publish_arm
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-arm
|
||||||
|
dockerfile: docker/Dockerfile.linux.arm
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
|
||||||
|
- name: publish_arm
|
||||||
|
image: plugins/docker
|
||||||
|
settings:
|
||||||
|
repo: itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: linux-arm64
|
||||||
|
dockerfile: docker/Dockerfile.linux.arm64
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
|
||||||
|
- name: manifest
|
||||||
|
image: plugins/manifest
|
||||||
|
settings:
|
||||||
|
spec: docker/manifest.tmpl
|
||||||
|
auto_tag: true
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
.env
|
||||||
|
release/
|
||||||
|
|
55
LICENSE.md
Normal file
55
LICENSE.md
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
# Blue Oak Model License
|
||||||
|
|
||||||
|
Version 1.0.0
|
||||||
|
|
||||||
|
## Purpose
|
||||||
|
|
||||||
|
This license gives everyone as much permission to work with
|
||||||
|
this software as possible, while protecting contributors
|
||||||
|
from liability.
|
||||||
|
|
||||||
|
## Acceptance
|
||||||
|
|
||||||
|
In order to receive this license, you must agree to its
|
||||||
|
rules. The rules of this license are both obligations
|
||||||
|
under that agreement and conditions to your license.
|
||||||
|
You must not do anything with this software that triggers
|
||||||
|
a rule that you cannot or will not follow.
|
||||||
|
|
||||||
|
## Copyright
|
||||||
|
|
||||||
|
Each contributor licenses you to do everything with this
|
||||||
|
software that would otherwise infringe that contributor's
|
||||||
|
copyright in it.
|
||||||
|
|
||||||
|
## Notices
|
||||||
|
|
||||||
|
You must ensure that everyone who gets a copy of
|
||||||
|
any part of this software from you, with or without
|
||||||
|
changes, also gets the text of this license or a link to
|
||||||
|
<https://blueoakcouncil.org/license/1.0.0>.
|
||||||
|
|
||||||
|
## Excuse
|
||||||
|
|
||||||
|
If anyone notifies you in writing that you have not
|
||||||
|
complied with [Notices](#notices), you can keep your
|
||||||
|
license by taking all practical steps to comply within 30
|
||||||
|
days after the notice. If you do not do so, your license
|
||||||
|
ends immediately.
|
||||||
|
|
||||||
|
## Patent
|
||||||
|
|
||||||
|
Each contributor licenses you to do everything with this
|
||||||
|
software that would otherwise infringe any patent claims
|
||||||
|
they can license or become able to license.
|
||||||
|
|
||||||
|
## Reliability
|
||||||
|
|
||||||
|
No contributor can revoke this license.
|
||||||
|
|
||||||
|
## No Liability
|
||||||
|
|
||||||
|
***As far as the law allows, this software comes as is,
|
||||||
|
without any warranty or condition, and no contributor
|
||||||
|
will be liable to anyone for any damages related to this
|
||||||
|
software or this license, under any kind of legal claim.***
|
53
README.md
53
README.md
|
@ -1,3 +1,52 @@
|
||||||
# codeberg-pages-deploy
|
A plugin to deploy to codeberg pages. Basically takes a folder and pushes it to the "pages" branch in the same repo..
|
||||||
|
|
||||||
A drone plugin to deploy to codeberg pages. Basically takes a folder and pushes it to the "pages" branch in the same repo.
|
# Usage
|
||||||
|
|
||||||
|
The following settings changes this plugin's behavior.
|
||||||
|
|
||||||
|
* param1 (optional) does something.
|
||||||
|
* param2 (optional) does something different.
|
||||||
|
|
||||||
|
Below is an example `.drone.yml` that uses this plugin.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
kind: pipeline
|
||||||
|
name: default
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: run itsblue.dev/plugins/codeberg-pages-deploy plugin
|
||||||
|
image: itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
pull: if-not-exists
|
||||||
|
settings:
|
||||||
|
param1: foo
|
||||||
|
param2: bar
|
||||||
|
```
|
||||||
|
|
||||||
|
# Building
|
||||||
|
|
||||||
|
Build the plugin binary:
|
||||||
|
|
||||||
|
```text
|
||||||
|
scripts/build.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Build the plugin image:
|
||||||
|
|
||||||
|
```text
|
||||||
|
docker build -t itsblue.dev/plugins/codeberg-pages-deploy -f docker/Dockerfile .
|
||||||
|
```
|
||||||
|
|
||||||
|
# Testing
|
||||||
|
|
||||||
|
Execute the plugin from your current working directory:
|
||||||
|
|
||||||
|
```text
|
||||||
|
docker run --rm -e PLUGIN_PARAM1=foo -e PLUGIN_PARAM2=bar \
|
||||||
|
-e DRONE_COMMIT_SHA=8f51ad7884c5eb69c11d260a31da7a745e6b78e2 \
|
||||||
|
-e DRONE_COMMIT_BRANCH=master \
|
||||||
|
-e DRONE_BUILD_NUMBER=43 \
|
||||||
|
-e DRONE_BUILD_STATUS=success \
|
||||||
|
-w /drone/src \
|
||||||
|
-v $(pwd):/drone/src \
|
||||||
|
itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
```
|
||||||
|
|
10
docker/Dockerfile
Normal file
10
docker/Dockerfile
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
FROM alpine:3.6 as alpine
|
||||||
|
RUN apk add -U --no-cache ca-certificates
|
||||||
|
|
||||||
|
FROM alpine:3.6
|
||||||
|
ENV GODEBUG netdns=go
|
||||||
|
|
||||||
|
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
||||||
|
ADD release/linux/amd64/plugin /bin/
|
||||||
|
ENTRYPOINT ["/bin/plugin"]
|
10
docker/Dockerfile.linux.arm
Normal file
10
docker/Dockerfile.linux.arm
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
FROM alpine:3.6 as alpine
|
||||||
|
RUN apk add -U --no-cache ca-certificates
|
||||||
|
|
||||||
|
FROM alpine:3.6
|
||||||
|
ENV GODEBUG netdns=go
|
||||||
|
|
||||||
|
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
||||||
|
ADD release/linux/arm/plugin /bin/
|
||||||
|
ENTRYPOINT ["/bin/plugin"]
|
10
docker/Dockerfile.linux.arm64
Normal file
10
docker/Dockerfile.linux.arm64
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
FROM alpine:3.6 as alpine
|
||||||
|
RUN apk add -U --no-cache ca-certificates
|
||||||
|
|
||||||
|
FROM alpine:3.6
|
||||||
|
ENV GODEBUG netdns=go
|
||||||
|
|
||||||
|
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||||
|
|
||||||
|
ADD release/linux/arm64/plugin /bin/
|
||||||
|
ENTRYPOINT ["/bin/plugin"]
|
31
docker/manifest.tmpl
Normal file
31
docker/manifest.tmpl
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
image: itsblue.dev/plugins/codeberg-pages-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||||
|
{{#if build.tags}}
|
||||||
|
tags:
|
||||||
|
{{#each build.tags}}
|
||||||
|
- {{this}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
manifests:
|
||||||
|
-
|
||||||
|
image: itsblue.dev/plugins/codeberg-pages-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||||
|
platform:
|
||||||
|
architecture: amd64
|
||||||
|
os: linux
|
||||||
|
-
|
||||||
|
image: itsblue.dev/plugins/codeberg-pages-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||||
|
platform:
|
||||||
|
variant: v8
|
||||||
|
architecture: arm64
|
||||||
|
os: linux
|
||||||
|
-
|
||||||
|
image: itsblue.dev/plugins/codeberg-pages-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||||
|
platform:
|
||||||
|
variant: v7
|
||||||
|
architecture: arm
|
||||||
|
os: linux
|
||||||
|
-
|
||||||
|
image: itsblue.dev/plugins/codeberg-pages-deploy:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm
|
||||||
|
platform:
|
||||||
|
variant: v6
|
||||||
|
architecture: arm
|
||||||
|
os: linux
|
8
go.mod
Normal file
8
go.mod
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module itsblue.dev/plugins/codeberg-pages-deploy
|
||||||
|
|
||||||
|
go 1.12
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/kelseyhightower/envconfig v1.4.0
|
||||||
|
github.com/sirupsen/logrus v1.4.2
|
||||||
|
)
|
9
go.sum
Normal file
9
go.sum
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
|
||||||
|
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||||
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
48
main.go
Normal file
48
main.go
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
// Copyright 2020 the Drone Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Blue Oak Model License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"itsblue.dev/plugins/codeberg-pages-deploy/plugin"
|
||||||
|
|
||||||
|
"github.com/kelseyhightower/envconfig"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
logrus.SetFormatter(new(formatter))
|
||||||
|
|
||||||
|
var args plugin.Args
|
||||||
|
if err := envconfig.Process("", &args); err != nil {
|
||||||
|
logrus.Fatalln(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch args.Level {
|
||||||
|
case "debug":
|
||||||
|
logrus.SetFormatter(textFormatter)
|
||||||
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
|
case "trace":
|
||||||
|
logrus.SetFormatter(textFormatter)
|
||||||
|
logrus.SetLevel(logrus.TraceLevel)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := plugin.Exec(context.Background(), args); err != nil {
|
||||||
|
logrus.Fatalln(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// default formatter that writes logs without including timestamp
|
||||||
|
// or level information.
|
||||||
|
type formatter struct {}
|
||||||
|
func (*formatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||||
|
return []byte(entry.Message), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// text formatter that writes logs with level information
|
||||||
|
var textFormatter = &logrus.TextFormatter{
|
||||||
|
DisableTimestamp: true,
|
||||||
|
}
|
149
plugin/pipeline.go
Normal file
149
plugin/pipeline.go
Normal file
|
@ -0,0 +1,149 @@
|
||||||
|
// Copyright 2020 the Drone Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Blue Oak Model License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
// Pipeline provides Pipeline metadata from the environment.
|
||||||
|
type Pipeline struct {
|
||||||
|
// Build provides build metadata.
|
||||||
|
Build struct {
|
||||||
|
Branch string `envconfig:"DRONE_BUILD_BRANCH"`
|
||||||
|
Number int `envconfig:"DRONE_BUILD_NUMBER"`
|
||||||
|
Parent int `envconfig:"DRONE_BUILD_PARENT"`
|
||||||
|
Event string `envconfig:"DRONE_BUILD_EVENT"`
|
||||||
|
Action string `envconfig:"DRONE_BUILD_ACTION"`
|
||||||
|
Status string `envconfig:"DRONE_BUILD_STATUS"`
|
||||||
|
Created int64 `envconfig:"DRONE_BUILD_CREATED"`
|
||||||
|
Started int64 `envconfig:"DRONE_BUILD_STARTED"`
|
||||||
|
Finished int64 `envconfig:"DRONE_BUILD_FINISHED"`
|
||||||
|
Link string `envconfig:"DRONE_BUILD_LINK"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calver provides the calver details parsed from the
|
||||||
|
// git tag. If the git tag is empty or is not a valid
|
||||||
|
// calver, the values will be empty.
|
||||||
|
Calver struct {
|
||||||
|
Version string `envconfig:"DRONE_CALVER"`
|
||||||
|
Short string `envconfig:"DRONE_CALVER_SHORT"`
|
||||||
|
MajorMinor string `envconfig:"DRONE_CALVER_MAJOR_MINOR"`
|
||||||
|
Major string `envconfig:"DRONE_CALVER_MAJOR"`
|
||||||
|
Minor string `envconfig:"DRONE_CALVER_MINOR"`
|
||||||
|
Micro string `envconfig:"DRONE_CALVER_MICRO"`
|
||||||
|
Modifier string `envconfig:"DRONE_CALVER_MODIFIER"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Card provides adaptive card configuration options.
|
||||||
|
Card struct {
|
||||||
|
Path string `envconfig:"DRONE_CARD_PATH"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit provides the commit metadata.
|
||||||
|
Commit struct {
|
||||||
|
Rev string `envconfig:"DRONE_COMMIT_SHA"`
|
||||||
|
Before string `envconfig:"DRONE_COMMIT_BEFORE"`
|
||||||
|
After string `envconfig:"DRONE_COMMIT_AFTER"`
|
||||||
|
Ref string `envconfig:"DRONE_COMMIT_REF"`
|
||||||
|
Branch string `envconfig:"DRONE_COMMIT_BRANCH"`
|
||||||
|
Source string `envconfig:"DRONE_COMMIT_SOURCE"`
|
||||||
|
Target string `envconfig:"DRONE_COMMIT_TARGET"`
|
||||||
|
Link string `envconfig:"DRONE_COMMIT_LINK"`
|
||||||
|
Message string `envconfig:"DRONE_COMMIT_MESSAGE"`
|
||||||
|
|
||||||
|
Author struct {
|
||||||
|
Username string `envconfig:"DRONE_COMMIT_AUTHOR"`
|
||||||
|
Name string `envconfig:"DRONE_COMMIT_AUTHOR_NAME"`
|
||||||
|
Email string `envconfig:"DRONE_COMMIT_AUTHOR_EMAIL"`
|
||||||
|
Avatar string `envconfig:"DRONE_COMMIT_AUTHOR_AVATAR"`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deploy provides the deployment metadata.
|
||||||
|
Deploy struct {
|
||||||
|
ID string `envconfig:"DRONE_DEPLOY_TO"`
|
||||||
|
Target string `envconfig:"DRONE_DEPLOY_ID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Failed provides a list of failed steps and failed stages
|
||||||
|
// for the current pipeline.
|
||||||
|
Failed struct {
|
||||||
|
Steps []string `envconfig:"DRONE_FAILED_STEPS"`
|
||||||
|
Stages []string `envconfig:"DRONE_FAILED_STAGES"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Git provides the git repository metadata.
|
||||||
|
Git struct {
|
||||||
|
HTTPURL string `envconfig:"DRONE_GIT_HTTP_URL"`
|
||||||
|
SSHURL string `envconfig:"DRONE_GIT_SSH_URL"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// PullRequest provides the pull request metadata.
|
||||||
|
PullRequest struct {
|
||||||
|
Number int `envconfig:"DRONE_PULL_REQUEST"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Repo provides the repository metadata.
|
||||||
|
Repo struct {
|
||||||
|
Branch string `envconfig:"DRONE_REPO_BRANCH"`
|
||||||
|
Link string `envconfig:"DRONE_REPO_LINK"`
|
||||||
|
Namespace string `envconfig:"DRONE_REPO_NAMESPACE"`
|
||||||
|
Name string `envconfig:"DRONE_REPO_NAME"`
|
||||||
|
Private bool `envconfig:"DRONE_REPO_PRIVATE"`
|
||||||
|
Remote string `envconfig:"DRONE_GIT_HTTP_URL"`
|
||||||
|
SCM string `envconfig:"DRONE_REPO_SCM"`
|
||||||
|
Slug string `envconfig:"DRONE_REPO"`
|
||||||
|
Visibility string `envconfig:"DRONE_REPO_VISIBILITY"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Stage provides the stage metadata.
|
||||||
|
Stage struct {
|
||||||
|
Kind string `envconfig:"DRONE_STAGE_KIND"`
|
||||||
|
Type string `envconfig:"DRONE_STAGE_TYPE"`
|
||||||
|
Name string `envconfig:"DRONE_STAGE_NAME"`
|
||||||
|
Number int `envconfig:"DRONE_STAGE_NUMBER"`
|
||||||
|
Machine string `envconfig:"DRONE_STAGE_MACHINE"`
|
||||||
|
OS string `envconfig:"DRONE_STAGE_OS"`
|
||||||
|
Arch string `envconfig:"DRONE_STAGE_ARCH"`
|
||||||
|
Variant string `envconfig:"DRONE_STAGE_VARIANT"`
|
||||||
|
Status string `envconfig:"DRONE_STAGE_STATUS"`
|
||||||
|
Started int64 `envconfig:"DRONE_STAGE_STARTED"`
|
||||||
|
Finished int64 `envconfig:"DRONE_STAGE_FINISHED"`
|
||||||
|
DependsOn []string `envconfig:"DRONE_STAGE_DEPENDS_ON"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step provides the step metadata.
|
||||||
|
Step struct {
|
||||||
|
Number int `envconfig:"DRONE_STEP_NUMBER"`
|
||||||
|
Name string `envconfig:"DRONE_STEP_NAME"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Semver provides the semver details parsed from the
|
||||||
|
// git tag. If the git tag is empty or is not a valid
|
||||||
|
// semver, the values will be empty and the error field
|
||||||
|
// will be populated with the parsing error.
|
||||||
|
Semver struct {
|
||||||
|
Version string `envconfig:"DRONE_SEMVER"`
|
||||||
|
Short string `envconfig:"DRONE_SEMVER_SHORT"`
|
||||||
|
Major string `envconfig:"DRONE_SEMVER_MAJOR"`
|
||||||
|
Minor string `envconfig:"DRONE_SEMVER_MINOR"`
|
||||||
|
Patch string `envconfig:"DRONE_SEMVER_PATCH"`
|
||||||
|
Build string `envconfig:"DRONE_SEMVER_BUILD"`
|
||||||
|
PreRelease string `envconfig:"DRONE_SEMVER_PRERELEASE"`
|
||||||
|
Error string `envconfig:"DRONE_SEMVER_ERROR"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// System provides the Drone system metadata, including
|
||||||
|
// the system version of details required to create the
|
||||||
|
// drone website address.
|
||||||
|
System struct {
|
||||||
|
Proto string `envconfig:"DRONE_SYSTEM_PROTO"`
|
||||||
|
Host string `envconfig:"DRONE_SYSTEM_HOST"`
|
||||||
|
Hostname string `envconfig:"DRONE_SYSTEM_HOSTNAME"`
|
||||||
|
Version string `envconfig:"DRONE_SYSTEM_VERSION"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Tag provides the git tag details.
|
||||||
|
Tag struct {
|
||||||
|
Name string `envconfig:"DRONE_TAG"`
|
||||||
|
}
|
||||||
|
}
|
25
plugin/plugin.go
Normal file
25
plugin/plugin.go
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// Copyright 2020 the Drone Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Blue Oak Model License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import "context"
|
||||||
|
|
||||||
|
// Args provides plugin execution arguments.
|
||||||
|
type Args struct {
|
||||||
|
Pipeline
|
||||||
|
|
||||||
|
// Level defines the plugin log level.
|
||||||
|
Level string `envconfig:"PLUGIN_LOG_LEVEL"`
|
||||||
|
|
||||||
|
// TODO replace or remove
|
||||||
|
Param1 string `envconfig:"PLUGIN_PARAM1"`
|
||||||
|
Param2 string `envconfig:"PLUGIN_PARAM2"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exec executes the plugin.
|
||||||
|
func Exec(ctx context.Context, args Args) error {
|
||||||
|
// write code here
|
||||||
|
return nil
|
||||||
|
}
|
11
plugin/plugin_test.go
Normal file
11
plugin/plugin_test.go
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
// Copyright 2020 the Drone Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Blue Oak Model License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestPlugin(t *testing.T) {
|
||||||
|
t.Skip()
|
||||||
|
}
|
36
plugin/util.go
Normal file
36
plugin/util.go
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright 2020 the Drone Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Blue Oak Model License
|
||||||
|
// that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func writeCard(path, schema string, card interface{}) {
|
||||||
|
data, _ := json.Marshal(map[string]interface{}{
|
||||||
|
"schema": schema,
|
||||||
|
"data": card,
|
||||||
|
})
|
||||||
|
switch {
|
||||||
|
case path == "/dev/stdout":
|
||||||
|
writeCardTo(os.Stdout, data)
|
||||||
|
case path == "/dev/stderr":
|
||||||
|
writeCardTo(os.Stderr, data)
|
||||||
|
case path != "":
|
||||||
|
ioutil.WriteFile(path, data, 0644)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeCardTo(out io.Writer, data []byte) {
|
||||||
|
encoded := base64.StdEncoding.EncodeToString(data)
|
||||||
|
io.WriteString(out, "\u001B]1338;")
|
||||||
|
io.WriteString(out, encoded)
|
||||||
|
io.WriteString(out, "\u001B]0m")
|
||||||
|
io.WriteString(out, "\n")
|
||||||
|
}
|
18
scripts/build.sh
Executable file
18
scripts/build.sh
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# force go modules
|
||||||
|
export GOPATH=""
|
||||||
|
|
||||||
|
# disable cgo
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
|
||||||
|
set -e
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# linux
|
||||||
|
GOOS=linux GOARCH=amd64 go build -o release/linux/amd64/plugin
|
||||||
|
GOOS=linux GOARCH=arm64 go build -o release/linux/arm64/plugin
|
||||||
|
GOOS=linux GOARCH=arm go build -o release/linux/arm/plugin
|
||||||
|
|
||||||
|
# windows
|
||||||
|
GOOS=windows go build -o release/windows/amd64/plugin.exe
|
3
scripts/upgrade.sh
Executable file
3
scripts/upgrade.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
curl https://raw.githubusercontent.com/drone/boilr-plugin/master/template/plugin/pipeline.go --output plugin/pipeline.go
|
Loading…
Reference in a new issue