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

[bitbucket] parallel steps without the explicit 'steps' property fail to convert #2

Open jimsheldon opened 1 year ago

jimsheldon commented 1 year ago

This is a valid bitbucket-pipelines.yaml file:

image: atlassian/default-image:3

pipelines:
  default:
    - parallel:
      - step:
          name: 'Build and Test'
          script:
            - echo "Your build and test goes here..."
      - step:
          name: 'Lint'
          script:
            - echo "Your linting goes here..."
      - step:
          name: 'Security scan'
          script:
            - echo "Your security scan goes here..."

Conversion fails with this error:

./go-convert bitbucket bitbucket-pipelines.yml
2023/03/06 14:46:36 yaml: unmarshal errors:
  line 6: cannot unmarshal !!seq into yaml.Parallel

The current conversion logic requires a steps property beneath the parallel property.

This yaml converts successfully:

image: atlassian/default-image:3

pipelines:
  default:
    - parallel:
        steps:
        - step:
            name: 'Build and Test'
            script:
              - echo "Your build and test goes here..."
        - step:
            name: 'Lint'
            script:
              - echo "Your linting goes here..."
        - step:
            name: 'Security scan'
            script:
              - echo "Your security scan goes here..."
./go-convert bitbucket bitbucket-pipelines.yml 
stages:
- name: build
  spec:
    steps:
    - name: parallel
      spec:
        steps:
        - name: Build and Test
          spec:
            image: atlassian/default-image:3
            run: echo "Your build and test goes here..."
          type: script
        - name: Lint
          spec:
            image: atlassian/default-image:3
            run: echo "Your linting goes here..."
          type: script
        - name: Security scan
          spec:
            image: atlassian/default-image:3
            run: echo "Your security scan goes here..."
          type: script
      type: parallel
  type: ci
version: 1

We should update the logic to allow steps to be optional.

eoinmcafee00 commented 1 year ago

Hey @jimsheldon

I don't think this is an issue. The indentation is wrong in your example. Steps and parallel should inline. (I think)

`image: atlassian/default-image:3

pipelines:
  default:
    - parallel:
    - step:
        name: 'Build and Test'
        script:
          - echo "Your build and test goes here..."
    - step:
        name: 'Lint'
        script:
          - echo "Your linting goes here..."
    - step:
        name: 'Security scan'
        script:
          - echo "Your security scan goes here..."
`

more examples: https://support.atlassian.com/bitbucket-cloud/docs/parallel-step-options/

jimsheldon commented 1 year ago

@eoinmcafee00 I don't think that yaml is valid, Atlassian provides a yaml validator here https://bitbucket-pipelines.atlassian.io/validator and that yaml doesn't seem valid.

My examples don't have consistent spacing, this might be clearer regarding the level of the steps property:

image: atlassian/default-image:3

pipelines:
  default:
    - parallel:
        steps:
          - step:
              name: 'Build and Test'
              script:
                - echo "Your build and test goes here..."
          - step:
              name: 'Lint'
              script:
                - echo "Your linting goes here..."
          - step:
              name: 'Security scan'
              script:
                - echo "Your security scan goes here..."

You can remove the steps property and it is still a valid Bitbucket pipeline:

image: atlassian/default-image:3

pipelines:
  default:
    - parallel:
        - step:
            name: 'Build and Test'
            script:
              - echo "Your build and test goes here..."
        - step:
            name: 'Lint'
            script:
              - echo "Your linting goes here..."
        - step:
            name: 'Security scan'
            script:
              - echo "Your security scan goes here..."

But that yaml currently fails to convert:

./go-convert bitbucket bitbucket-pipelines.yml
2023/03/09 09:17:56 yaml: unmarshal errors:
  line 6: cannot unmarshal !!seq into yaml.Parallel