我怎么可以做一份工作,在审查行动运行之间随机1和50次一天?

0

的问题

我怎么可以做一份工作,在审查行动运行之间随机1和50次一天?

这是我计划任务的工作。

cron:'0 0 * * *'

这将每天运行一次。

但是我想要的是运行随机的1-50次一天。

我怎么让它随意从1到50?

下面是我的混帐行动的阳明海运设定文件作为工作流程

#1. Repository Fork
# 2. Modify the files A and B according to the procedure
# 3. After committing the modifications, push & Enjoy!

name: planting-grass

# A. Comment lines 8-11
# on:
# push:
# branches:
# - unknown

# B. Uncomment lines 14-16
on:
   schedule:
     - cron: '0 0 * * *'

jobs:
  task:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set current date
        id: date
        run: echo "::set-output name=date::$(date +'%Y-%m-%d')"
      - name: Execute commands
        run: bash ./task.sh ${{ steps.date.outputs.date }}
      - name: Commit files
        run: |
          git config --global user.name "$(git --no-pager log --format=format:'%an' -n 1)"
          git config --global user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
          git add date.txt
          git commit -m ${{ steps.date.outputs.date }}
      - name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ github.ref }}

Cron作业,并随机的时候,在给定时间 的方法,通过这个岗位不工作。

enter image description here

最好的问候!

bash cron github-actions sh
2021-11-20 05:36:39
1

最好的答案

1

你可以通过修改您的庆典脚本循环的一个随机的次数。 例如,这Bash脚本的循环之间1和50倍。

#!/usr/bin/env bash
loops=$(( ( RANDOM % 50 )  + 1 ))
echo "$loops"
for i in $(seq 1 $loops); do
    echo foo
done

一个缺点,这种做法是,你需要采取的步骤正在做'提交文件的步骤,并将它们合并成的脚本中的'执行命令'的步骤,或他们不会重复。

2021-11-20 06:06:40

在从初行动的环境中,不能运行的阳明海运环境内的对发言。
emarwa.mouma.35t

真的,但是所有的东西你做内的"提交的文件"的步骤是东西,你可以在庆典。 配置Git? 你可以做那个在庆典。 提交的文件? 你可以做那个在庆典。 得到的日期? 你可以做那个在庆典。
Nick ODell

结果,这种解决方案: ./task.sh: 4: i: not found
emarwa.mouma.35t

@emarwa.mouma.35t如果你真的不关心的时间间隔,这种做法是最佳国际海事组织。 每天一次,脚本/守则之间运行的1和50次。 你可以实现它作为一个包装脚本的电话 ./task.sh (而不是的 echo foo),或者,加上循环 task.sh. 我会用 for ((i=1; i<=loops; i++)) 而不是的 seq但这并不重要。
dan

@emarwa.mouma.35t样的错误在你 前面的问题,我的答案,需要指定bash. 运行 while (( i <= loops )) (或类似的)在 sh 将产生这一错误。
dan

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................