Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[github] support jobs.<job_id>.outputs #43

Open
jimsheldon opened this issue Mar 24, 2023 · 3 comments
Open

[github] support jobs.<job_id>.outputs #43

jimsheldon opened this issue Mar 24, 2023 · 3 comments
Assignees
Labels
gap Harness product gap github GitHub Actions conversion target p1 priority 1

Comments

@jimsheldon
Copy link
Contributor

A map of outputs for a job. Job outputs are available to all downstream jobs that depend on this job.

See

@jimsheldon jimsheldon added gap Harness product gap github GitHub Actions conversion target labels Mar 24, 2023
@jimsheldon
Copy link
Contributor Author

jimsheldon commented Mar 31, 2023

Example v0 pipeline with outputs referenced in a step and following stage:

  stages:
    - stage:
        name: first
        identifier: first
        description: ""
        type: CI
        spec:
          cloneCodebase: false
          platform:
            os: Linux
            arch: Amd64
          runtime:
            type: Cloud
            spec: {}
          execution:
            steps:
              - step:
                  type: Run
                  name: one
                  identifier: one
                  spec:
                    shell: Sh
                    command: export SOMEVAR=somevalue
                    outputVariables:
                      - name: SOMEVAR
              - step:
                  type: Run
                  name: two
                  identifier: two
                  spec:
                    shell: Sh
                    command: |-
                      # both of these return the output
                      echo <+steps.one.output.outputVariables.SOMEVAR>
                      echo <+execution.steps.one.output.outputVariables.SOMEVAR>
    - stage:
        name: second
        identifier: second
        description: ""
        type: CI
        spec:
          cloneCodebase: false
          platform:
            os: MacOS
            arch: Arm64
          runtime:
            type: Cloud
            spec: {}
          execution:
            steps:
              - step:
                  type: Run
                  name: one
                  identifier: one
                  spec:
                    shell: Sh
                    command: echo <+pipeline.stages.first.spec.execution.steps.one.output.outputVariables.SOMEVAR>

@jimsheldon
Copy link
Contributor Author

Here is an equivalent use of outputs from this documentation https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idoutputs

  stages:
    - stage:
        name: job1
        identifier: job1
        description: ""
        type: CI
        spec:
          cloneCodebase: false
          platform:
            os: Linux
            arch: Amd64
          runtime:
            type: Cloud
            spec: {}
          execution:
            steps:
              - step:
                  type: Run
                  name: step1
                  identifier: step1
                  spec:
                    shell: Sh
                    command: export OUTPUT1=hello
                    outputVariables:
                      - name: OUTPUT1
              - step:
                  type: Run
                  name: step2
                  identifier: step2
                  spec:
                    shell: Sh
                    command: export OUTPUT2=world
                    outputVariables:
                      - name: OUTPUT2
    - stage:
        name: job2
        identifier: job2
        description: ""
        type: CI
        spec:
          cloneCodebase: false
          platform:
            os: Linux
            arch: Amd64
          runtime:
            type: Cloud
            spec: {}
          execution:
            steps:
              - step:
                  type: Run
                  name: echo
                  identifier: echo
                  spec:
                    shell: Sh
                    command: echo $OUTPUT1 $OUTPUT2
                    envVariables:
                      OUTPUT1: <+pipeline.stages.job1.spec.execution.steps.step1.output.outputVariables.OUTPUT1>
                      OUTPUT2: <+pipeline.stages.job1.spec.execution.steps.step2.output.outputVariables.OUTPUT2>

@jimsheldon
Copy link
Contributor Author

jimsheldon commented Apr 7, 2023

I started to work on this in https://github.com/drone/go-convert/compare/issue43

I have a test that currently fails.

The tricky part is that we need to take this:

    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}

And use those values to add the necessary outputs list to each step:

    steps:
    - id: step1
      spec:
        run: echo "test=hello" >> "$GITHUB_OUTPUT"
        outputs:
        - test
      type: script
    - id: step2
      spec:
        run: echo "test=world" >> "$GITHUB_OUTPUT"
        outputs:
        - test

NOTE: The above still won't work as-is, the variables have to be exported for Harness CI's outputs to pick them up. The run commands would have to change to export test=hello and export test=world.

I think we can wait on converting the references to outputs like these

      - env:
          OUTPUT1: ${{needs.job1.outputs.output1}}
          OUTPUT2: ${{needs.job1.outputs.output2}}

These would have to convert to this

      - env:
          OUTPUT1: <+pipeline.stages.job1.spec.execution.steps.step1.output.outputVariables.test>
          OUTPUT2: <+pipeline.stages.job1.spec.execution.steps.step2.output.outputVariables.test>

@jimsheldon jimsheldon added the p1 priority 1 label Apr 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gap Harness product gap github GitHub Actions conversion target p1 priority 1
Projects
None yet
Development

No branches or pull requests

2 participants