Using file mounts with server-side execution
mounts are a powerful way to run custom files withoutdirectly 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
#!/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
mounts field. The following is an example of mountingthe above Python script in a
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
. ├── batch-spec.yml └── hello_appender.py
Note that a
container appropriate for the mounted file has also been chosen for this step.
After writing the batch spec, use the Sourcegraph CLI (
remote to execute the batch spec server-side.
src batch remote -f batch-spec.yml
src provides a URL to the execution of the batch change.