mirror of
https://github.com/suzuki-shunsuke/drone-jsonnet-generator.git
synced 2026-02-11 00:53:26 +02:00
ci: add build and ci tools
* Drone * golangci-lint * goreleaser * commitlint * scripts * README, CONTRIBUTING
This commit is contained in:
77
.drone.yml
Normal file
77
.drone.yml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: commitlint
|
||||||
|
steps:
|
||||||
|
- name: npm install
|
||||||
|
image: &node_image node:10.16.0-alpine
|
||||||
|
commands:
|
||||||
|
- npm i
|
||||||
|
- name: tag/commitlint
|
||||||
|
image: *node_image
|
||||||
|
commands:
|
||||||
|
- npx commitlint --from HEAD~1 --to HEAD
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- push
|
||||||
|
- name: pr/commitlint
|
||||||
|
image: *node_image
|
||||||
|
commands:
|
||||||
|
- npx commitlint --from master --to HEAD || exit 1
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: build
|
||||||
|
workspace:
|
||||||
|
base: /go
|
||||||
|
path: src/github.com/suzuki-shunsuke/drone-jsonnet-generator
|
||||||
|
steps:
|
||||||
|
- name: golangci-lint
|
||||||
|
image: golangci/golangci-lint:v1.17.1
|
||||||
|
commands:
|
||||||
|
- golangci-lint run
|
||||||
|
- name: codecov
|
||||||
|
image: &image_go golang:1.12.5
|
||||||
|
commands:
|
||||||
|
# bash and cgo seem to be required
|
||||||
|
- bash scripts/codecov-test.sh
|
||||||
|
- curl -s https://codecov.io/bash > /tmp/codecov.sh
|
||||||
|
- test "$LOCAL" == "true" || bash /tmp/codecov.sh
|
||||||
|
environment:
|
||||||
|
CODECOV_TOKEN:
|
||||||
|
from_secret: codecov_token
|
||||||
|
- name: fetch tags
|
||||||
|
image: plugins/git
|
||||||
|
commands:
|
||||||
|
- git fetch --tags
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- name: release
|
||||||
|
image: &goreleaser goreleaser/goreleaser:v0.109.0
|
||||||
|
commands:
|
||||||
|
- goreleaser release
|
||||||
|
environment:
|
||||||
|
GO111MODULE: on
|
||||||
|
GITHUB_TOKEN:
|
||||||
|
from_secret: github_token
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- tag
|
||||||
|
- name: git
|
||||||
|
image: plugins/git
|
||||||
|
commands:
|
||||||
|
# bash not found
|
||||||
|
- sh scripts/tag-dummy.sh
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
|
- name: release/pr
|
||||||
|
image: *goreleaser
|
||||||
|
commands:
|
||||||
|
- goreleaser release --skip-publish
|
||||||
|
when:
|
||||||
|
event:
|
||||||
|
- pull_request
|
||||||
9
.gitignore
vendored
Normal file
9
.gitignore
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
vendor
|
||||||
|
dist
|
||||||
|
node_modules
|
||||||
|
profile.out
|
||||||
|
.coverage
|
||||||
|
coverage.txt
|
||||||
|
|
||||||
|
# https://github.com/suzuki-shunsuke/git-rm-branch
|
||||||
|
.git-rm-branch.yml
|
||||||
20
.golangci.yml
Normal file
20
.golangci.yml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
linters:
|
||||||
|
enable:
|
||||||
|
- deadcode
|
||||||
|
- goconst
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- golint
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- interfacer
|
||||||
|
- maligned
|
||||||
|
- misspell
|
||||||
|
- nakedret
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- unconvert
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
disable-all: true
|
||||||
12
.goreleaser.yml
Normal file
12
.goreleaser.yml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
---
|
||||||
|
builds:
|
||||||
|
- binary: drone-jsonnet-generator
|
||||||
|
main: cmd/drone-jsonnet-generator/main.go
|
||||||
|
env:
|
||||||
|
- CGO_ENABLED=0
|
||||||
|
goos:
|
||||||
|
- windows
|
||||||
|
- darwin
|
||||||
|
- linux
|
||||||
|
goarch:
|
||||||
|
- amd64
|
||||||
74
CONTRIBUTING.md
Normal file
74
CONTRIBUTING.md
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
## Check before send a pull request
|
||||||
|
|
||||||
|
* Commit message format conforms the [AngularJS Commit Message Format](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits)
|
||||||
|
* [Commit message type is appropriate](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#type)
|
||||||
|
* [If the pull request includes breaking changes, please describe them](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#footer)
|
||||||
|
* Document and code comment is updated
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
* [npm](https://www.npmjs.com/)
|
||||||
|
* [Golang](https://golang.org/)
|
||||||
|
* [golangci-lint](https://github.com/golangci/golangci-lint)
|
||||||
|
* [goreleaser](https://goreleaser.com/)
|
||||||
|
|
||||||
|
We use node libraries and npm scripts for development.
|
||||||
|
Please see [package.json](https://github.com/suzuki-shunsuke/drone-jsonnet-generator/blob/master/package.json) .
|
||||||
|
|
||||||
|
## Set up
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm run setup
|
||||||
|
```
|
||||||
|
|
||||||
|
## Lint
|
||||||
|
|
||||||
|
```
|
||||||
|
# Lint with go vet.
|
||||||
|
$ npm run vet
|
||||||
|
# Lint with golangci-lint. It takes some time.
|
||||||
|
$ npm run lint
|
||||||
|
```
|
||||||
|
|
||||||
|
## Format codes with gofmt
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm run fmt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Test
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm t
|
||||||
|
# Test with Drone
|
||||||
|
$ npm run ci-local
|
||||||
|
```
|
||||||
|
|
||||||
|
## Commit Message Format
|
||||||
|
|
||||||
|
The commit message format of this project conforms to the [AngularJS Commit Message Format](https://github.com/angular/angular.js/blob/master/DEVELOPERS.md#commits).
|
||||||
|
We validate the commit message with git's `commit-msg` hook using [commitlint](http://marionebl.github.io/commitlint/#/) and [husky](https://www.npmjs.com/package/husky), so you have to install them before commit.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm i
|
||||||
|
```
|
||||||
|
|
||||||
|
## Release
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm run tag <tag>
|
||||||
|
$ git push
|
||||||
|
$ git push --tags
|
||||||
|
```
|
||||||
|
|
||||||
|
Tag must start with "v".
|
||||||
|
`npm run tag` command updates [internal/domain/version.go](https://github.com/suzuki-shunsuke/drone-jsonnet-generator/blob/master/internal/domain/version.go) and commit and creates a tag.
|
||||||
|
When we push a tag to GitHub, ci is run and drone-jsonnet-generator is built and uploaded to [GitHub Relases](https://github.com/suzuki-shunsuke/drone-jsonnet-generator/releases) .
|
||||||
|
|
||||||
|
## CI
|
||||||
|
|
||||||
|
We use [Drone](https://cloud.drone.io/suzuki-shunsuke/drone-jsonnet-generator).
|
||||||
|
|
||||||
|
Please see [.drone.yml](https://github.com/suzuki-shunsuke/drone-jsonnet-generator/blob/master/.drone.yml) .
|
||||||
219
README.md
219
README.md
@@ -1 +1,218 @@
|
|||||||
# drone-jsonnet-generator
|
# drone-jsonnet-generator
|
||||||
|
|
||||||
|
CLI tool to convert [Drone](https://drone.io/) v0.8x format .drone.yml to v1 format .drone.jsonnet
|
||||||
|
|
||||||
|
When you migrate matrix build to multi machine pipeline,
|
||||||
|
[jsonnet](https://jsonnet.org) is recommended officially.
|
||||||
|
|
||||||
|
https://docs.drone.io/user-guide/pipeline/migrating/
|
||||||
|
|
||||||
|
> The above syntax can be quite verbose if you are testing a large number of variations.
|
||||||
|
> To simplify your configuration we recommend using jsonnet.
|
||||||
|
|
||||||
|
But it is bothersome to convert .drone.yml to .drone.jsonnet manually .
|
||||||
|
|
||||||
|
`drone-jsonnet-generator` automates this bothersome tasks.
|
||||||
|
|
||||||
|
## Note
|
||||||
|
|
||||||
|
* This tool assumes that matrix build is used at source .drone.yml . If you don't use matrix build, you should use `drone convert` instead of this tool
|
||||||
|
* This tool can't convert perfectly. You should fix generated .drone.jsonnet . This tool automate 95% tasks. You should fix the following points.
|
||||||
|
* Remove pipeline name's double quotes (ex. `"'GO_VERSION:' + GO_VERSION"` -> `'GO_VERSION:' + GO_VERSION`)
|
||||||
|
* Change matrix build variable `${VARIABLE_NAME}` to jsonnet variable (ex. `"golang:${GO_VERSION}"` -> `"golang:" + GO_VERSION`)
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
Run the command `drone-jsonnet-generator gen` and fix generated .drone.jsonnet manually.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
### Example 1. matrix build without include
|
||||||
|
|
||||||
|
source .drone.yml
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
pipeline:
|
||||||
|
build:
|
||||||
|
image: golang:${GO_VERSION}
|
||||||
|
commands:
|
||||||
|
- echo hello
|
||||||
|
services:
|
||||||
|
database:
|
||||||
|
image: ${DATABASE}
|
||||||
|
matrix:
|
||||||
|
GO_VERSION:
|
||||||
|
- 1.4
|
||||||
|
- 1.3
|
||||||
|
DATABASE:
|
||||||
|
- mysql:5.5
|
||||||
|
- mysql:6.5
|
||||||
|
```
|
||||||
|
|
||||||
|
generated .drone.jsonnet
|
||||||
|
|
||||||
|
```jsonnet
|
||||||
|
local pipeline(GO_VERSION, DATABASE) = {
|
||||||
|
"kind": "pipeline",
|
||||||
|
"name": "'GO_VERSION:' + GO_VERSION + ' DATABASE:' + DATABASE",
|
||||||
|
"platform": {
|
||||||
|
"arch": "amd64",
|
||||||
|
"os": "linux"
|
||||||
|
},
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"image": "${DATABASE}",
|
||||||
|
"name": "database",
|
||||||
|
"pull": "default"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"commands": [
|
||||||
|
"echo hello"
|
||||||
|
],
|
||||||
|
"image": "golang:${GO_VERSION}",
|
||||||
|
"name": "build",
|
||||||
|
"pull": "default"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
local array_DATABASE = [
|
||||||
|
"mysql:5.5",
|
||||||
|
"mysql:6.5"
|
||||||
|
];
|
||||||
|
local array_GO_VERSION = [
|
||||||
|
"1.4",
|
||||||
|
"1.3"
|
||||||
|
];
|
||||||
|
|
||||||
|
[
|
||||||
|
pipeline(GO_VERSION, DATABASE) for DATABASE in array_DATABASE for GO_VERSION in array_GO_VERSION
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
### Example 2. matrix build with include
|
||||||
|
|
||||||
|
source .drone.yml
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
pipeline:
|
||||||
|
build:
|
||||||
|
image: golang:${GO_VERSION}
|
||||||
|
commands:
|
||||||
|
- echo hello
|
||||||
|
services:
|
||||||
|
database:
|
||||||
|
image: ${DATABASE}
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- GO_VERSION: 1.4
|
||||||
|
DATABASE: mysql:5.5
|
||||||
|
- GO_VERSION: 1.4
|
||||||
|
DATABASE: mysql:6.5
|
||||||
|
- GO_VERSION: 1.3
|
||||||
|
DATABASE: mysql:5.5
|
||||||
|
```
|
||||||
|
|
||||||
|
generated .drone.jsonnet
|
||||||
|
|
||||||
|
```jsonnet
|
||||||
|
local pipeline(GO_VERSION, DATABASE) = {
|
||||||
|
"kind": "pipeline",
|
||||||
|
"name": "'GO_VERSION:' + GO_VERSION + ' DATABASE:' + DATABASE",
|
||||||
|
"platform": {
|
||||||
|
"arch": "amd64",
|
||||||
|
"os": "linux"
|
||||||
|
},
|
||||||
|
"services": [
|
||||||
|
{
|
||||||
|
"image": "${DATABASE}",
|
||||||
|
"name": "database",
|
||||||
|
"pull": "default"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"steps": [
|
||||||
|
{
|
||||||
|
"commands": [
|
||||||
|
"echo hello"
|
||||||
|
],
|
||||||
|
"image": "golang:${GO_VERSION}",
|
||||||
|
"name": "build",
|
||||||
|
"pull": "default"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
local args = [
|
||||||
|
{
|
||||||
|
"DATABASE": "mysql:5.5",
|
||||||
|
"GO_VERSION": "1.4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DATABASE": "mysql:6.5",
|
||||||
|
"GO_VERSION": "1.4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"DATABASE": "mysql:5.5",
|
||||||
|
"GO_VERSION": "1.3"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
[
|
||||||
|
pipeline(arg.GO_VERSION, arg.DATABASE) for arg in args
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
`drone-jsonnet-generator` is written with Golang and binary is distributed at [release page](https://github.com/suzuki-shunsuke/drone-jsonnet-generator/releases), so installation is easy and no dependency is needed.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ drone-jsonnet-generator --help
|
||||||
|
NAME:
|
||||||
|
drone-jsonnet-generator - convert Drone v0.8x format .drone.yml to v1 format .drone.jsonnet
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
drone-jsonnet-generator [global options] command [command options] [arguments...]
|
||||||
|
|
||||||
|
VERSION:
|
||||||
|
0.1.0
|
||||||
|
|
||||||
|
AUTHOR:
|
||||||
|
suzuki-shunsuke https://github.com/suzuki-shunsuke
|
||||||
|
|
||||||
|
COMMANDS:
|
||||||
|
gen convert Drone v0.8x format .drone.yml to v1 format .drone.jsonnet
|
||||||
|
help, h Shows a list of commands or help for one command
|
||||||
|
|
||||||
|
GLOBAL OPTIONS:
|
||||||
|
--help, -h show help
|
||||||
|
--version, -v print the version
|
||||||
|
```
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ drone-jsonnet-generator gen --help
|
||||||
|
NAME:
|
||||||
|
drone-jsonnet-generator gen - convert Drone v0.8x format .drone.yml to v1 format .drone.jsonnet
|
||||||
|
|
||||||
|
USAGE:
|
||||||
|
drone-jsonnet-generator gen [command options] [arguments...]
|
||||||
|
|
||||||
|
OPTIONS:
|
||||||
|
--source value, -s value source .drone.yml path (default: ".drone.yml")
|
||||||
|
--target value, -t value target .drone.jsonnet path (default: ".drone.jsonnet")
|
||||||
|
--stdout output generated jsonnet to stdout
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contribution
|
||||||
|
|
||||||
|
See [CONTRIBUTING.md](CONTRIBUTING.md) .
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[MIT](LICENSE)
|
||||||
|
|||||||
1
commitlint.config.js
Normal file
1
commitlint.config.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
module.exports = {extends: ['@commitlint/config-angular']}
|
||||||
1265
package-lock.json
generated
Normal file
1265
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
17
package.json
Normal file
17
package.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"scripts": {
|
||||||
|
"commitmsg": "commitlint -e $GIT_PARAMS",
|
||||||
|
"precommit": "npm run vet && npm t && npm run lint",
|
||||||
|
"test": "go test ./... -covermode=atomic",
|
||||||
|
"fmt": "bash scripts/fmt.sh",
|
||||||
|
"vet": "go vet ./...",
|
||||||
|
"lint": "golangci-lint run",
|
||||||
|
"c": "bash scripts/coverage.sh",
|
||||||
|
"tag": "bash scripts/tag.sh"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@commitlint/cli": "^7.5.2",
|
||||||
|
"@commitlint/config-angular": "^6.1.3",
|
||||||
|
"husky": "^0.14.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
12
scripts/codecov-test.sh
Normal file
12
scripts/codecov-test.sh
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# https://github.com/codecov/example-go#caveat-multiple-files
|
||||||
|
|
||||||
|
echo "" > coverage.txt
|
||||||
|
|
||||||
|
for d in $(go list ./... | grep -v vendor | grep -v dummy); do
|
||||||
|
go test -race -coverprofile=profile.out -covermode=atomic $d || exit 1
|
||||||
|
if [ -f profile.out ]; then
|
||||||
|
cat profile.out >> coverage.txt
|
||||||
|
rm profile.out
|
||||||
|
fi
|
||||||
|
done
|
||||||
3
scripts/coverage.sh
Normal file
3
scripts/coverage.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
mkdir -p .coverage/$1
|
||||||
|
go test ./$1 -coverprofile=.coverage/$1/coverage.txt -covermode=atomic
|
||||||
|
go tool cover -html=.coverage/$1/coverage.txt
|
||||||
1
scripts/drone-local-env
Normal file
1
scripts/drone-local-env
Normal file
@@ -0,0 +1 @@
|
|||||||
|
LOCAL=true
|
||||||
5
scripts/fmt.sh
Normal file
5
scripts/fmt.sh
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
find . -type d -name node_modules -prune -o \
|
||||||
|
-type d -name .git -prune -o \
|
||||||
|
-type d -name vendor -prune -o \
|
||||||
|
-type f -name "*.go" -print \
|
||||||
|
| xargs gofmt -l -s -w
|
||||||
3
scripts/tag-dummy.sh
Normal file
3
scripts/tag-dummy.sh
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
git fetch
|
||||||
|
git tag
|
||||||
|
git tag `git tag | tail -n 1`-alpha || exit 1
|
||||||
39
scripts/tag.sh
Normal file
39
scripts/tag.sh
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
# Usage
|
||||||
|
# bash scripts/tag.sh v0.3.2
|
||||||
|
|
||||||
|
if [ $# -gt 1 ]; then
|
||||||
|
echo "too many arguments" > /dev/stderr
|
||||||
|
echo 'Usage tag.sh $TAG' > /dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $# -lt 1 ]; then
|
||||||
|
echo "TAG argument is required" > /dev/stderr
|
||||||
|
echo 'Usage tag.sh $TAG' > /dev/stderr
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
TAG=$1
|
||||||
|
echo "TAG: $TAG"
|
||||||
|
VERSION=${TAG#v}
|
||||||
|
|
||||||
|
if [ "$TAG" = "$VERSION" ]; then
|
||||||
|
echo "TAG must start with 'v'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "cd `dirname $0`/.."
|
||||||
|
cd `dirname $0`/..
|
||||||
|
|
||||||
|
echo "create internal/domain/version.go"
|
||||||
|
cat << EOS > internal/domain/version.go
|
||||||
|
package domain
|
||||||
|
|
||||||
|
// Version is the cube's version.
|
||||||
|
const Version = "$VERSION"
|
||||||
|
EOS
|
||||||
|
|
||||||
|
git add internal/domain/version.go
|
||||||
|
git commit -m "build: update version to $TAG"
|
||||||
|
echo "git tag $TAG"
|
||||||
|
git tag $TAG
|
||||||
Reference in New Issue
Block a user