1
0

More than 1 year has passed since last update.

GitHub Actionsのcronが60日で止まる件対応をしてみる

Last updated at Posted at 2023-01-20

こちらの記事になるように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日経った時にうごいてればセーフです。
検証中...

1
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0