Skip to content

For internal use only: add `src batches exec` command

Warren Gifford requested to merge mrn/src-exec into main

Created by: mrnugget

This adds the for-internal-use-only src batch exec command that will be used by server-side batch changes to execute a batch spec in specific workspaces on different machines, concurrently.

Note: the vast majority of the added code you see here is copy&pasted from batch_common.go. I really don't want to add more conditionals to the huge function in there though, so I created a new one. Yes, there's duplication, but it's so much easier to understand and to maintain. And we'll likely make a lot of changes to this new function here anyway, so effort to generalize and DRY this code will probably be wasted.

Example

Given the following input file, input.json

{
  "rawSpec": "\nname: text-only-output-4\ndescription: Just a test campaign spec to test text only output\n\non:\n  - repository: github.com/sourcegraph/automation-testing\n  # - repository: github.com/sourcegraph-testing/mkcert\n  # - repository: github.com/sourcegraph-testing/tidb\n  # - repository: github.com/sourcegraph-testing/titan\n  # - repository: github.com/sourcegraph-testing/etcd\n  # - repository: github.com/sourcegraph-testing/tiny-go-test-repository\n\nsteps:\n  - run: |\n      echo \"this is step 1\" >> README.txt\n      echo \"this is step 1\"\n      echo \"this is step 1\" 1>&2\n    container: alpine:3\n  - run: |\n      echo \"this is step 2\" >> README.md\n      echo \"this is step 2\"\n      echo \"this is step 2\" 1>&2\n    container: alpine:3\n  - run: |\n      echo \"this is step 3\" >> README.md\n      echo \"this is step 3\"\n      echo \"this is step 3\" 1>&2\n    container: alpine:3\n    outputs:\n      myOutput:\n        value: \"my-output.txt\"\n  - run: |\n      echo \"this is step 4\" >> README.md\n      cat README.md\n      echo \"previous_step.modified_files=${{ previous_step.modified_files }}\" >> README.md\n      ls -lrt\n    container: alpine:3\n  - run: echo \"this is step 5\" >> ${{ outputs.myOutput }}\n    container: alpine:3\n\nchangesetTemplate:\n  title: Testing step caching\n  body:  Testing step caching\n  branch: thorsten/text-only-output-2\n  published: true\n  commit:\n    message: Caching testing\n",
  "workspaces": [
    {
      "repository": {
        "id": "UmVwb3NpdG9yeTo3",
        "name": "github.com/sourcegraph/automation-testing"
      },
      "branch": {
        "abbrevName": "master",
        "target": {
          "oid": "d559e66a56e6615759f60f543475fd69e347f592"
        }
      },
      "path": "",
      "onlyFetchWorkspace": false,
      "steps": [
        {
          "run": "echo \"this is step 1\" >> README.txt\necho \"this is step 1\"\necho \"this is step 1\" 1>&2",
          "container": "alpine:3",
          "env": {}
        }
      ],
      "searchResultPaths": []
    }
  ]
}

we can use src batch exec to execute the workspaces.steps (not the steps in the included raw batch spec!!) in the given workspaces:

src batch exec -f input.json

Merge request reports

Loading