drone / go-convert

Package convert provides tools for converting pipeline configuration files to the Drone format.
Apache License 2.0
10 stars 8 forks source link

[drone] `platform` not handled consistently #18

Closed jimsheldon closed 1 year ago

jimsheldon commented 1 year ago

The platform parameter is not converted consistently.

Examples

Linux/arm64

kind: pipeline
type: docker
name: default

platform:
  os: linux
  arch: arm64

steps:
- name: hello
  image: busybox
  commands:
  - echo hello

Conversion to new Harness YAML:

./go-convert drone example.yaml
options: {}
stages:
- name: default
  spec:
    clone: {}
    platform:
      arch: arm64
      os: linux
    runtime:
      spec: {}
      type: machine
    steps:
    - name: hello
      spec:
        image: busybox
        run: echo hello
      type: script
  type: ci

The above conversion set arm64 as expected.

Conversion to old Harness YAML:

./go-convert drone -downgrade example.yaml
pipeline:
  identifier: default
  name: default
  orgIdentifier: default
  projectIdentifier: default
  properties:
    ci:
      codebase:
        build: <+input>
  stages:
  - stage:
      identifier: default
      name: default
      spec:
        cloneCodebase: true
        execution:
          steps:
          - step:
              identifier: hello
              name: hello
              spec:
                command: echo hello
                image: busybox
              timeout: ""
              type: Run
        platform:
          arch: Amd64
          os: Linux
        runtime:
          spec: {}
          type: Cloud
      type: CI

The above converted yaml has Amd64 which is wrong.

Windows/amd64

kind: pipeline
type: docker
name: default

platform:
  os: windows
  arch: amd64
  version: 1809

steps:
- name: hello
  image: busybox
  commands:
  - echo hello

Conversion to new Harness YAML:

options: {}
stages:
- name: default
  spec:
    clone: {}
    platform:
      arch: amd64
      os: windows
    runtime:
      spec: {}
      type: machine
    steps:
    - name: hello
      spec:
        image: busybox
        run: echo hello
      type: script
  type: ci

The above conversion set windows as expected.

NOTE: Should there be a warning that version is no longer a supported field?

Conversion to old Harness YAML:

pipeline:
  identifier: default
  name: default
  orgIdentifier: default
  projectIdentifier: default
  properties:
    ci:
      codebase:
        build: <+input>
  stages:
  - stage:
      identifier: default
      name: default
      spec:
        cloneCodebase: true
        execution:
          steps:
          - step:
              identifier: hello
              name: hello
              spec:
                command: echo hello
                image: busybox
              timeout: ""
              type: Run
        platform:
          arch: Amd64
          os: Linux
        runtime:
          spec: {}
          type: Cloud
      type: CI

The above converted yaml has Linux which is wrong.

bradrydzewski commented 1 year ago

@jimsheldon I improved the logic here, if you want to test: https://github.com/drone/go-convert/commit/46798623493eed2209fdd014c0d1713a3543d19c#diff-8865ad14716d0f160ef996df47eb1750206588bf431971e39cf3c5042237a769R513

Note that there are some optimizations, like forcing macos to use arm64 when the runtime is cloud since we do not support intel chips in the cloud. Similar to windows only supporting amd64. So in some cases, where it makes sense, we ignore or override the data from the yaml if we know it would otherwise product a yaml that would fail at runtime.

jimsheldon commented 1 year ago

Thanks @bradrydzewski conversion looks good now, thanks.