AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Fix Python CI "update cassettes" step (#4591)
merwanehamadiee6b97ef5e7e
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex df9148c4b9..8d44f2a4b2 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -18,7 +18,7 @@ concurrency:jobs:lint:# eliminate duplicate runs on master- if: github.event_name == 'push' || github.ref_name != 'master' || (github.event.pull_request.head.repo.fork == (github.event_name == 'pull_request_target'))+ if: github.event_name == 'push' || github.base_ref != 'master' || (github.event.pull_request.head.repo.fork == (github.event_name == 'pull_request_target'))runs-on: ubuntu-latestenv:@@ -37,14 +37,15 @@ jobs:with:python-version: ${{ env.min-python-version }}- - name: Set Date- run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV+ - id: get_date+ name: Get date+ run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT- - name: Cache Python packages+ - name: Set up Python dependency cacheuses: actions/cache@v3with:path: ~/.cache/pip- key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ env.DATE }}+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ steps.get_date.outputs.date }}- name: Install dependenciesrun: |@@ -73,7 +74,7 @@ jobs:test:# eliminate duplicate runs on master- if: github.event_name == 'push' || github.ref_name != 'master' || (github.event.pull_request.head.repo.fork == (github.event_name == 'pull_request_target'))+ if: github.event_name == 'push' || github.base_ref != 'master' || (github.event.pull_request.head.repo.fork == (github.event_name == 'pull_request_target'))permissions:# Gives the action the necessary permissions for publishing new@@ -90,7 +91,7 @@ jobs:python-version: ["3.10"]steps:- - name: Check out repository+ - name: Checkout repositoryuses: actions/checkout@v3with:fetch-depth: 0@@ -98,8 +99,12 @@ jobs:repository: ${{ github.event.pull_request.head.repo.full_name }}submodules: true- - id: checkout_cassettes- name: Check out cassettes+ - name: Configure git user Auto-GPT-Bot+ run: |+ git config --global user.name "Auto-GPT-Bot"+ git config --global user.email "[email protected]"++ - name: Checkout cassettesif: ${{ startsWith(github.event_name, 'pull_request') }}run: |cassette_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"@@ -111,21 +116,14 @@ 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+ # Pick non-conflicting cassette updates from the base branch+ git merge --no-commit --strategy-option=ours origin/${{ github.event.pull_request.base.ref }}+ echo "Using cassettes from mirror branch '$cassette_branch'," \+ "synced to upstream branch '${{ github.event.pull_request.base.ref }}'."else- 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+ git checkout -b $cassette_branch+ echo "Branch '$cassette_branch' does not exist in cassette submodule." \+ "Using cassettes from '${{ github.event.pull_request.base.ref }}'."fi- name: Set up Python ${{ matrix.python-version }}@@ -133,21 +131,22 @@ jobs:with:python-version: ${{ matrix.python-version }}- - name: Set Date- run: echo "DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV+ - id: get_date+ name: Get date+ run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT- - name: Cache Python packages+ - name: Set up Python dependency cacheuses: actions/cache@v3with:path: ~/.cache/pip- key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ env.DATE }}+ key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ steps.get_date.outputs.date }}- - name: Install dependencies+ - name: Install Python dependenciesrun: |python -m pip install --upgrade pippip install -r requirements.txt- - name: Run pytest tests with coverage+ - name: Run pytest with coveragerun: |pytest -n auto --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report termpython tests/integration/challenges/utils/build_current_score.py@@ -162,10 +161,9 @@ jobs:- id: setup_git_authname: Set up git token authentication+ # Cassettes may be pushed even when tests fail+ if: success() || failure()run: |- git config --global user.name "Auto-GPT-Bot"- git config --global user.email "[email protected]"-config_key="http.${{ github.server_url }}/.extraheader"base64_pat=$(echo -n "pat:${{ secrets.PAT_REVIEW }}" | base64 -w0)@@ -186,58 +184,39 @@ jobs:if ! git diff --quiet $score_file; thengit add $score_filegit commit -m "Update challenge scores"- git push origin HEAD:${{ github.ref }}+ git push origin HEAD:${{ github.ref_name }}elseecho "The challenge scores didn't change."fi- id: push_cassettesname: Push updated cassettes+ # For pull requests, push updated cassettes even when tests fail+ if: github.event_name == 'push' || success() || failure()run: |if [ "${{ startsWith(github.event_name, 'pull_request') }}" = "true" ]; thenis_pull_request=truecassette_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="${{ github.ref_name }}"ficd 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; thengit 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-cassettesgit commit -m "Update cassette submodule"- git push origin HEAD:$current_branch+ git push origin HEAD:$cassette_branchfi- else- echo "No cassette changes to commit"- fi-- if [ -n "$cassette_diff" ]; thenecho "updated=true" >> $GITHUB_OUTPUTelseecho "updated=false" >> $GITHUB_OUTPUT+ echo "No cassette changes to commit"fi- name: Post Set up git token auth@@ -246,7 +225,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 PRif: ${{ startsWith(github.event_name, 'pull_request') }}run: |PR_NUMBER=${{ github.event.pull_request.number }}@@ -263,10 +242,4 @@ jobs:echo $TOKEN | gh auth login --with-tokengh 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%20changefidiff --git a/tests/integration/challenges/basic_abilities/test_write_file.py b/tests/integration/challenges/basic_abilities/test_write_file.pyindex cbbad514b6..393dbfd05d 100644--- a/tests/integration/challenges/basic_abilities/test_write_file.py+++ b/tests/integration/challenges/basic_abilities/test_write_file.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom autogpt.agent import Agentfrom autogpt.commands.file_operations import read_file@@ -17,7 +18,7 @@ CYCLE_COUNT = 3@challengedef test_write_file(writer_agent: Agent,- patched_api_requestor: None,+ patched_api_requestor: MockerFixture,monkeypatch: pytest.MonkeyPatch,config: Config,level_to_run: int,diff --git a/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.py b/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.pyindex 6b970e8b22..2f61fef390 100644--- a/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.py+++ b/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_a.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom autogpt.commands.file_operations import read_filefrom autogpt.config import Config@@ -19,7 +20,7 @@ from autogpt.agent import Agentdef 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:diff --git a/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_b.py b/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_b.pyindex feac95a0f6..6461e13fbf 100644--- a/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_b.py+++ b/tests/integration/challenges/information_retrieval/test_information_retrieval_challenge_b.py@@ -1,6 +1,7 @@import contextlibimport pytest+from pytest_mock import MockerFixturefrom autogpt.agent import Agentfrom autogpt.commands.file_operations import read_file@@ -20,7 +21,7 @@ CYCLE_COUNT = 3def 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:diff --git a/tests/integration/challenges/kubernetes/test_kubernetes_template_challenge_a.py b/tests/integration/challenges/kubernetes/test_kubernetes_template_challenge_a.pyindex 5fd280ac4b..aa46ac4d4f 100644--- a/tests/integration/challenges/kubernetes/test_kubernetes_template_challenge_a.py+++ b/tests/integration/challenges/kubernetes/test_kubernetes_template_challenge_a.py@@ -1,5 +1,6 @@import pytestimport yaml+from pytest_mock import MockerFixturefrom autogpt.agent import Agentfrom autogpt.commands.file_operations import read_file@@ -19,6 +20,7 @@ CYCLE_COUNT = 3def test_kubernetes_template_challenge_a(kubernetes_agent: Agent,monkeypatch: pytest.MonkeyPatch,+ patched_api_requestor: MockerFixture,config: Config,level_to_run: int,) -> None:diff --git a/tests/integration/challenges/memory/test_memory_challenge_a.py b/tests/integration/challenges/memory/test_memory_challenge_a.pyindex 8919bf58c0..08f461bdd8 100644--- a/tests/integration/challenges/memory/test_memory_challenge_a.py+++ b/tests/integration/challenges/memory/test_memory_challenge_a.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom autogpt.agent import Agentfrom autogpt.commands.file_operations import read_file, write_to_file@@ -15,7 +16,7 @@ from tests.utils import requires_api_key@challengedef 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,diff --git a/tests/integration/challenges/memory/test_memory_challenge_b.py b/tests/integration/challenges/memory/test_memory_challenge_b.pyindex 5c28b330a3..c82763129a 100644--- a/tests/integration/challenges/memory/test_memory_challenge_b.py+++ b/tests/integration/challenges/memory/test_memory_challenge_b.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom autogpt.agent import Agentfrom autogpt.commands.file_operations import read_file, write_to_file@@ -17,7 +18,7 @@ NOISE = 1000@challengedef 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,diff --git a/tests/integration/challenges/memory/test_memory_challenge_c.py b/tests/integration/challenges/memory/test_memory_challenge_c.pyindex 23c0217d61..ab8ece1052 100644--- a/tests/integration/challenges/memory/test_memory_challenge_c.py+++ b/tests/integration/challenges/memory/test_memory_challenge_c.py@@ -1,4 +1,5 @@import pytest+from pytest_mock import MockerFixturefrom autogpt.agent import Agentfrom autogpt.commands.file_operations import read_file, write_to_file@@ -18,7 +19,7 @@ NOISE = 1000@challengedef 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,