AutoGPT

Форк
0
/
autogpt-ci.yml 
296 строк · 10.5 Кб
1
name: AutoGPT Python CI
2

3
on:
4
  push:
5
    branches: [ master, development, ci-test* ]
6
    paths:
7
      - '.github/workflows/autogpt-ci.yml'
8
      - 'autogpts/autogpt/**'
9
      - '!autogpts/autogpt/tests/vcr_cassettes'
10
  pull_request:
11
    branches: [ master, development, release-* ]
12
    paths:
13
      - '.github/workflows/autogpt-ci.yml'
14
      - 'autogpts/autogpt/**'
15
      - '!autogpts/autogpt/tests/vcr_cassettes'
16

17
concurrency:
18
  group: ${{ format('autogpt-ci-{0}', github.head_ref && format('{0}-{1}', github.event_name, github.event.pull_request.number) || github.sha) }}
19
  cancel-in-progress: ${{ startsWith(github.event_name, 'pull_request') }}
20

21
defaults:
22
  run:
23
    shell: bash
24
    working-directory: autogpts/autogpt
25

26
jobs:
27
  lint:
28
    runs-on: ubuntu-latest
29
    env:
30
      min-python-version: "3.10"
31

32
    steps:
33
      - name: Checkout repository
34
        uses: actions/checkout@v4
35
        with:
36
          fetch-depth: 0
37

38
      - name: Set up Python ${{ env.min-python-version }}
39
        uses: actions/setup-python@v5
40
        with:
41
          python-version: ${{ env.min-python-version }}
42

43
      - id: get_date
44
        name: Get date
45
        run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
46

47
      - name: Set up Python dependency cache
48
        uses: actions/cache@v4
49
        with:
50
          path: ~/.cache/pypoetry
51
          key: ${{ runner.os }}-poetry-${{ hashFiles('autogpts/autogpt/pyproject.toml') }}-${{ steps.get_date.outputs.date }}
52

53
      - name: Install Python dependencies
54
        run: |
55
          curl -sSL https://install.python-poetry.org | python3 -
56
          poetry install
57

58
      - name: Lint with flake8
59
        run: poetry run flake8
60

61
      - name: Check black formatting
62
        run: poetry run black . --check
63
        if: success() || failure()
64

65
      - name: Check isort formatting
66
        run: poetry run isort . --check
67
        if: success() || failure()
68

69
      # - name: Check mypy formatting
70
      #   run: poetry run mypy
71
      #   if: success() || failure()
72

73
      # - name: Check for unused imports and pass statements
74
      #   run: |
75
      #     cmd="autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports --ignore-pass-after-docstring autogpt tests"
76
      #     poetry run $cmd --check || (echo "You have unused imports or pass statements, please run '${cmd} --in-place'" && exit 1)
77

78
  test:
79
    permissions:
80
      contents: read
81
    timeout-minutes: 30
82
    strategy:
83
      fail-fast: false
84
      matrix:
85
        python-version: ["3.10"]
86
        platform-os: [ubuntu, macos, macos-arm64, windows]
87
    runs-on: ${{ matrix.platform-os != 'macos-arm64' && format('{0}-latest', matrix.platform-os) || 'macos-14' }}
88

89
    steps:
90
      # Quite slow on macOS (2~4 minutes to set up Docker)
91
      # - name: Set up Docker (macOS)
92
      #   if: runner.os == 'macOS'
93
      #   uses: crazy-max/ghaction-setup-docker@v3
94

95
      - name: Start MinIO service (Linux)
96
        if: runner.os == 'Linux'
97
        working-directory: '.'
98
        run: |
99
          docker pull minio/minio:edge-cicd
100
          docker run -d -p 9000:9000 minio/minio:edge-cicd
101

102
      - name: Start MinIO service (macOS)
103
        if: runner.os == 'macOS'
104
        working-directory: ${{ runner.temp }}
105
        run: |
106
          brew install minio/stable/minio
107
          mkdir data
108
          minio server ./data &
109

110
      # No MinIO on Windows:
