Skip to content

Commit

Permalink
Fix updated cassettes step
Browse files Browse the repository at this point in the history
  • Loading branch information
waynehamadi committed Jun 5, 2023
1 parent 60ac0c4 commit c7b95da
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 58 deletions.
71 changes: 19 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ jobs:
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true

- id: checkout_cassettes
name: Check out cassettes
- name: Setup git username and email
run: |
git config --global user.name "Auto-GPT-Bot"
git config --global user.email "github-bot@agpt.co"
- name: Check out cassettes
if: ${{ startsWith(github.event_name, 'pull_request') }}
run: |
cassette_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"
Expand All @@ -111,21 +115,12 @@ jobs:
git checkout $cassette_branch
if git merge --no-commit --no-ff ${{ github.event.pull_request.base.ref }}; then
echo "Using cassettes from mirror branch, synced to upstream branch '${{ github.event.pull_request.base.ref }}'"
else
echo "Could not merge upstream changes to cassettes. Using cassettes from ${{ github.event.pull_request.base.ref }}."
git merge --abort
git checkout ${{ github.event.pull_request.base.ref }}
# Delete branch to prevent conflict when re-creating it
git branch -D $cassette_branch
fi
echo "cassette_branch=$(git branch --show-current)" >> $GITHUB_OUTPUT
git merge --no-commit --strategy-option ours origin/${{ github.event.pull_request.base.ref }}
echo "Using cassettes from mirror branch, synced to upstream branch '${{ github.event.pull_request.base.ref }}' if no conflicts."
else
git checkout -b $cassette_branch
echo "Branch '$cassette_branch' does not exist in cassette submodule."\
"Using cassettes from ${{ github.event.pull_request.base.ref }}."
echo "cassette_branch=${{ github.event.pull_request.base.ref }}" >> $GITHUB_OUTPUT
fi
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -162,10 +157,8 @@ jobs:

