繁体   English   中英

如何在 github 中找到一份工作,每天随机运行 1 到 50 次?

[英]how can I make a job in github action run randomly between 1 and 50 times a day?

如何在 github 中找到一份工作,每天随机运行 1 到 50 次?

这是我的 cron 工作。

cron: '0 0 * * *'

这将每天运行一次。

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

如何让它从 1 到 50 随机工作?

下面是我的 git 动作的 yml 设置文件作为工作流

#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 作业和随机时间,在给定的时间内通过这篇文章的方法不起作用。

在此处输入图像描述

此致!

您可以通过修改 Bash 脚本以随机循环次数来执行此操作。 例如,这个 Bash 脚本循环 1 到 50 次。

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

这种方法的一个缺点是您需要采取在“提交文件”步骤中完成的步骤并将它们合并到“执行命令”步骤中的脚本中,否则它们将不会重复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM