Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

巧妙利用 iOS 的快捷指令配合 GitHub Actions 实现自动化 #198

Open
yihong0618 opened this issue Dec 23, 2020 · 23 comments
Open
Labels
Top Top label of gitblog 开发笔记

Comments

@yihong0618
Copy link
Owner

yihong0618 commented Dec 23, 2020

之前一直在利用 Actions 的 crontab 每一个小时跑一次。但我一直在思考,能不能我只要跑完步就触发,那样可以节省很多资源,还可以跑完就能看到自己新生成的数据。

于是想到了,可以利用捷径啊!我们一般利用 app 记录跑步,如果能用某种手段跑完步,触发 Actions 就可以同步数据,或是完成其它功能了。

这样就不用 crontab 了,只要能利用手机触发就可以了。

那么怎么触发呢?

  • 最开始我知道 Actions 能手动触发是来自 @laixintao 的一篇博客 -- 玩了一下 Github 个人首页的 Profile 中的一个回复,原来是可以给 actions 增加手动触发选项的。
    image
  • 如果可以手动触发,那么有没有 api 呢?搜索了下 GitHub API 文档,并没有发现这个。尝试搜索了一下 GitHub 嗯,在某个项目下发现某个人做过类似的想法。好了,api 有了。试试能不能触发。
  • 首先在 yml 文件中增加 workflow_dispatch: 可以手动触发
  • 先拿到这个项目的 actions id (需要自行申请 token)
 curl https://api.github.com/repos/yihong0618/blog/actions/workflows -H "Authorization: token d8xxxxxxxxxx" # change to your config

image

  • 拿到 action id 就可以利用 api post 触发 action 啦
 curl -H "Content-Type:application/json" -X POST -d '{"inputs": {}, "ref":"master"}' https://api.github.com/repos/yihong0618/blog/actions/workflows/: actionid/dispatches -H "Authorization: token d8e03d6xxxxxxxxxxxx"  # change to your config

那么怎么结合捷径呢?

  1. 捷径打开或关闭 app 运行,那么,跑完步一般会关闭 app, 只要关闭 app 触发就可以
    image
  2. 增加捷径中的网络请求条件
    image
  3. 填写你之前获取到的 url 和 payload (触发捷径的api)
    image
  4. 你跑完步关闭跑步 app 时候就可以触发这个捷径了。之后就可以把原来 crontab 的一小时一次,改成一天一次了。
    image

还可以做什么呢?

  1. 利用 shanbay_remember 扇贝背完今日单词,关闭 app 时触发捷径自动发送今日的单词 mp3 和单词整理到 tg
  2. 利用地理位置或 wifi 触发,到公司自动发送每日 GitHub status
  3. 可以利用一个 action 触发另一个项目的 action,实现另一个 repo 的更新
  4. 利用关闭闹钟同步自己起床记录
  5. ..........欢迎大家想到好玩的补充
  6. 记录展示自己的心跳 -- iBeats
    image

另外

  1. 目前主分支可能是 main 而不是 master
  2. 可能需要 inputs 请按下图配置
  3. yml 中的 inputs 也可以按下图配置

image
image

@yihong0618 yihong0618 added 开发笔记 Top Top label of gitblog labels Dec 23, 2020
@frostming
Copy link
Contributor

捷徑好像很好用的樣子,我也想用iphone...

@yihong0618
Copy link
Owner Author

捷徑好像很好用的樣子,我也想用iphone...

我拍脑袋感觉安卓应该有替代品。

@yihong0618 yihong0618 changed the title 巧妙利用 iOS 的快捷指令(捷径)配合 GitHub Actions 实现自动化 巧妙利用 iOS 的快捷指令捷径配合 GitHub Actions 实现自动化 Jan 21, 2021
@yihong0618 yihong0618 changed the title 巧妙利用 iOS 的快捷指令捷径配合 GitHub Actions 实现自动化 巧妙利用 iOS 的快捷指令配合 GitHub Actions 实现自动化 Jan 21, 2021
@beyoung
Copy link

beyoung commented Apr 7, 2021

感谢分享😄

@yihong0618
Copy link
Owner Author

感谢分享😄

谢谢哈哈。

@W4J1e
Copy link

W4J1e commented Aug 18, 2021

慕名而来,这个用github issue写博客这个思路简直是妙啊!

@yihong0618
Copy link
Owner Author

慕名而来,这个用github issue写博客这个思路简直是妙啊!

谢谢哈哈哈

@phh95
Copy link

phh95 commented Sep 27, 2021

里面说的 需要自行申请 token,是去哪里申请呢?

@yihong0618
Copy link
Owner Author

里面说的 需要自行申请 token,是去哪里申请呢?

就是你 gitblog 的 token

@phh95
Copy link

phh95 commented Sep 27, 2021

如果要让触发后的结果显示在 GitHub ID 同名的 profile 页面中,是不是要把 workflow 文件放在 GitHub ID 同名的仓库中呢?看到你之前的 workflow 文件删除了 https://github.com/yihong0618/gitblog/blob/master/.github/workflows/generate_kb.yml 访问不了

@yihong0618
Copy link
Owner Author

如果要让触发后的结果显示在 GitHub ID 同名的 profile 页面中,是不是要把 workflow 文件放在 GitHub ID 同名的仓库中呢?看到你之前的 workflow 文件删除了 https://github.com/yihong0618/gitblog/blob/master/.github/workflows/generate_kb.yml 访问不了

可以参考这个
https://github.com/yihong0618/iBeats

@ygbingo
Copy link

ygbingo commented Nov 24, 2021

蟹蟹分享

@lofiCafe
Copy link

感谢yihong大哥的分享!

@yihong0618
Copy link
Owner Author

感谢yihong大哥的分享!

客气了。

@yihong0618
Copy link
Owner Author

蟹蟹分享

客气~

@antonio081014
Copy link

image

github官方提供。
ps:本质是一样的,纯分享一下。

@Mackerly
Copy link

Mackerly commented Sep 26, 2022

请问如何使用捷径更新 repository secret? 看文档 https://docs.github.com/en/rest/actions/secrets 中的Create or update a repository secret部分,不太明白 key_id 是什么。

@yihong0618
Copy link
Owner Author

@Mackerly
secret 在项目 setting 里设置。

@i-abc
Copy link

i-abc commented Oct 22, 2022

老哥这太酷了。
我在安卓上使用 MacroDroid,用来自动同步 GitHubPoster、running_page,太方便了。

image

@yihong0618
Copy link
Owner Author

老哥这太酷了。 我在安卓上使用 MacroDroid,用来自动同步 GitHubPoster、running_page,太方便了。

image

哈哈

@QiYongchuan
Copy link

老哥整个项目太酷了!我从昨天晚上8点看到现在!(也不是一直看👀,自己跟着搭建了我的第一版博客,目前还没实现自动化的更新等。)

太有趣了,我希望后续可以继续搭建起我的其他功能。

太有意思的项目啦

@yihong0618
Copy link
Owner Author

老哥整个项目太酷了!我从昨天晚上8点看到现在!(也不是一直看👀,自己跟着搭建了我的第一版博客,目前还没实现自动化的更新等。)

太有趣了,我希望后续可以继续搭建起我的其他功能。

太有意思的项目啦

谢谢~(^-^)

@eatcosmos
Copy link

可以搞个情侣心跳,当心跳一样的时候出个特效

@yihong0618
Copy link
Owner Author

可以搞个情侣心跳,当心跳一样的时候出个特效

来!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Top Top label of gitblog 开发笔记
Projects
None yet
Development

No branches or pull requests