mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-26 10:24:30 +01:00
220 lines
8.3 KiB
YAML
220 lines
8.3 KiB
YAML
name: Python CI
|
|
|
|
on:
|
|
push:
|
|
branches: [ master, ci-test*]
|
|
paths-ignore:
|
|
- 'tests/Auto-GPT-test-cassettes'
|
|
- 'tests/integration/challenges/current_score.json'
|
|
pull_request_target:
|
|
branches: [ master, stable , ci-test*]
|
|
|
|
concurrency:
|
|
group: ${{ format('ci-{0}', github.head_ref && format('pr-{0}', github.event.pull_request.number) || github.sha) }}
|
|
cancel-in-progress: ${{ github.event_name == 'pull_request_target' }}
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
min-python-version: "3.10"
|
|
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.event.pull_request.head.ref }}
|
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
|
|
- name: Set up Python ${{ env.min-python-version }}
|
|
uses: actions/setup-python@v2
|
|
with:
|
|
python-version: ${{ env.min-python-version }}
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
|
|
- name: Lint with flake8
|
|
run: flake8
|
|
|
|
- name: Check black formatting
|
|
run: black . --check
|
|
if: success() || failure()
|
|
|
|
- name: Check isort formatting
|
|
run: isort . --check
|
|
if: success() || failure()
|
|
|
|
- name: Check mypy formatting
|
|
run: mypy
|
|
if: success() || failure()
|
|
|
|
- name: Check for unused imports and pass statements
|
|
run: |
|
|
cmd="autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests"
|
|
$cmd --check || (echo "You have unused imports or pass statements, please run '${cmd} --in-place'" && exit 1)
|
|
|
|
test:
|
|
permissions:
|
|
# Gives the action the necessary permissions for publishing new
|
|
# comments in pull requests.
|
|
pull-requests: write
|
|
# Gives the action the necessary permissions for pushing data to the
|
|
# python-coverage-comment-action branch, and for editing existing
|
|
# comments (to avoid publishing multiple comments in the same PR)
|
|
contents: write
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 30
|
|
strategy:
|
|
matrix:
|
|
python-version: ["3.10"]
|
|
|
|
steps:
|
|
- name: Check out repository
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
ref: ${{ github.event.pull_request.head.ref }}
|
|
repository: ${{ github.event.pull_request.head.repo.full_name }}
|
|
submodules: true
|
|
token: ${{ secrets.PAT_REVIEW }}
|
|
|
|
- name: Use cassettes previously sent
|
|
if: ${{ github.event_name == 'pull_request_target' }}
|
|
run: |
|
|
new_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"
|
|
git config --global user.name "Github Actions"
|
|
git config --global user.email "github-actions@github.com"
|
|
cd tests/Auto-GPT-test-cassettes
|
|
|
|
if git ls-remote --exit-code --heads origin $new_branch ; then
|
|
git fetch origin $new_branch:$new_branch
|
|
git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }}
|
|
|
|
git checkout $new_branch
|
|
|
|
if git merge --no-commit --no-ff ${{ github.event.pull_request.base.ref }}; then
|
|
echo "No merge conflict detected. We can use the cassettes previously sent."
|
|
else
|
|
echo "Merge conflict detected. This means we cannot use the cassettes previously sent, so we will take the cassettes of ${{ github.event.pull_request.base.ref }}."
|
|
git merge --abort
|
|
git checkout ${{ github.event.pull_request.base.ref }}
|
|
fi
|
|
else
|
|
echo "Branch $new_branch does not exist. We will use the cassettes of ${{ github.event.pull_request.base.ref }}"
|
|
fi
|
|
|
|
- name: Set up Python ${{ matrix.python-version }}
|
|
uses: actions/setup-python@v2
|
|
with:
|
|
python-version: ${{ matrix.python-version }}
|
|
|
|
- name: Install dependencies
|
|
run: |
|
|
python -m pip install --upgrade pip
|
|
pip install -r requirements.txt
|
|
|
|
- name: Run pytest tests with coverage
|
|
run: |
|
|
pytest -n auto --cov=autogpt --cov-report term-missing --cov-branch --cov-report xml --cov-report term
|
|
python tests/integration/challenges/utils/build_current_score.py
|
|
env:
|
|
CI: true
|
|
PROXY: ${{ secrets.PROXY }}
|
|
AGENT_MODE: ${{ vars.AGENT_MODE }}
|
|
AGENT_TYPE: ${{ vars.AGENT_TYPE }}
|
|
|
|
- name: Upload coverage reports to Codecov
|
|
uses: codecov/codecov-action@v3
|
|
|
|
- name: Update cassette submodule to push target if push event
|
|
if: ${{ github.event_name == 'push' }}
|
|
run: |
|
|
current_branch=$(echo ${{ github.ref }} | sed -e "s/refs\/heads\///g")
|
|
git config --global user.name "Auto-GPT-Bot"
|
|
git config --global user.email "github-bot@agpt.co"
|
|
git add tests/integration/challenges/current_score.json
|
|
|
|
if ! git diff-index --quiet HEAD; then
|
|
git commit -m "Update current score"
|
|
git push origin HEAD:refs/heads/$current_branch
|
|
else
|
|
echo "The current score didn't change."
|
|
fi
|
|
|
|
cd tests/Auto-GPT-test-cassettes
|
|
git fetch origin $current_branch
|
|
git add .
|
|
|
|
# Check if there are any changes
|
|
if ! git diff-index --quiet HEAD; then
|
|
git commit -m "Auto-update cassettes after Push event"
|
|
git pull --rebase origin $current_branch
|
|
|
|
git push origin HEAD:refs/heads/$current_branch
|
|
|
|
cd ../..
|
|
git add tests/Auto-GPT-test-cassettes
|
|
git commit -m "Update submodule reference"
|
|
git push origin HEAD:refs/heads/$current_branch
|
|
else
|
|
echo "No cassettes changes to commit"
|
|
exit 0
|
|
fi
|
|
|
|
- name: Update cassette submodule to submodule branch if PR event
|
|
if: ${{ github.event_name == 'pull_request_target' }}
|
|
run: |
|
|
new_branch="${{ github.event.pull_request.user.login }}-${{ github.event.pull_request.head.ref }}"
|
|
|
|
cd tests/Auto-GPT-test-cassettes
|
|
git config --global user.name "Auto-GPT-Bot"
|
|
git config --global user.email "github-bot@agpt.co"
|
|
git add .
|
|
|
|
# Check if there are any changes
|
|
if ! git diff-index --quiet HEAD; then
|
|
git commit -m "Auto-update cassettes after merging PR #$pr_number"
|
|
git push -f origin HEAD:refs/heads/$new_branch
|
|
|
|
else
|
|
echo "No changes to commit"
|
|
exit 0
|
|
fi
|
|
git fetch origin ${{ github.event.pull_request.base.ref }}:${{ github.event.pull_request.base.ref }} || echo "DIFF_EXISTS=false" >> $GITHUB_ENV
|
|
differences=$(git diff origin/$new_branch origin/${{ github.event.pull_request.base.ref }})
|
|
|
|
if [ -n "$differences" ]; then
|
|
echo "DIFF_EXISTS=true" >> $GITHUB_ENV
|
|
else
|
|
echo "DIFF_EXISTS=false" >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Apply or remove behaviour change label and comment
|
|
if: ${{ github.event_name == 'pull_request_target' }}
|
|
run: |
|
|
PR_NUMBER=${{ github.event.pull_request.number }}
|
|
TOKEN=${{ secrets.PAT_REVIEW }}
|
|
REPO=${{ github.repository }}
|
|
|
|
if [[ "${{ env.DIFF_EXISTS }}" == "true" ]]; then
|
|
echo "Adding label and comment..."
|
|
curl -X POST \
|
|
-H "Authorization: Bearer $TOKEN" \
|
|
-H "Accept: application/vnd.github.v3+json" \
|
|
https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels \
|
|
-d '{"labels":["behaviour change"]}'
|
|
|
|
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
|