Browse Source

Initial Commit

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main
jolheiser 1 month ago
commit
abc1ed471f
Signed by: jolheiser GPG Key ID: B853ADA5DA7BBF7A
  1. 1
      .gitignore
  2. 19
      LICENSE
  3. 11
      README.md
  4. 106
      env.go
  5. 190
      env.json
  6. 11
      go.mod
  7. 28
      go.sum
  8. 94
      input.json
  9. 107
      main.go

1
.gitignore

@ -0,0 +1 @@
.idea/

19
LICENSE

@ -0,0 +1,19 @@
Copyright (c) 2021 John Olheiser
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

11
README.md

@ -0,0 +1,11 @@
# Woodpecker Env
Woodpecker Environment variables for plugins.
## Updating
Replace the [input](input.json) and re-run `go generate ./...`
## License
[MIT](LICENSE)

106
env.go

@ -0,0 +1,106 @@
package env
import (
"os"
)
// List of CI env variables with an example value comment
var (
CI string // Example: drone
CI_BUILD_CREATED string // Example: 1639112012
CI_BUILD_EVENT string // Example: pull_request
CI_BUILD_FINISHED string // Example: 1639112085
CI_BUILD_LINK string // Example: https://git.jojodev.com/Canopy/website/pulls/1
CI_BUILD_NUMBER string // Example: 17
CI_BUILD_STARTED string // Example: 1639112014
CI_BUILD_STATUS string // Example: success
CI_COMMIT_AUTHOR string // Example: jolheiser
CI_COMMIT_AUTHOR_AVATAR string // Example: https://git.jojodev.com/user/avatar/jolheiser/-1
CI_COMMIT_AUTHOR_NAME string // Example: jolheiser
CI_COMMIT_BRANCH string // Example: main
CI_COMMIT_MESSAGE string // Example: Add netlify process
CI_COMMIT_REF string // Example: refs/pull/1/head
CI_COMMIT_REFSPEC string // Example: netlify:main
CI_COMMIT_SHA string // Example: 2abc3b37e83ac31ec8210b8504e64896a49f249c
CI_JOB_FINISHED string // Example: 1639112085
CI_JOB_NUMBER string // Example: 1
CI_JOB_STARTED string // Example: 1639112014
CI_JOB_STATUS string // Example: success
CI_PREV_BUILD_CREATED string // Example: 1639111573
CI_PREV_BUILD_EVENT string // Example: pull_request
CI_PREV_BUILD_FINISHED string // Example: 1639111668
CI_PREV_BUILD_LINK string // Example: https://git.jojodev.com/Canopy/website/pulls/1
CI_PREV_BUILD_NUMBER string // Example: 15
CI_PREV_BUILD_STARTED string // Example: 1639111575
CI_PREV_BUILD_STATUS string // Example: failure
CI_PREV_COMMIT_AUTHOR string // Example: jolheiser
CI_PREV_COMMIT_AUTHOR_AVATAR string // Example: https://git.jojodev.com/user/avatar/jolheiser/-1
CI_PREV_COMMIT_AUTHOR_NAME string // Example: jolheiser
CI_PREV_COMMIT_BRANCH string // Example: main
CI_PREV_COMMIT_MESSAGE string // Example: Add netlify process
CI_PREV_COMMIT_REF string // Example: refs/pull/1/head
CI_PREV_COMMIT_REFSPEC string // Example: netlify:main
CI_PREV_COMMIT_SHA string // Example: 5329dfdfef3f1388b1698aa5fe99a26edd15f7fa
CI_PULL_REQUEST string // Example: 1
CI_REMOTE_URL string // Example: https://git.jojodev.com/Canopy/website.git
CI_REPO string // Example: Canopy/website
CI_REPO_LINK string // Example: https://git.jojodev.com/Canopy/website
CI_REPO_NAME string // Example: Canopy/website
CI_REPO_REMOTE string // Example: https://git.jojodev.com/Canopy/website.git
CI_SYSTEM string // Example: woodpecker
CI_SYSTEM_ARCH string // Example: linux/amd64
CI_SYSTEM_HOST string // Example: ci.jojodev.com
CI_SYSTEM_LINK string // Example: https://ci.jojodev.com
CI_SYSTEM_NAME string // Example: woodpecker
CI_WORKSPACE string // Example: /woodpecker/src/git.jojodev.com/Canopy/website
)
func init() {
CI = os.Getenv("CI")
CI_BUILD_CREATED = os.Getenv("CI_BUILD_CREATED")
CI_BUILD_EVENT = os.Getenv("CI_BUILD_EVENT")
CI_BUILD_FINISHED = os.Getenv("CI_BUILD_FINISHED")
CI_BUILD_LINK = os.Getenv("CI_BUILD_LINK")
CI_BUILD_NUMBER = os.Getenv("CI_BUILD_NUMBER")
CI_BUILD_STARTED = os.Getenv("CI_BUILD_STARTED")
CI_BUILD_STATUS = os.Getenv("CI_BUILD_STATUS")
CI_COMMIT_AUTHOR = os.Getenv("CI_COMMIT_AUTHOR")
CI_COMMIT_AUTHOR_AVATAR = os.Getenv("CI_COMMIT_AUTHOR_AVATAR")
CI_COMMIT_AUTHOR_NAME = os.Getenv("CI_COMMIT_AUTHOR_NAME")
CI_COMMIT_BRANCH = os.Getenv("CI_COMMIT_BRANCH")
CI_COMMIT_MESSAGE = os.Getenv("CI_COMMIT_MESSAGE")
CI_COMMIT_REF = os.Getenv("CI_COMMIT_REF")
CI_COMMIT_REFSPEC = os.Getenv("CI_COMMIT_REFSPEC")
CI_COMMIT_SHA = os.Getenv("CI_COMMIT_SHA")
CI_JOB_FINISHED = os.Getenv("CI_JOB_FINISHED")
CI_JOB_NUMBER = os.Getenv("CI_JOB_NUMBER")
CI_JOB_STARTED = os.Getenv("CI_JOB_STARTED")
CI_JOB_STATUS = os.Getenv("CI_JOB_STATUS")
CI_PREV_BUILD_CREATED = os.Getenv("CI_PREV_BUILD_CREATED")
CI_PREV_BUILD_EVENT = os.Getenv("CI_PREV_BUILD_EVENT")
CI_PREV_BUILD_FINISHED = os.Getenv("CI_PREV_BUILD_FINISHED")
CI_PREV_BUILD_LINK = os.Getenv("CI_PREV_BUILD_LINK")
CI_PREV_BUILD_NUMBER = os.Getenv("CI_PREV_BUILD_NUMBER")
CI_PREV_BUILD_STARTED = os.Getenv("CI_PREV_BUILD_STARTED")
CI_PREV_BUILD_STATUS = os.Getenv("CI_PREV_BUILD_STATUS")
CI_PREV_COMMIT_AUTHOR = os.Getenv("CI_PREV_COMMIT_AUTHOR")
CI_PREV_COMMIT_AUTHOR_AVATAR = os.Getenv("CI_PREV_COMMIT_AUTHOR_AVATAR")
CI_PREV_COMMIT_AUTHOR_NAME = os.Getenv("CI_PREV_COMMIT_AUTHOR_NAME")
CI_PREV_COMMIT_BRANCH = os.Getenv("CI_PREV_COMMIT_BRANCH")
CI_PREV_COMMIT_MESSAGE = os.Getenv("CI_PREV_COMMIT_MESSAGE")
CI_PREV_COMMIT_REF = os.Getenv("CI_PREV_COMMIT_REF")
CI_PREV_COMMIT_REFSPEC = os.Getenv("CI_PREV_COMMIT_REFSPEC")
CI_PREV_COMMIT_SHA = os.Getenv("CI_PREV_COMMIT_SHA")
CI_PULL_REQUEST = os.Getenv("CI_PULL_REQUEST")
CI_REMOTE_URL = os.Getenv("CI_REMOTE_URL")
CI_REPO = os.Getenv("CI_REPO")
CI_REPO_LINK = os.Getenv("CI_REPO_LINK")
CI_REPO_NAME = os.Getenv("CI_REPO_NAME")
CI_REPO_REMOTE = os.Getenv("CI_REPO_REMOTE")
CI_SYSTEM = os.Getenv("CI_SYSTEM")
CI_SYSTEM_ARCH = os.Getenv("CI_SYSTEM_ARCH")
CI_SYSTEM_HOST = os.Getenv("CI_SYSTEM_HOST")
CI_SYSTEM_LINK = os.Getenv("CI_SYSTEM_LINK")
CI_SYSTEM_NAME = os.Getenv("CI_SYSTEM_NAME")
CI_WORKSPACE = os.Getenv("CI_WORKSPACE")
}

