Skip to content

test action

test action #7

name: Update SDK Example
on:
push:
branches:
- copilot
paths:
- 'context/changelog.json'
- '.github/workflows/update-sdk-example.yml'
workflow_dispatch: # Allows manual triggering
jobs:
update-example:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Copilot CLI
run: |
gh extension install github/gh-copilot
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create Copilot prompt
run: |
cat << EOF > prompt.txt
Context: openapi.yaml file represents MongoDB Atlas OpenAPI. sdk-example.go is the file I want to edit. changelog.json contains new changes to the attached OpenAPI.yaml
SDK uses OpenAPI tag and operationId fields to build SDK methods.
Action: Act as software agent that for provided SDK example extending it by providing sdk method calls from changelog.json path
EOF
- name: Use GitHub Copilot to update SDK example
run: |
gh copilot suggest --prompt-file prompt.txt --file golang/sdk-example.go > golang/sdk-example.go.new
mv golang/sdk-example.go.new golang/sdk-example.go
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Format code
run: |
go install golang.org/x/tools/cmd/goimports@latest
goimports -w golang/sdk-example.go
- name: Create Pull Request
run: |
git config --global user.name 'GitHub Action'
git config --global user.email '[email protected]'
BRANCH_NAME="automated-sdk-example-update-$(date +%s)"
git checkout -b $BRANCH_NAME
if ! git diff --quiet; then
git add golang/sdk-example.go
git commit -m "chore: Update SDK example based on changelog changes
Automated update by GitHub Copilot based on changelog.json changes"
git push origin $BRANCH_NAME
gh pr create \
--title "chore: Update SDK example based on changelog changes" \
--body "This PR was automatically created using GitHub Copilot to update the SDK example based on changelog.json changes." \
--base main \
--head $BRANCH_NAME
else
echo "No changes to commit"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Handle Failure
if: failure()
run: |
echo "::error::Failed to update SDK example. Please check the logs for details."