sourcegraph / sourcegraph-public-snapshot

Code AI platform with Code Search & Cody
https://sourcegraph.com
Other
10.11k stars 1.29k forks source link

SSBC Spec validation breaks when using outputs #57396

Open gabtorre opened 1 year ago

gabtorre commented 1 year ago
  1. Create a server side batch change using outputs in a range action.
    ...
    outputs:
      foo:
        value: ${{ step.modified_files }}
    ...
    changesetTemplate:
    body: |
    ${{ range $index, $bar := outputs.foo }}
      - ${{ $bar }}
    ${{ end }} 

    Expected behavior:

    The spec validation and execution are expected to run without issues.

Actual behavior:

Error: Validating batch spec template: template: validateBatchSpecTemplate:20: undefined variable "$bar" Screenshot 2023-10-05 at 1 29 33 PM

It looks like this validation is removing the line with outputs, resulting in the spec below: https://sourcegraph.com/github.com/sourcegraph/sourcegraph@434944e17d371b5246feed4b3c99b9703a9fd15e/-/blob/lib/batches/template/templating.go?L58-68

changesetTemplate:
  body: |

      - ${{ $bar }}
    ${{ end }} 

If you would like immediate help on this, please email support@sourcegraph.com (you can still create the issue, but there are no SLAs on issues like there are for support requests).

BolajiOlajide commented 1 year ago

Temporary workaround:

name: output-test
description: change golang

on:
  - repositoriesMatchingQuery: context:global repo:sourcegraph/sourcegraph file:Dockerfile select:file golang
steps:
  - run: |     
      while read -r dockerfile; do 
        sed -E -i 's/golang/golang:18.18.0/' $dockerfile
      done < <(find . -not -path '*/node_modules/*' -name '*Dockerfile*')
    container: ubuntu:latest

changesetTemplate:
  title: changing golang
  body: |
    ${{ range $index, $hook := steps.modified_files }}
       - ${{ $hook }}

    ${{ end }} 
  commit:
    message: my message
  branch: ${{ batch_change.name }}

I'm working on a proper solution for this.

BolajiOlajide commented 1 year ago

It turns out we strip out outputs from the changesetTemplate today.

https://sourcegraph.com/-/editor?remote_url=git%40github.com%3Asourcegraph%2Fsourcegraph.git&branch=main&file=lib%2Fbatches%2Ftemplate%2Ftemplating.go&editor=VSCode&version=2.2.16&start_row=57&start_col=1&end_row=60&end_col=50

This isn't ideal and we should work on fixing.