190
env.json

@ -0,0 +1,190 @@
[
{
"key": "CI",
"comment": "drone"
},
{
"key": "CI_BUILD_CREATED",
"comment": "1639112012"
},
{
"key": "CI_BUILD_EVENT",
"comment": "pull_request"
},
{
"key": "CI_BUILD_FINISHED",
"comment": "1639112085"
},
{
"key": "CI_BUILD_LINK",
"comment": "https://git.jojodev.com/Canopy/website/pulls/1"
},
{
"key": "CI_BUILD_NUMBER",
"comment": "17"
},
{
"key": "CI_BUILD_STARTED",
"comment": "1639112014"
},
{
"key": "CI_BUILD_STATUS",
"comment": "success"
},
{
"key": "CI_COMMIT_AUTHOR",
"comment": "jolheiser"
},
{
"key": "CI_COMMIT_AUTHOR_AVATAR",
"comment": "https://git.jojodev.com/user/avatar/jolheiser/-1"
},
{
"key": "CI_COMMIT_AUTHOR_NAME",
"comment": "jolheiser"
},
{
"key": "CI_COMMIT_BRANCH",
"comment": "main"
},
{
"key": "CI_COMMIT_MESSAGE",
"comment": "Add netlify process"
},
{
"key": "CI_COMMIT_REF",
"comment": "refs/pull/1/head"
},
{
"key": "CI_COMMIT_REFSPEC",
"comment": "netlify:main"
},
{
"key": "CI_COMMIT_SHA",
"comment": "2abc3b37e83ac31ec8210b8504e64896a49f249c"
},
{
"key": "CI_JOB_FINISHED",
"comment": "1639112085"
},
{
"key": "CI_JOB_NUMBER",
"comment": "1"
},
{
"key": "CI_JOB_STARTED",
"comment": "1639112014"
},
{
"key": "CI_JOB_STATUS",
"comment": "success"
},
{
"key": "CI_PREV_BUILD_CREATED",
"comment": "1639111573"
},
{
"key": "CI_PREV_BUILD_EVENT",
"comment": "pull_request"
},
{
"key": "CI_PREV_BUILD_FINISHED",
"comment": "1639111668"
},
{
"key": "CI_PREV_BUILD_LINK",
"comment": "https://git.jojodev.com/Canopy/website/pulls/1"
},
{
"key": "CI_PREV_BUILD_NUMBER",
"comment": "15"
},
{
"key": "CI_PREV_BUILD_STARTED",
"comment": "1639111575"
},
{
"key": "CI_PREV_BUILD_STATUS",
"comment": "failure"
},
{
"key": "CI_PREV_COMMIT_AUTHOR",
"comment": "jolheiser"
},
{
"key": "CI_PREV_COMMIT_AUTHOR_AVATAR",
"comment": "https://git.jojodev.com/user/avatar/jolheiser/-1"
},
{
"key": "CI_PREV_COMMIT_AUTHOR_NAME",
"comment": "jolheiser"
},
{
"key": "CI_PREV_COMMIT_BRANCH",
"comment": "main"
},
{
"key": "CI_PREV_COMMIT_MESSAGE",
"comment": "Add netlify process"
},
{
"key": "CI_PREV_COMMIT_REF",
"comment": "refs/pull/1/head"
},
{
"key": "CI_PREV_COMMIT_REFSPEC",
"comment": "netlify:main"
},
{
"key": "CI_PREV_COMMIT_SHA",
"comment": "5329dfdfef3f1388b1698aa5fe99a26edd15f7fa"
},
{
"key": "CI_PULL_REQUEST",
"comment": "1"
},
{
"key": "CI_REMOTE_URL",
"comment": "https://git.jojodev.com/Canopy/website.git"
},
{
"key": "CI_REPO",
"comment": "Canopy/website"
},
{
"key": "CI_REPO_LINK",
"comment": "https://git.jojodev.com/Canopy/website"
},
{
"key": "CI_REPO_NAME",
"comment": "Canopy/website"
},
{
"key": "CI_REPO_REMOTE",
"comment": "https://git.jojodev.com/Canopy/website.git"
},
{
"key": "CI_SYSTEM",
"comment": "woodpecker"
},
{
"key": "CI_SYSTEM_ARCH",
"comment": "linux/amd64"
},
{
"key": "CI_SYSTEM_HOST",
"comment": "ci.jojodev.com"
},
{
"key": "CI_SYSTEM_LINK",
"comment": "https://ci.jojodev.com"
},
{
"key": "CI_SYSTEM_NAME",
"comment": "woodpecker"
},
{
"key": "CI_WORKSPACE",
"comment": "/woodpecker/src/git.jojodev.com/Canopy/website"
}
]

