与当地环境相比,github行动行为不同
我创建了一个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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,这是您的问题:
默认情况下,
Checkout@v2
和neckout@v3
使浅>浅> (depth 1),单分支克隆。这样的克隆完全有一个提交:最近的克隆人。结果,这是:
根本没有产生输出。没有父母的承诺可以与之进行比较。 (我认为这是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编译器错误来自:
因为我的大脑处于GO模式。 GO代码,我放了太多括号,但是
GOFMT
将其删除,并且没有编译错误。Here's your problem in a nutshell:
By default,
checkout@v2
andcheckout@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:
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 ingit diff-tree
, the shallow clone makesgit diff-tree
think this is a root commit. Oddly, the user-orientedgit 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 rungit diff-tree <options> HEAD
: there's no need for a separategit rev-parse
step here (though you might still want that in theecho
).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:
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.