こちらの記事になるように60日間動きがないとcronが止まってしまう模様です。
定期的に定期実行処理が止まってる。。
現在時刻をもとにファイル作成してGit Pushしてみる
- 現在時刻取得
- JSONファイル作成
- GitHub Actions側からGit Push
をして定期実行すれば常に動き(commitやpush)がある状態になりそう。
JavaScriptの処理でJSONファイルを書き出す
現在時間を取得してJSONに書き出す処理です。
時間はday.jsを使用
const fs = require('fs');
const LOGFILE_NAME = `log.json`;
//日本時間
const dayjs = require('dayjs');
const utc = require('dayjs/plugin/utc');
const timezone = require('dayjs/plugin/timezone');
dayjs.extend(utc);
dayjs.extend(timezone);
dayjs.tz.setDefault("Asia/Tokyo");
//ロギング
const logjson = {
msg: 'success',
time: dayjs().tz().format()
}
fs.writeFileSync(LOGFILE_NAME, JSON.stringify(logjson));
console.log(`log done--`);
GitHub Actionsに追記
以下でGitHub Actions側でGit commit & pushをしてくれる
- name: git commit & push
run: |
git config core.filemode false
if ! git diff --exit-code --quiet
then
git add --update
git config user.name github-actions
git config user.email action@github.com
git commit -m "Commit by github-actions"
git push https://${{github.actor}}:${{secrets.GITHUB_TOKEN}}@github.com/${{github.repository}}.git HEAD:${{github.ref}}
fi
参考: https://intestine.hatenadiary.jp/entry/2021/08/10/151409
ということで様子見
一旦回してみるけどこれで60日経った時にうごいてればセーフです。
検証中...