11
go.mod

@ -0,0 +1,11 @@
module go.jolheiser.com/woodpecker-env
go 1.17
require golang.org/x/tools v0.1.8
require (
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)

28
go.sum

@ -0,0 +1,28 @@
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 h1:id054HUawV2/6IGm2IV8KZQjqtwAOo2CYlOToYqa0d0=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.8 h1:P1HhGGuLW4aAclzjtmJdf0mJOjVUZUzOTqkAkWL+l6w=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

94
input.json

@ -0,0 +1,94 @@
{
"DRONE_BRANCH": "main",
"DRONE_COMMIT_AUTHOR_AVATAR": "https://git.jojodev.com/user/avatar/jolheiser/-1",
"CI_COMMIT_REFSPEC": "netlify:main",
"DRONE_JOB_FINISHED": "1639112085",
"CI_PREV_COMMIT_AUTHOR_NAME": "jolheiser",
"CI": "drone",
"NODE_VERSION": "14.18.2",
"HOSTNAME": "4a6cf27e84ad",
"DRONE_COMMIT_AUTHOR": "jolheiser",
"CI_BUILD_STARTED": "1639112014",
"CI_BUILD_NUMBER": "17",
"DRONE_REPO_LINK": "https://git.jojodev.com/Canopy/website",
"CI_PREV_COMMIT_AUTHOR_AVATAR": "https://git.jojodev.com/user/avatar/jolheiser/-1",
"DRONE_TARGET_BRANCH": "main",
"YARN_VERSION": "1.22.15",
"DRONE_PREV_BUILD_NUMBER": "15",
"CI_SYSTEM_LINK": "https://ci.jojodev.com",
"CI_BUILD_LINK": "https://git.jojodev.com/Canopy/website/pulls/1",
"CI_WORKSPACE": "/woodpecker/src/git.jojodev.com/Canopy/website",
"HOME": "/root",
"DRONE_COMMIT_BRANCH": "main",
"DRONE_REPO_SCM": "git",
"CI_PREV_COMMIT_AUTHOR": "jolheiser",
"CI_PREV_COMMIT_BRANCH": "main",
"DRONE_BUILD_STATUS": "success",
"CI_PULL_REQUEST": "1",
"CI_JOB_STARTED": "1639112014",
"CI_JOB_NUMBER": "1",
"CI_BUILD_EVENT": "pull_request",
"CI_COMMIT_SHA": "2abc3b37e83ac31ec8210b8504e64896a49f249c",
"DRONE_ARCH": "linux/amd64",
"CI_BUILD_CREATED": "1639112012",
"CI_REPO_NAME": "Canopy/website",
"CI_COMMIT_REF": "refs/pull/1/head",
"DRONE_PREV_COMMIT_SHA": "5329dfdfef3f1388b1698aa5fe99a26edd15f7fa",
"CI_PREV_BUILD_STATUS": "failure",
"DRONE_SOURCE_BRANCH": "netlify",
"DRONE_COMMIT_MESSAGE": "Add netlify process",
"DRONE_REPO_BRANCH": "main",
"CI_BUILD_FINISHED": "1639112085",
"DRONE_REMOTE_URL": "https://git.jojodev.com/Canopy/website.git",
"DRONE_JOB_STATUS": "success",
"DRONE_COMMIT_REFSPEC": "netlify:main",
"CI_REPO": "Canopy/website",
"CI_PREV_COMMIT_MESSAGE": "Add netlify process",
"DRONE_REPO_OWNER": "Canopy",
"CI_COMMIT_AUTHOR_NAME": "jolheiser",
"PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"CI_SYSTEM_HOST": "ci.jojodev.com",
"CI_COMMIT_AUTHOR_AVATAR": "https://git.jojodev.com/user/avatar/jolheiser/-1",
"DRONE": "true",
"CI_PREV_COMMIT_REFSPEC": "netlify:main",
"DRONE_BUILD_STARTED": "1639112014",
"DRONE_BUILD_NUMBER": "17",
"CI_JOB_FINISHED": "1639112085",
"DRONE_BUILD_LINK": "https://ci.jojodev.com/Canopy/website/17",
"DRONE_WORKSPACE": "/woodpecker/src/git.jojodev.com/Canopy/website",
"CI_COMMIT_AUTHOR": "jolheiser",
"CI_REPO_LINK": "https://git.jojodev.com/Canopy/website",
"CI_PREV_BUILD_STARTED": "1639111575",
"CI_PREV_BUILD_NUMBER": "15",
"CI_PREV_BUILD_LINK": "https://git.jojodev.com/Canopy/website/pulls/1",
"CI_COMMIT_BRANCH": "main",
"CI_REPO_REMOTE": "https://git.jojodev.com/Canopy/website.git",
"SHELL": "/bin/sh",
"DRONE_COMMIT": "2abc3b37e83ac31ec8210b8504e64896a49f249c",
"DRONE_PULL_REQUEST": "1",
"CI_SYSTEM_ARCH": "linux/amd64",
"DRONE_JOB_STARTED": "1639112014",
"DRONE_BUILD_EVENT": "pull_request",
"DRONE_JOB_NUMBER": "1",
"DRONE_COMMIT_SHA": "2abc3b37e83ac31ec8210b8504e64896a49f249c",
"DRONE_REPO_NAME": "website",
"DRONE_BUILD_CREATED": "1639112012",
"CI_BUILD_STATUS": "success",
"DRONE_COMMIT_REF": "refs/pull/1/head",
"CI_SYSTEM_NAME": "woodpecker",
"DRONE_MACHINE": "085cfd5637e5",
"DRONE_PREV_BUILD_STATUS": "failure",
"CI_PREV_BUILD_EVENT": "pull_request",
"PWD": "/woodpecker/src/git.jojodev.com/Canopy/website",
"DRONE_BUILD_FINISHED": "1639112085",
"CI_PREV_COMMIT_SHA": "5329dfdfef3f1388b1698aa5fe99a26edd15f7fa",
"DRONE_COMMIT_LINK": "https://git.jojodev.com/Canopy/website/pulls/1",
"CI_PREV_BUILD_CREATED": "1639111573",
"CI_PREV_COMMIT_REF": "refs/pull/1/head",
"CI_COMMIT_MESSAGE": "Add netlify process",
"DRONE_REPO": "Canopy/website",
"CI_SYSTEM": "woodpecker",
"CI_JOB_STATUS": "success",
"CI_REMOTE_URL": "https://git.jojodev.com/Canopy/website.git",
"CI_PREV_BUILD_FINISHED": "1639111668"
}

