2019-06-12 10:53:16 +09:00
2019-06-12 10:33:48 +09:00
2019-06-12 10:30:48 +09:00
2019-06-12 09:53:55 +09:00
2019-06-12 09:57:25 +09:00
2019-06-12 09:57:25 +09:00
2019-06-12 09:57:25 +09:00
2019-06-12 09:57:25 +09:00
2019-06-12 10:46:19 +09:00
2019-06-12 09:53:55 +09:00
2019-06-11 09:36:14 +09:00
2019-06-12 09:57:25 +09:00
2019-06-12 09:57:25 +09:00
2019-06-12 10:08:10 +09:00

drone-jsonnet-generator

License

CLI tool to convert Drone v0.8x format .drone.yml to v1 format .drone.jsonnet

When you migrate matrix build to multi machine pipeline, jsonnet 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

---
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

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

---
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

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, so installation is easy and no dependency is needed.

Usage

$ 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
$ 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 .

License

MIT

Description
drone-jsonnet-generator. CLI tool to convert Drone v0.8x format .drone.yml to v1 format .drone.jsonnet
Readme MIT 93 KiB
Languages
Go 84.8%
Shell 14.6%
JavaScript 0.6%