GitHub Actions:带有输入的调度和计划工作流程
最近编写了一个项目,需要每天定时从 producthunt 抓取数据并生成阅读良好的 markdown 文档,项目已经上线,[参考地址](https://indiehack.org/)。
除此之外,还希望能够输入日期,手动触发抓取这一天的数据。
也就是,工作流有输入。当工作流由 cron 触发时,我需要它使用一些默认变量运行。当手动触发时,我想允许用户覆盖一些默认值。

Github Actions 工作流示例
比如:有如下 github actions 工作流:
name: Print some text every 3rd minute
on:
schedule:
- cron: '1/3 * * * *'
jobs:
print_text:
runs-on: 'ubuntu-20.04'
steps:
-name: Print some text
run: echo "Periodically printing passages"
每隔一段时间,输出一段文字Periodically printing passages
如果手动触发时,允许输入参数覆盖这一段文字,可以在定义工作流中,使用 inputs 来定义可以接收的输入,参考如下:
name: Print some text every 3rd minute
on:
schedule:
- cron: '1/3 * * * *'
workflow_dispatch: # adding the workflow_dispatch so it can be triggered manually
inputs:
text_to_print:
description: 'What text do you want to print?'
required: true
default: 'Periodically printing passages'
jobs:
print_text:
runs-on: 'ubuntu-20.04'
steps:
- name: Set the variables
env:
DEFAULT_MESSAGE: 'Periodically printing passages' # here is the default message
run: echo "MESSAGE=${{ github.event.inputs.text_to_print || env.DEFAULT_MESSAGE }}" >> $GITHUB_ENV
- name: Print some text
run: echo "$MESSAGE" # prints the environmental variable, MESSAGE
我可以在 GitHub 中的 Actions 标签中触发此操作:

让这个工作发挥作用的关键是:
echo "MESSAGE=${{ github.event.inputs.text\_to\_print || env.DEFAULT\_MESSAGE }}" >> $GITHUB\_ENV
上面一行选择将定义的变量赋值给变量,MESSAGE然后将其注入到变量中$GITHUB\_ENV。我们可以在Print some text步骤中引用它。
参考资料
继续阅读
基于全文检索与主题相似度
使用 Github Action自动执行 Netlify 部署
GitHub Actions 在众多使用场景中都非常实用,例如在特定操作(如推送到某个分支)时触发 CI/CD 构建。还可以扩展为在特定时间运行定时任务(cron job)。 在本文中,我们将探讨如何利用 GitHub Actions 在指定时间触发 Netlify 的构建任务。 本博客是部署在 Netlify 上,技
Github 仓库操作— token使用,Action 操作权限
由于最近有在 mac 上操作多个 Github 账号代码库的情况。 记得之前操作的方式,是配置 ssh key等操作权限,需要在 mac 隐藏目录.ssh下面的known_hosts文件进行编辑,将相应 key 填写进去。 或者使用用户名密码操作的方式,不过随着 GitHub 对用户安全要求的提升,GitHub 已经停
使用自定义 GitHub Actions CI/CD 部署到 Vercel
除了上一篇介绍的 使用 Github Action自动执行Vercel 部署** **使用Deploy Hooks 的方式进行部署之外,还可以有更复杂的场景。 比如可以将 Vercel 与 GitHub Actions 一起使用作为您的 CI/CD 提供程序,在每次推送代码时生成预览部署,并在代码合并到main分支时部