107
main.go

@ -0,0 +1,107 @@
//go:build generate
package main
import (
"bytes"
_ "embed"
"encoding/json"
"os"
"sort"
"strings"
"text/template"
"golang.org/x/tools/imports"
)
var (
//go:embed input.json
JSON []byte
keys []string
data map[string]string
)
//go:generate go run main.go
func main() {
if err := json.Unmarshal(JSON, &data); err != nil {
panic(err)
}
for key := range data {
if !strings.HasPrefix(key, "CI") {
continue
}
keys = append(keys, key)
}
sort.Strings(keys)
if err := envGo(); err != nil {
panic(err)
}
if err := envJSON(); err != nil {
panic(err)
}
}
func envGo() error {
fi, _ := os.Create("env.go")
defer fi.Close()
var buf bytes.Buffer
if err := tmpl.Execute(&buf, map[string]interface{}{
"keys": keys,
"data": data,
}); err != nil {
return err
}
out, err := imports.Process("env.go", buf.Bytes(), nil)
if err != nil {
return err
}
_, err = fi.Write(out)
return err
}
type CI struct {
Key string `json:"key"`
Comment string `json:"comment"`
}
func envJSON() error {
fi, _ := os.Create("env.json")
defer fi.Close()
var ci []CI
for _, key := range keys {
ci = append(ci, CI{
Key: key,
Comment: data[key],
})
}
out, err := json.MarshalIndent(ci, "", "\t")
if err != nil {
return err
}
_, err = fi.Write(out)
return err
}
var tmpl = template.Must(template.New("").Parse(`package env
import (
"os"
)
// List of CI env variables with an example value comment
var (
{{range $key := .keys}}{{$key}} string // Example: {{index $.data $key}}
{{end}})
func init() {
{{range $key := .keys}}{{$key}} = os.Getenv("{{$key}}")
{{end}}}`))
Loading…
Cancel
Save