github-actions:上一步的多行输出,并在工作流程的下一步中“使用”

问题描述 投票:0回答:1

我不明白,如何收集上一步中实现为

uses
的所有输出,以在工作流程的下一步中将其作为 PR 评论公开。

关于使用 variables

$GITHUB_OUTPUT
&GITHUB_STEP_SUMMARY
echo <<EOF
等收集多行输出有很多答案,但为此需要使用自己的脚本。

我的脚本是:

name: check-pep8
on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  check-pep8:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      checks: write
      pull-requests: write

    steps:
      - uses: actions/checkout@v4

      - name: Run PEP-8 check
        id: pep8-action
        continue-on-error: true
        uses: quentinguidee/pep8-action@v1
        with:
          arguments: '--max-line-length=120'

      - name: Comment PR
        if: steps.pep8-action.status != 'success'
        uses: thollander/actions-comment-pull-request@v3
        with:
          message: |
            ${{ join(steps.pep8-action.outputs.output, ' ') }}

步骤

pep8-action
的完整输出是

./corpora_deduplication.py:42:15: E701 multiple statements on one line (colon)
./corpora_deduplication.py:47:41: E222 multiple spaces after operator
./corpora_deduplication.py:47:41: E251 unexpected spaces around keyword / parameter equals
./corpora_deduplication.py:47:121: E501 line too long (145 > 120 characters)
./corpora_deduplication.py:48:81: E702 multiple statements on one line (semicolon)
./corpora_deduplication.py:48:121: E501 line too long (163 > 120 characters)
./corpora_deduplication.py:61:3: E271 multiple spaces after keyword
./corpora_deduplication.py:61:13: E225 missing whitespace around operator
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
Warning: The `set-output` command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
./corpora_deduplication.py:47:41: E222 multiple spaces after operator
./corpora_deduplication.py:47:41: E251 unexpected spaces around keyword / parameter equals
./corpora_deduplication.py:47:121: E501 line too long (145 > 120 characters)
./corpora_deduplication.py:48:81: E702 multiple statements on one line (semicolon)
./corpora_deduplication.py:48:121: E501 line too long (163 > 120 characters)
./corpora_deduplication.py:61:3: E271 multiple spaces after keyword
./corpora_deduplication.py:61:13: E225 missing whitespace around operator

我看到了

steps.pep8-action.outputs.output
中唯一的第一行:

{
"exit-code": "1",
"output": "./corpora_deduplication.py:42:15: E701 multiple statements on one line (colon)"
}

有什么解决方法吗?

github yaml github-actions pep8 github-ci
1个回答
0
投票

感谢 Benjamin W. 的通知。

我走了另一条路,按照文档做了一切。

# Install Python dependencies, run tests and lint Python code
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python package

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  checks:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      checks: write
      pull-requests: write

    steps:
    - name: Checkout repo
      uses: actions/checkout@v4

    - name: Set up Python
      uses: actions/setup-python@v3
      with:
        # Semantic version range syntax or exact version of a Python version
        python-version: '3.x'
        # Optional - x64 or x86 architecture, defaults to x64
        architecture: 'x64'
        # Cache all dependencies
        cache: 'pip'

    - name: Install dependencies
      run: |
        python -m  pip install --upgrade pip
        python -m  pip install flake8 pytest
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    
    - name: Lint with flake8
      continue-on-error: true
      id: pep8-action
      run: |
        {
          # Keep the multi-line output
          echo 'output<<EOF'
          # stop the build if there are Python syntax errors or undefined names
          flake8 . --count --select=E9,F63,F7,F82 --show-source --exit-zero
          echo ---
          # exit-zero treats all errors as warnings
          flake8 . --count --max-complexity=10 --max-line-length=120 --exit-zero
          echo EOF
        } >> "$GITHUB_OUTPUT"

    - name: Comment PR
      if: ${{ contains(steps.pep8-action.outputs.output, 'py') }}
      uses: thollander/actions-comment-pull-request@v3
      with:
        message: |
          ${{ join(steps.pep8-action.outputs.output, ' ') }}

    - name: Test with pytest
      run: |
        pytest

    - name: Lint check is failed
      if: ${{ contains(steps.pep8-action.outputs.output, 'py') }}
      run: exit 1
© www.soinside.com 2019 - 2024. All rights reserved.