drone / go-convert

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

[downgrade] stage-level environment variables do not convert correctly #139

Closed jimsheldon closed 9 months ago

jimsheldon commented 9 months ago

Here is an example v1 yaml

stages:
- name: test
  spec:
    envs:
      STAGE_VARIABLE: value
    platform:
      arch: amd64
      os: linux
    runtime:
      spec: {}
      type: cloud
    steps:
    - name: hello
      spec:
        image: busybox
        run: |
          echo hello
        shell: bash
      type: script
  type: ci
version: 1

which converts to this v0 yaml

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

envVariables is not valid at this level, STAGE_VARIABLE is not available to the hello step shell commands.

It should convert to this v0 yaml

pipeline:
  identifier: default
  name: default
  orgIdentifier: default
  projectIdentifier: default
  properties:
    ci:
      codebase:
        build: <+input>
  stages:
  - stage:
      identifier: test
      name: test
      spec:
        cloneCodebase: true
        execution:
          steps:
          - step:
              identifier: hello
              name: hello
              spec:
                command: |
                  echo hello
                image: busybox
                shell: Bash
              timeout: ""
              type: Run
        platform:
          arch: Amd64
          os: Linux
        runtime:
          spec: {}
          type: Cloud
      type: CI
      variables:
      - name: STAGE_VARIABLE
        type: String
        description: ""
        required: false
        value: value

Valid values for type are String, Secret and Number, I think we only need to worry about String and Number. We might be able to get away with treating everything as String with double quotes and not worry about Number.

jimsheldon commented 9 months ago

Fix in #140