0xf

日記だよ

GitHub Actionsメモ

ちょっと調べていたのでメモしておく。

  • 今のところApproveされているかどうかは拾えなさそう。mergeableであるかどうかのチェックで代用するのが正解かな。mergeableは pull_request データ構造に存在する。
  • ワークフロー中、人間の承認を要求するようにするのは Env を利用すると良さそう。
  • workflow_dispatch で手動実行する際にパラメータ指定ができるようになってた
  • issue_comment とかでPRの内容に応じた処理をしたい場合には PR の head を取得したあと checkout を実行する
    • PR元のブランチは head、PR先はbaseで取得できる。returnでオブジェクトを返すとシリアライズされて面倒なので変数名つけてoutputに突っ込んでおくと便利だった。そういえば json 形式で文字列を返すと "hello"みたいになるって話があった。単一文字列のJSON表現。デフォルトの result-encoding が json だということを知ってれば「まあ・・・」って気にはなる。
     - uses: actions/github-script@v6
        id: pull_request_info
        with:
          script: |
            const pull_request = await github.request(context.payload.issue.pull_request.url)
            function setOutput(name, value){
               console.log(`::set-output name=${name}::${value}`)
            }
            setOutput("head_ref", pull_request.data.head.ref)
            setOutput("base_ref", pull_request.data.base.ref)
            setOutput("merged_at", pull_request.merged_at)
     - uses: actions/checkout@v2
        with:
          ref: ${{ steps.pull_request_info.outputs.head_ref }}
  • comment-ops的なことをやろうとすると create時だけでいいか、editも対応しようか迷う。
    • edit の際は github.event.changes で変更元がやってくるので、例えばコメントの編集であれば、github.event.changes.body.fromgithub.event.comment.body を併せて記載してあげると親切かもしれない。