111
      # - Windows doesn't support running Linux Docker containers
112
      # - It doesn't seem possible to start background processes on Windows. They are
113
      #   killed after the step returns.
114
      #   See: https://github.com/actions/runner/issues/598#issuecomment-2011890429
115

116
      - name: Checkout repository
117
        uses: actions/checkout@v4
118
        with:
119
          fetch-depth: 0
120
          submodules: true
121

122
      - name: Configure git user Auto-GPT-Bot
123
        run: |
124
          git config --global user.name "Auto-GPT-Bot"
125
          git config --global user.email "github-bot@agpt.co"
126

127
      - name: Checkout cassettes
128
        if: ${{ startsWith(github.event_name, 'pull_request') }}
129
        env:
130
          PR_BASE: ${{ github.event.pull_request.base.ref }}
131
          PR_BRANCH: ${{ github.event.pull_request.head.ref }}
132
          PR_AUTHOR: ${{ github.event.pull_request.user.login }}
133
        run: |
134
          cassette_branch="${PR_AUTHOR}-${PR_BRANCH}"
135
          cassette_base_branch="${PR_BASE}"
136
          cd tests/vcr_cassettes
137

138
          if ! git ls-remote --exit-code --heads origin $cassette_base_branch ; then
139
            cassette_base_branch="master"
140
          fi
141

142
          if git ls-remote --exit-code --heads origin $cassette_branch ; then
143
            git fetch origin $cassette_branch
144
            git fetch origin $cassette_base_branch
145

146
            git checkout $cassette_branch
147

148
            # Pick non-conflicting cassette updates from the base branch
149
            git merge --no-commit --strategy-option=ours origin/$cassette_base_branch
150
            echo "Using cassettes from mirror branch '$cassette_branch'," \
151
              "synced to upstream branch '$cassette_base_branch'."
152
          else
153
            git checkout -b $cassette_branch
154
            echo "Branch '$cassette_branch' does not exist in cassette submodule." \
155
              "Using cassettes from '$cassette_base_branch'."
156
          fi
157

158
      - name: Set up Python ${{ matrix.python-version }}
159
        uses: actions/setup-python@v5
160
        with:
161
          python-version: ${{ matrix.python-version }}
162

163
      - id: get_date
164
        name: Get date
165
        run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
166

167
      - name: Set up Python dependency cache
168
        # On Windows, unpacking cached dependencies takes longer than just installing them
169
        if: runner.os != 'Windows'
170
        uses: actions/cache@v4
171
        with:
172
          path: ${{ runner.os == 'macOS' && '~/Library/Caches/pypoetry' || '~/.cache/pypoetry' }}
173
          key: poetry-${{ runner.os }}-${{ hashFiles('autogpts/autogpt/poetry.lock') }}
174

175
      - name: Install Poetry (Unix)
176
        if: runner.os != 'Windows'
177
        run: |
178
          curl -sSL https://install.python-poetry.org | python3 -
179

180
          if [ "${{ runner.os }}" = "macOS" ]; then
181
            PATH="$HOME/.local/bin:$PATH"
182
            echo "$HOME/.local/bin" >> $GITHUB_PATH
183
          fi
184

185
      - name: Install Poetry (Windows)
186
        if: runner.os == 'Windows'
187
        shell: pwsh
188
        run: |
