Skip to content

Templating, lower_case variables and files

Warren Gifford requested to merge mrnugget/templates-and-files into main

Created by: mrnugget

This builds on top of https://github.com/sourcegraph/src-cli/pull/334 and adds templating to campaign spec including lower-case variable names and access to STDOUT/STDERR.

Updated campaign spec from previous prototype:

name: templated-and-files
description: Use template variables and mount files in campaign specs

on:
  - repositoriesMatchingQuery: repo:automation-testing lang:go fmt.Sprintf("%d", :[v]) patterntype:structural -file:vendor count:5

steps:
  # Run comby over the search results in each repository:
  - run: comby -in-place -config /tmp/go-sprintf.toml -f ${{ join repository.search_result_paths "," }}
    container: comby/comby
    files:
      # Create files inside the container by specifying path and content here:
      /tmp/go-sprintf.toml: |
        [sprintf_to_strconv]
        match='fmt.Sprintf("%d", :[v])'
        rewrite='strconv.Itoa(:[v])'

  - run: echo "comby found the following problems:" >> CHANGELOG.md && cat /tmp/comby-output.txt >> CHANGELOG.md
    container: alpine:3
    files:
      # files also support templating:
      /tmp/comby-output.txt: ${{ previous_step.stdout }}

  - run: echo $MY_MODIFIED_FILES >> modified_files.txt
    container: alpine:3
    env:
      # env vars also support templating:
      MY_MODIFIED_FILES: ${{ join previous_step.modified_files "\n" }}

changesetTemplate:
  title: templated-and-files
  body: My not-first campaign!
  branch: campaign/testing-files
  commit:
    message: Code your code with templates
  published: false

Details

  • ${{ .Repository.SearchResultPaths }} and ${{ repository.search_result_paths }}
  • ${{ .Repository.Name }} and ${{ repository.name }} and the other fields and methods on *graphql.Repository
  • ${{ .PreviousStep.ModifiedFiles }} and ${{ previous_step.modified_files }}
  • ${{ .PreviousStep.AddedFiles }} and ${{ previous_step.added_files }}
  • ${{ .PreviousStep.DeletedFiles }} and ${{ previous_step.deleted_files }}
  • ${{ .PreviousStep.Stdout }} and${{ previous_step.stdout }}
  • ${{ .PreviousStep.Stderr }} and ${{ previous_step.stderr}}
  • ${{ join <list> <sep> }}, example: ${{ join repository.search_result_paths "\n" }}
  • ${{ split <string> <sep> }}, example: ${{ split repository.name "/" }}

TODOs

  • Support mounting local files Erik and I decided against this, since that would make server-side execution harder.
  • Parse env too

Merge request reports

Loading