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

[github] support maps in matrix arrays #54

Open jimsheldon opened 1 year ago

jimsheldon commented 1 year ago

Example pipeline

jobs:
  job1:
    strategy:
      matrix:
        app:
          [
            { name: theapp1, port: 8080, runner: my-runner },
            { name: theapp2, port: 8081, runner: ubuntu-latest },
            {
              name: theapp3,
              port: 8082,
              runner: my-other-runner,
            }
          ]
    name: build-${{ matrix.app.name }}
    runs-on: ${{ matrix.app.runner }}
    steps:
      - name: Build app
        run: ./build.sh ${{ matrix.app.name }}

Conversion fails

$ go-convert github example.yml
2023/03/28 09:54:00 yaml: unmarshal errors:
  line 7: cannot unmarshal !!map into string
  line 8: cannot unmarshal !!map into string
  line 9: cannot unmarshal !!map into string
jimsheldon commented 1 year ago

Similar approach found here https://github.com/nedbat/coveragepy/blob/master/.github/workflows/kit.yml

Example

jobs:
  wheels:
    name: "${{ matrix.py }} ${{ matrix.os }} ${{ matrix.arch }} wheels"
    runs-on: ${{ matrix.os }}-latest
    strategy:
      matrix:
        include:
          - {"os": "ubuntu", "py": "cp310", "arch": "aarch64"}
          - {"os": "ubuntu", "py": "cp311", "arch": "aarch64"}
          - {"os": "macos", "py": "cp38", "arch": "arm64"}
          - {"os": "macos", "py": "cp311", "arch": "x86_64"}
          - {"os": "windows", "py": "cp37", "arch": "x86"}
          - {"os": "windows", "py": "cp310", "arch": "AMD64"}
          - {"os": "windows", "py": "cp311", "arch": "AMD64"}
      fail-fast: false

Converts successfully

$ go-convert github example.yml
stages:
- name: wheels
  spec:
    platform:
      arch: amd64
      os: linux
    runtime:
      spec: {}
      type: cloud
  strategy:
    spec:
      include:
      - arch: aarch64
        os: ubuntu
        py: cp310
      - arch: aarch64
        os: ubuntu
        py: cp311
      - arch: arm64
        os: macos
        py: cp38
      - arch: x86_64
        os: macos
        py: cp311
      - arch: x86
        os: windows
        py: cp37
      - arch: AMD64
        os: windows
        py: cp310
      - arch: AMD64
        os: windows
        py: cp311
    type: matrix
  type: ci
version: 1

Note that name strips out the matrix variables, and runs-on is missing.

jimsheldon commented 1 year ago

Putting this in the backlog for now.