Automating scripts
Once you have a script that you are happy with, you can automate it using the command line interface.
Running a script using the CLI
The basic usage of the CLI is to run a script with a tool name and a list of files.
The CLI will use the secrets in the .env
file, populate env.files
with <...files>
, run the script
and emit the output to the standard output.
You can use the CLI to run your scripts in a CI/CD pipeline. The CLI will return a non-zero exit code if the script fails, which can be used to fail the pipeline.
Apply Edits
Add the --apply-edits
flag to the CLI to automatically write the file edits.
GitHub Action
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. This section explains how to integrate your GenAIScript in GitHub Actions workflows and pull requests.
Configure secrets and variables
Configure the secrets and variables on your repository or organization so that GenAIScript can connect to your LLM.
The secrets and variables should match the .env
file in your local environment.
Running a script
Use the cli to run the script in a GitHub Action.
- Make sure to pass the secrets and variables to the script to give access to the LLM.
- use the
--out <path>
flag to store the results in a directory so that you can upload them as an artifact.
Add the trace to the action summary
Use the out-trace
flag to output the trace to the summary file, $GITHUB_STEP_SUMMARY
(see example).
Diff
You can use host.exec
to execute git command to retrieve changes in the current branch.
Note that you’ll need to pull origin/main
branch to make this command work in an action.
Storing output in artifacts
Ensure that the directory containing the results is uploaded as an artifact. You can review the trace by opening the res.trace.md
file.
in the zipped artifact.
Azure OpenAI with a Service Principal
The official documentation of the azure login action contains detailled steps on configure Azure resource access from GitHub Actions.
Create a Service Principal following connect from azure secret guide.
Assign any role to the service principal (e.g. Reader) in your Azure subscription. You need this to login.
Assign the role Cognitive Services OpenAI User to the service principal. You need this so that the service principal can access the OpenAI resource.
Configure the AZURE_CREDENTIALS secret in your GitHub repository with the service principal credentials.
Configure the
AZURE_OPENAI_API_ENDPOINT
in your repository GitHub Action variables.Add the following step in your workflow to your GitHub action to login to Azure.
Update each step that invokes the cli to include the
AZURE_OPENAI_API_ENDPOINT
variable.
GitHub Pull request
If your GitHub Action is triggered by a pull request event, you can use the following flags to add comments: description, conversation and reviews.
In order to create comments,
the workflow must have the pull-requests: write
permission
and the GITHUB_TOKEN
secret must be passed to the script.
Update Description
The --pull-request-description
inserts the LLM output into the pull request section (see example).
The command takes an optional string argument to uniquely identify this comment, it is used to update the comment (default is the script id).
If you want to run this script when the pull request is ready for review, use the ready_for_review
, opened
, reopened
events.
Conversation comment
The --pull-request-comment
adds the LLM output as a comment to the pull request conversation (see example).
The optional argument is an identifier for the comment (default is the script id) so that only one comment appears for the id.
Review comments
Use the --pull-request-reviews
to convert annotations as review comments
to the last commit on the pull request (see example).
GenAIScript will automatically try to ignore duplicate review comments and only create new ones.
To collect the changes of the last commit in the pull request branch (see cool blog post), you can try this git command: