IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    用GithubAction替代Zapier?

    1900发表于 2024-01-09 19:19:38
    love 0

    最近终于将Ghost前后端一体的身份转变为只作为提供数据的CMS,前端则转为使用纯静态页面,使用11ty生成并部署在了Netlify上。

    恰好Ghost自带的WebHook通知功能可以在执行文章、页面、Tag甚至会员注册等操作时触发Webhook通知,同步触发部署操作,作为Jamstack的后端CMS工具可谓是十分好用。

    我们只需进入Ghost后台,进入 Integrations > Add custom Integrations ,起个名字,然点击下方的 Add Webhook 即可完成。

    alt
    alt

    添加Webhook通知触发器

    不过在使用Ghost的Webhook通知触发Netlify的时候发现在 文章内容过长 时Netlify会出现payload不能超过140kb,并build失败的提示。

    alt

    我查了一下资料,发现 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 同样效果的开源工具。

    GitHub - actionsflow/actionsflow: The free Zapier/IFTTT alternative for developers to automate your workflows based on Github actions
    The free Zapier/IFTTT alternative for developers to automate your workflows based on Github actions - GitHub - actionsflow/actionsflow: The free Zapier/IFTTT alternative for developers to automate…
    altGitHubactionsflow
    alt

    安装

    可以看官方的安装教程,我这里总结一个简单版的。

    • 通过这个链接 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在这里可以查看。
    on:
      webhook:
    jobs:
      request:
        name: Make a HTTP Request
        runs-on: ubuntu-latest
        steps:
          - name: Make a HTTP Request
            uses: actionsflow/axios@v1
            id: info
            with:
              url: https://api.netlify.com/build_hooks/${{ secrets.NETLIFYKEY }}?trigger_branch=main&trigger_title=gaction
              method: POST
              body: |
                {
                  "link":"test", 
                }

    netlify.yml

    • 去 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
    alt

    目前还不知道怎么在触发器里组装自定义的消息发给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.


沪ICP备19023445号-2号
友情链接