189
          (Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | python -
190

191
          $env:PATH += ";$env:APPDATA\Python\Scripts"
192
          echo "$env:APPDATA\Python\Scripts" >> $env:GITHUB_PATH
193

194
      - name: Install Python dependencies
195
        run: poetry install
196

197
      - name: Run pytest with coverage
198
        run: |
199
          poetry run pytest -vv \
200
            --cov=autogpt --cov-branch --cov-report term-missing --cov-report xml \
201
            --numprocesses=logical --durations=10 \
202
            tests/unit tests/integration
203
        env:
204
          CI: true
205
          PLAIN_OUTPUT: True
206
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
207
          S3_ENDPOINT_URL: ${{ runner.os != 'Windows' && 'http://127.0.0.1:9000' || '' }}
208
          AWS_ACCESS_KEY_ID: minioadmin
209
          AWS_SECRET_ACCESS_KEY: minioadmin
210

211
      - name: Upload coverage reports to Codecov
212
        uses: codecov/codecov-action@v4
213
        with:
214
          token: ${{ secrets.CODECOV_TOKEN }}
215
          flags: autogpt-agent,${{ runner.os }}
216

217
      - id: setup_git_auth
218
        name: Set up git token authentication
219
        # Cassettes may be pushed even when tests fail
220
        if: success() || failure()
221
        run: |
222
          config_key="http.${{ github.server_url }}/.extraheader"
223
          if [ "${{ runner.os }}" = 'macOS' ]; then
224
            base64_pat=$(echo -n "pat:${{ secrets.PAT_REVIEW }}" | base64)
225
          else
226
            base64_pat=$(echo -n "pat:${{ secrets.PAT_REVIEW }}" | base64 -w0)
227
          fi
228

229
          git config "$config_key" \
230
            "Authorization: Basic $base64_pat"
231

232
          cd tests/vcr_cassettes
233
          git config "$config_key" \
234
            "Authorization: Basic $base64_pat"
235

236
          echo "config_key=$config_key" >> $GITHUB_OUTPUT
237

238
      - id: push_cassettes
239
        name: Push updated cassettes
240
        # For pull requests, push updated cassettes even when tests fail
241
        if: github.event_name == 'push' || (! github.event.pull_request.head.repo.fork && (success() || failure()))
242
        env:
243
          PR_BRANCH: ${{ github.event.pull_request.head.ref }}
244
          PR_AUTHOR: ${{ github.event.pull_request.user.login }}
245
        run: |
246
          if [ "${{ startsWith(github.event_name, 'pull_request') }}" = "true" ]; then
247
            is_pull_request=true
248
            cassette_branch="${PR_AUTHOR}-${PR_BRANCH}"
249
          else
250
            cassette_branch="${{ github.ref_name }}"
251
          fi
252

253
          cd tests/vcr_cassettes
254
          # Commit & push changes to cassettes if any
255
          if ! git diff --quiet; then
256
            git add .
257
            git commit -m "Auto-update cassettes"
258
            git push origin HEAD:$cassette_branch
259
            if [ ! $is_pull_request ]; then
260
              cd ../..
261
              git add tests/vcr_cassettes
262
              git commit -m "Update cassette submodule"
263
              git push origin HEAD:$cassette_branch
264
            fi
265
            echo "updated=true" >> $GITHUB_OUTPUT
266
          else
267
            echo "updated=false" >> $GITHUB_OUTPUT
268
            echo "No cassette changes to commit"
269
          fi
270

271
      - name: Post Set up git token auth
272
        if: steps.setup_git_auth.outcome == 'success'
273
        run: |
274
          git config --unset-all '${{ steps.setup_git_auth.outputs.config_key }}'
275
          git submodule foreach git config --unset-all '${{ steps.setup_git_auth.outputs.config_key }}'
276

277
      - name: Apply "behaviour change" label and comment on PR
278
        if: ${{ startsWith(github.event_name, 'pull_request') }}
279
        run: |
280
          PR_NUMBER="${{ github.event.pull_request.number }}"
281
          TOKEN="${{ secrets.PAT_REVIEW }}"
282
          REPO="${{ github.repository }}"
283

284
          if [[ "${{ steps.push_cassettes.outputs.updated }}" == "true" ]]; then
285
            echo "Adding label and comment..."
286
            echo $TOKEN | gh auth login --with-token
287
            gh issue edit $PR_NUMBER --add-label "behaviour change"
288
            gh issue comment $PR_NUMBER --body "You changed AutoGPT's behaviour on ${{ runner.os }}. The cassettes have been updated and will be merged to the submodule when this Pull Request gets merged."
289
          fi
290

291
      - name: Upload logs to artifact
292
        if: always()
293
        uses: actions/upload-artifact@v4
294
        with:
295
          name: test-logs
296
          path: autogpts/autogpt/logs/
297

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.