与当地环境相比,github行动行为不同

发布于 2025-02-08 12:17:18 字数 2216 浏览 1 评论 0原文

我创建了一个GitHub Action Pipeline来进行最近的订单代码。该测试脚本在我的本地环境中起作用,但在GitHub服务器中不起作用。我没有注意到什么特殊性?

这是我的覆盖代码:

    #!/usr/bin/env bash
    
    LATEST_COMMIT=$(git rev-parse HEAD);
    echo "Analyzing code changes under the commit hash: $LATEST_COMMIT";
    FILES_UNDER_THE_LATEST_COMMIT=$(git diff-tree --no-commit-id --name-only -r $LATEST_COMMIT);
    echo "Files under the commit:";
    echo $FILES_UNDER_THE_LATEST_COMMIT;
    MATCHES=$(echo $FILES_UNDER_THE_LATEST_COMMIT | grep '.py');
    echo "Files under the commit with Python extension: $MATCHES";
    echo "Starting linting...";
    if echo $MATCHES | grep -q '.py';
    then
      echo $MATCHES | xargs pylint --rcfile .pylintrc;
    else
      echo "Nothing to lint";
    fi

这是我的github操作配置:

name: Pylint

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10"]
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      if: "!contains(github.event.head_commit.message, 'NO_LINT')"
      run: |
        python -m pip install --upgrade pip
        pip install pylint psycopg2 snowflake-connector-python pymssql
        chmod +x .github/workflows/run_linting.sh
    - name: Analysing all Python scripts in the project with Pylint
      if: "contains(github.event.head_commit.message, 'CHECK_ALL')"
      run: pylint --rcfile .pylintrc lib processes tests
    - name: Analysing the latest committed changes Pylint
      if: "!contains(github.event.head_commit.message, 'NO_LINT')"
      run: .github/workflows/run_linting.sh

我在github中获得的内容:

以及我的计算机上的内容:

I have created a GitHub actions pipeline to do linting of the recent committed code. The test script works in my local environment, but not on the GitHub server. What peculiarity I don't notice?

Here is my code for linting:

    #!/usr/bin/env bash
    
    LATEST_COMMIT=$(git rev-parse HEAD);
    echo "Analyzing code changes under the commit hash: $LATEST_COMMIT";
    FILES_UNDER_THE_LATEST_COMMIT=$(git diff-tree --no-commit-id --name-only -r $LATEST_COMMIT);
    echo "Files under the commit:";
    echo $FILES_UNDER_THE_LATEST_COMMIT;
    MATCHES=$(echo $FILES_UNDER_THE_LATEST_COMMIT | grep '.py');
    echo "Files under the commit with Python extension: $MATCHES";
    echo "Starting linting...";
    if echo $MATCHES | grep -q '.py';
    then
      echo $MATCHES | xargs pylint --rcfile .pylintrc;
    else
      echo "Nothing to lint";
    fi

Here is my GitHub Actions config:

name: Pylint

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.10"]
    steps:
    - uses: actions/checkout@v3
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v3
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      if: "!contains(github.event.head_commit.message, 'NO_LINT')"
      run: |
        python -m pip install --upgrade pip
        pip install pylint psycopg2 snowflake-connector-python pymssql
        chmod +x .github/workflows/run_linting.sh
    - name: Analysing all Python scripts in the project with Pylint
      if: "contains(github.event.head_commit.message, 'CHECK_ALL')"
      run: pylint --rcfile .pylintrc lib processes tests
    - name: Analysing the latest committed changes Pylint
      if: "!contains(github.event.head_commit.message, 'NO_LINT')"
      run: .github/workflows/run_linting.sh

What I get in GitHub:
What I get in GitHub

And what on my computer:
And what on my computer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愚人国度 2025-02-15 12:17:18

简而言之,这是您的问题:

 步骤:
     - 用途:Action/Checkout@V3
 

默认情况下,Checkout@v2neckout@v3使浅>浅> (depth 1),单分支克隆。这样的克隆完全有一个提交:最近的克隆人。

结果,这是:

  git diff-tree -no-commit-id -name-name-home-r $最新_commit
 

根本没有产生输出。没有父母的承诺可以与之进行比较。 (我认为这是git中的一个错误:git diff-tree应注意,由于.git/浅层嫁接文件。 ,浅层克隆制作git diff-tree think 这是一个根提交,奇怪的将每个文件当作添加的每个文件 - 不是您想要的,而是实际上工作

。 >将迫使一个完整的(非保留)克隆,但是使用浅单分支克隆的原因是通过省略不必要的提交来加快动作。由于这里只需要前两个“层”提交的“层”,depth:2提供了正确的数字。

旁注:您的bash代码已用半柱终止。这可以正常工作,但是不必要(这让我想起了太多的C或C ++编程。 1 ,您还可以运行git git diff-tree< options :不需要单独的git rev-parse在这里步骤(尽管您可能仍然希望在echo


)从C到C ++,到Python到Shell等。我要么放置太多或太少的括号和半柱,导致C编译器错误来自:

if x == 0 {

因为我的大脑处于GO模式。 GO代码,我放了太多括号,但是GOFMT将其删除,并且没有编译错误。

Here's your problem in a nutshell:

    steps:
    - uses: actions/checkout@v3

By default, checkout@v2 and checkout@v3 make a shallow (depth 1), single-branch clone. Such a clone has exactly one commit in it: the most recent one.

As a consequence, this:

git diff-tree --no-commit-id --name-only -r $LATEST_COMMIT

produces no output at all. There's no parent commit available to compare against. (I'd argue that this is a bit of a bug in Git: git diff-tree should notice that the parent is missing due to the .git/shallow grafts file. However, git diff-tree traditionally produces an empty diff for a root commit, and without special handling in git diff-tree, the shallow clone makes git diff-tree think this is a root commit. Oddly, the user-oriented git diff would treat every file as added—still not what you want, but it would have actually worked.)

To fix this, force the depth to be at least 2. Using depth: 0 will force a full (non-shallow) clone, but the reason for using a shallow, single-branch clone is to speed up the action by omitting unnecessary commits. As only the first two "layers" of commit are required here, depth: 2 provides the correct number.

Side note: your bash code has every command terminated with a semicolon. This works fine, but is unnecessary (it reminds me of doing too much C or C++ programming.1 Also, you can just run git diff-tree <options> HEAD: there's no need for a separate git rev-parse step here (though you might still want that in the echo).


1As I switch from C to C++ to Go to Python to shell etc., I either put in too many or too few parentheses and semicolons, leading to C compiler errors from:

if x == 0 {

because my brain is in Go mode. ???? When I switch back to hacking on the Go code, I put in too many parentheses, but gofmt removes them and there's no compile error.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文