Skip to content

Latest commit

 

History

History
87 lines (63 loc) · 2.89 KB

server_side_file_mounts.md

File metadata and controls

87 lines (63 loc) · 2.89 KB

Using file mounts with server-side execution

Note This is new!

We're very much looking for input and feedback on this feature. You can either contact us directly, leave feedback in this issue, or tweet at us.

This feature is available in Sourcegraph 4.1 with Sourcegraph CLI 4.0.1 and later.

NOTE: Running a batch spec server-side with file mounts is currently only supported with Sourcegraph CLI.

File mounts are a powerful way to run custom files without directly embedding the files in your batch spec.

Writing a batch spec

In the following example, you have a Python script that appends "Hello World" to all README.md files.

#!/usr/bin/env python3
import os.path


def main():
  if os.path.exists('README.md'):
    with open('README.md', 'a') as f:
      f.write('\nHello World')


if __name__ == "__main__":
  main()

To use the Python script in your batch change, mount the script in a step using the mounts field. The following is an example of mounting the above Python script in a step.

name: hello-world
description: Add Hello World to READMEs

# Find all repositories that contain a README.md file.
on:
  - repositoriesMatchingQuery: file:README.md

# In each repository, run this command. Each repository's resulting diff is captured.
steps:
  - run: python /tmp/hello_appender.py
    container: python:latest
    mount:
      - path: ./hello_appender.py
        mountpoint: /tmp/hello_appender.py

# Describe the changeset (e.g., GitHub pull request) you want for each repository.
changesetTemplate:
  title: Hello World
  body: My first batch change!
  branch: hello-world # Push the commit to this branch.
  commit:
    message: Append Hello World to all README.md files
  published: false # Do not publish any changes to the code hosts yet

In this example, the Python script should live besides the batch spec file, as indicated by the path:

.
├── batch-spec.yml
└── hello_appender.py

Note that a container appropriate for the mounted file has also been chosen for this step.

Running server-side

After writing the batch spec, use the Sourcegraph CLI (src) command remote to execute the batch spec server-side.

src batch remote -f batch-spec.yml

Once successful, src provides a URL to the execution of the batch change.