- id: setup_git_auth
name: Set up git token authentication
if: always() && (startsWith(github.event_name, 'pull_request') || success())
run: |
git config --global user.name "Auto-GPT-Bot"
git config --global user.email "github-bot@agpt.co"
config_key="http.${{ github.server_url }}/.extraheader"
base64_pat=$(echo -n "pat:${{ secrets.PAT_REVIEW }}" | base64 -w0)
Expand Down Expand Up @@ -193,51 +186,31 @@ jobs:
- id: push_cassettes
name: Push updated cassettes
if: always() && (startsWith(github.event_name, 'pull_request') || success())
run: |
if [ "${{ startsWith(github.event_name, 'pull_request') }}" = "true" ]; then
is_pull_request=true
cassette_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"
cassette_source_branch="${{ steps.checkout_cassettes.outputs.cassette_branch }}"
base_branch="${{ github.event.pull_request.base.ref }}"
else
current_branch=$(echo ${{ github.ref }} | sed -e "s/refs\/heads\///g")
cassette_branch=$current_branch
cassette_branch=$(echo ${{ github.ref }} | sed -e "s/refs\/heads\///g")
fi
cd tests/Auto-GPT-test-cassettes
git fetch origin $cassette_source_branch:$cassette_source_branch
# Commit & push changes to cassettes if any
if ! git diff --quiet $cassette_source_branch --; then
if [ "$cassette_branch" != "$cassette_source_branch" ]; then
git checkout -b $cassette_branch
fi
if ! git diff --quiet; then
git add .
git commit -m "Auto-update cassettes"
if [ $is_pull_request ]; then
git push --force origin HEAD:$cassette_branch
else
git push origin HEAD:$cassette_branch
fi
cd ../..
if [ $is_pull_request ]; then
git fetch origin $base_branch
cassette_diff=$(git diff origin/$base_branch)
else
git push origin HEAD:$cassette_branch
if [ ! $is_pull_request ]; then
cd ../..
git add tests/Auto-GPT-test-cassettes
git commit -m "Update cassette submodule"
git push origin HEAD:$current_branch
git push origin HEAD:$cassette_branch
fi
else
echo "No cassette changes to commit"
fi
if [ -n "$cassette_diff" ]; then
echo "updated=true" >> $GITHUB_OUTPUT
else
echo "updated=false" >> $GITHUB_OUTPUT
echo "No cassette changes to commit"
fi
- name: Post Set up git token auth
Expand All @@ -246,7 +219,7 @@ jobs:
git config --unset-all '${{ steps.setup_git_auth.outputs.config_key }}'
git submodule foreach git config --unset-all '${{ steps.setup_git_auth.outputs.config_key }}'
- name: Apply or remove behaviour change label and comment on PR
- name: Apply "behaviour change" label and comment on PR
if: ${{ startsWith(github.event_name, 'pull_request') }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
Expand All @@ -263,10 +236,4 @@ jobs:
echo $TOKEN | gh auth login --with-token
gh api repos/$REPO/issues/$PR_NUMBER/comments -X POST -F body="You changed AutoGPT's behaviour. The cassettes have been updated and will be merged to the submodule when this Pull Request gets merged."
else
echo "Removing label..."
curl -X DELETE \
-H "Authorization: Bearer $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels/behaviour%20change
fi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pytest_mock import MockerFixture

from autogpt.agent import Agent
from autogpt.commands.file_operations import read_file
Expand All @@ -17,7 +18,7 @@
@challenge
def test_write_file(
writer_agent: Agent,
patched_api_requestor: None,
patched_api_requestor: MockerFixture,
monkeypatch: pytest.MonkeyPatch,
config: Config,
level_to_run: int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pytest_mock import MockerFixture

from autogpt.commands.file_operations import read_file
from autogpt.config import Config
Expand All @@ -19,7 +20,7 @@
def test_information_retrieval_challenge_a(
information_retrieval_agents: Agent,
monkeypatch: pytest.MonkeyPatch,
patched_api_requestor: None,
patched_api_requestor: MockerFixture,
config: Config,
level_to_run: int,
) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import contextlib

import pytest
from pytest_mock import MockerFixture

from autogpt.agent import Agent
from autogpt.commands.file_operations import read_file
Expand All @@ -20,7 +21,7 @@
def test_information_retrieval_challenge_b(
get_nobel_prize_agent: Agent,
monkeypatch: pytest.MonkeyPatch,
patched_api_requestor: None,
patched_api_requestor: MockerFixture,
level_to_run: int,
config: Config,
) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import yaml
from pytest_mock import MockerFixture

from autogpt.agent import Agent
from autogpt.commands.file_operations import read_file
Expand All @@ -19,6 +20,7 @@
def test_kubernetes_template_challenge_a(
kubernetes_agent: Agent,
monkeypatch: pytest.MonkeyPatch,
patched_api_requestor: MockerFixture,
config: Config,
level_to_run: int,
) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pytest_mock import MockerFixture

from autogpt.agent import Agent
from autogpt.commands.file_operations import read_file, write_to_file
Expand All @@ -15,7 +16,7 @@
@challenge
def test_memory_challenge_a(
memory_management_agent: Agent,
patched_api_requestor: None,
patched_api_requestor: MockerFixture,
monkeypatch: pytest.MonkeyPatch,
config: Config,
level_to_run: int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pytest_mock import MockerFixture

from autogpt.agent import Agent
from autogpt.commands.file_operations import read_file, write_to_file
Expand All @@ -17,7 +18,7 @@
@challenge
def test_memory_challenge_b(
memory_management_agent: Agent,
patched_api_requestor: None,
patched_api_requestor: MockerFixture,
monkeypatch: pytest.MonkeyPatch,
config: Config,
level_to_run: int,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from pytest_mock import MockerFixture

from autogpt.agent import Agent
from autogpt.commands.file_operations import read_file, write_to_file
Expand All @@ -18,7 +19,7 @@
@challenge
def test_memory_challenge_c(
memory_management_agent: Agent,
patched_api_requestor: None,
patched_api_requestor: MockerFixture,
monkeypatch: pytest.MonkeyPatch,
config: Config,
level_to_run: int,
Expand Down

0 comments on commit c7b95da

Please sign in to comment.