是否有一种方法可以在动作运行时使用github-cli或api查看动作的输入?
我希望允许Github操作同时运行。它们将管理的资源由输入stack_name决定。我希望确保两个管道不能使用相同的stack_name输入同时运行。如果发生这种情况,那么我希望其中一个管道操作失败并立即停止。
我也接受了投入,并将其转化为我的一项工作的环境变量。作业完成后,这些值在日志中可用,我可以通过下面的输出来获得管道stack_name
$ gh run view $running_pipeline_id --repo=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY --log
....
env-check env-check 2022-03-22T17:06:30.2615395Z STACK_NAME: foo但是,在作业运行时,这是不可用的,相反,我得到了以下错误:
run 1234567890 is still in progress; logs will be available when it is complete这里是我目前尝试的一个代码块,可以实现这一点。我还可以建议如何进行更好的gh run list和/或gh run view调用,以避免使用grep和awk。我可以用jq解析的干净的json输出是更好的选择。
set +e
running_pipeline_ids=$(gh run list --workflow=$SLEEVE --repo=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY \
| grep 'in_progress' \
| awk '{print $((NF-2))}' \
| grep -v $GITHUB_RUN_ID)
set -e
for running_pipeline_id in $running_pipeline_ids; do
# get the stack name for all other running pipelines
running_pipeline_stack_name=$(gh run view $running_pipeline_id --repo=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY --log \
| grep 'STACK_NAME:' | head -n 1 \
| awk -F "STACK_NAME:" '{print $2}' | awk '{print $1}')
# fail if we detect another pipeline running against the same stack
if [ "$running_pipeline_stack_name" == "$STACK_NAME" ]; then
echo "ERROR: concurrent pipeline detected. $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$running_pipeline_id"
echo "Please try again after the running pipeline has completed."
exit 1
fi
done发布于 2022-03-23 08:29:23
也许您可以使用并发性特性的GitHub操作?
现在您不能直接将其分解为一个操作,但是如果您可以将您的操作提取到一个可重用工作流中,那么您可以使用并发特性。
看起来会是这样的:
# ./github/workflows/partial.yaml
on:
workflow_call:
inputs:
stack-name:
description: "name of the stack"
required: true
type: string
jobs:
greet:
runs-on: ubuntu-latest
concurrency:
group: ${{ inputs.stack-name }}
cancel-in-progress: true
steps:
- uses: my/other-action
with:
stack_name: ${{ inputs.stack-name }}然后你使用它的地方:
jobs:
test:
uses: my/app-repo/.github/workflows/partial.yml@main
with:
stack-name: 'my-stack'https://stackoverflow.com/questions/71578673
复制相似问题