This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Install GitHub CLI | |
run: | | |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg | |
sudo apt-key add /usr/share/keyrings/githubcli-archive-keyring.gpg | |
sudo apt-add-repository https://cli.github.com/packages | |
sudo apt update | |
sudo apt install gh -y | |
- name: Authenticate GitHub CLI | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token | |
- name: Install Copilot CLI | |
run: | | |
npm install -g @githubnext/github-copilot-cli | |
- 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: | | |
github-copilot-cli 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: | |
GITHUB_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." |