Github Actionsのあれこれ
github acitonsで差分ファイルをzip化する方法を探った際のメモ
参考:
https://www.granfairs.com/blog/staff/git-archivediff
https://dev.classmethod.jp/articles/github-actions-get-diff-files-on-pr-events/
https://dev.classmethod.jp/articles/how-to-get-a-ref-branch-within-a-workflow-execution-in-github-actions/
https://qiita.com/nade/items/3a5fbd77e2bc7df8a48a
リポジトリのブランチにアクセスする
https://github.com/actions/checkout
github context: https://docs.github.com/en/actions/learn-github-actions/contexts#github-context
デフォルトの環境変数:https://docs.github.com/ja/actions/learn-github-actions/variables#default-environment-variables
プルリク時に作成されるブランチ
参考:https://qiita.com/sonots/items/16df445132e704198e3e
pull/xxx/head は Pull Request を送ったブランチの head (最新状態)、pull/xxx/merge はマージ対象のブランチとマージした結果の状態を持つブランチである。
うまく差分が取れていないケースでは、refs/remotes/pull/**/merge(マージブランチ)がfetchで取れていない
参考:https://zenn.dev/babyjob/articles/bb4ef287ce8b0d#原因はチェックアウトするブランチ
マージブランチにcheckoutさせるため、actions/checkout@v3にref: ${{ github.context.ref }}を追記したが、やはりbase(master)にcheckoutしてしまう
→PRのmergeをトリガーにしていたため、マージブランチが既に存在しなかった?の原因(トリガーをPRのopenに変えるとdiffがうまく取れた)
→なぜcheckout先が変わると結果も変わる?
そもそもmergeした時点でbaseとheadの差分がなくなるから、その二つを比較する方法じゃ取れるわけがない?
baseの一個前のハッシュ(マージコミットの前)の状態と比較すればいける?もしくはbaseの最新と一個前
mergeをトリガーにする
code:yml
on:
pull_request:
types: closed
jobs:
build:
if: github.event.pull_request.merged == true
localでworkflowを実行するツール(未実施)
https://github.com/nektos/act
step間でのデータ参照はoutput経由
code:yml
- id: get-url
run: echo "url=https://xxx.com" >> "$GITHUB_OUTPUT"
- run: echo ${{ steps.get-url.outputs.url }}
※"$GITHUB_OUTPUTではなく$GITHUB_ENVを使うサンプルもよく見るが上手く動かない(nullになる)
→re-runする時にdebug log有効化すれば変数の中身まで全て出力してくれる
ref: Github Actionsでchrome拡張のリリース周りのあれこれを自動化する