用 GithubAction 替代 Zapier??
你需要使用 cfworker 做一下转发,可以参考这篇文章:如何订阅 Q 外的 RSS?方法来了
最近终于将 Ghost 前后端一体的身份转变为只作为提供数据的 CMS,前端则转为使用纯静态页面,使用 11ty 生成并部署在了 Netlify 上。
恰好 Ghost 自带的 WebHook 通知功能可以在执行文章、页面、Tag 甚至会员注册等操作时触发 Webhook 通知,同步触发部署操作,作为 Jamstack 的后端 CMS 工具可谓是十分好用。
我们只需进入 Ghost 后台,进入 Integrations
> Add custom Integrations
,起个名字,然点击下方的 Add Webhook
即可完成。
不过在使用 Ghost 的 Webhook 通知触发 Netlify 的时候发现在 文章内容过长 时 Netlify 会出现 payload 不能超过 140kb,并 build 失败的提示。
我查了一下资料,发现 Build payload exceeded limit of 140 KB - HUGO and Sanity.io 这篇文章提到两种解决办法
- 缩减 Ghost 发送的 Webhook 内容
- 通过其他 Webhook 工具接收,并删减掉内容再发送给 Netlify
第一种缩减 Ghost 发送内容的方法需要改 Ghost 源码,对于我目前这个水平来说明显不太现实。
所以只能用第二种办法了。
我尝试了一下文章内提到的 Zapier 后发现的确可以正常触发 Netlify 的 build 操作。
不过 Zapier 免费版只支持 100 个 plan,并且 Ghost 中不同的触发操作每一个都要手工创建一个触发器,可谓十分麻烦了。
所以,有没有其他工具?
答案是当然有拉 —— actionsflow,一款利用 Github Acion 实现 IFTTT/Zapier 同样效果的开源工具。
安装
可以看官方的安装教程,我这里总结一个简单版的。
- 通过这个链接 here 创建一个新的 rep。
- 将新 rep 项目中
.github/workflows/actionsflow.yml
文件中的的下面两行注释取消,意思让程序每 15 分钟触发一次 action。如果你像我一样只在需要的时候触发,可以不取消。
on:
schedule:
- cron: "*/15 * * * *"
- 在 rep 的文件夹
workflows
下创建 github action 格式的工作流文件就可以了,这里贴一份我的 webhook 配置。为了安全我这里将 Netlify 的 webhook key 使用 secrets 变量填入。Netlify 的 build webhook 在这里可以查看。
- 去 Github 生成 一个具有 rep 权限的 token(要常规模式的 token,不要问我怎么知道的)。
- 然后根据下面这个格式填写你的用户名、库名以及 workflows 名字(第三步新增的文件名),以及需要触发什么触发器,并且附上你的 Github Token,添加到 Ghost 中或者通过一些 API 测试工具测试即可。
# 填写规则
https://webhook.actionsflow.workers.dev/<用户名>/<rep名>/<workflows计划名>/<触发器类型>?__token=<yourgithubtoken>
# 我的示例
https://webhook.actionsflow.workers.dev/rebron1900/g-actions/netlify/webhook?__token=ghp_Nx17JGwMsjfdsafFD82nfsajn9rh19
目前还不知道怎么在触发器里组装自定义的消息发给 Netlify,之后再满满满研究吧。
actionsflow 支持很多种触发事件,列表如下,用法很多,之后有机会再来尝试其他的。
- Email - Watch for new emails.
- API polling - Polling JSON API updates.
- Graphql polling - Polling Graphql API updates.
- RSS - Watch RSS feed updates.
- Script - Run Javascript code to get updates.
- Webhook - Receive webhook notifications.
- AWS SNS - Any messages published to the SNS topic you create is triggered by this trigger.
- Google Form - Get Google Form response updates when someone submits their response.
- Instagram - Watch Instagram's media updates.
- NPM - Any new version of some package in NPM will trigger this trigger.
- Reddit - Any updates in Reddit will trigger this trigger.
- Slack - Triggered when new messages are detected on a specific Slack channel.
- Telegram Bot - Watch Telegram Bot updates.
- Trello - Watch any action updates on Trello.
- Twitter - Watch Twitter's timeline updates.
- Typeform - Get form response updates when someone submits their response.
- Weather - Get weather updates.
- Youtube - Get Youtube channel or playlist video updates.
加入评论