Closed17
masterにPRがマージされたらgobumpでバージョン上げてgit tagを打つgithub actions
「masterにPRがマージされた」時だけ発火するgithub actions
この辺りを見てるとこう書く感じで良さそう
name: bump-version
on:
pull_request:
branches:
- master
types: [closed]
jobs:
gobump:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
しかしgithub actions、このあたりの発火タイミングのデバッグって難しくないですか?PRマージしないとちゃんと動いてるか試せないというか…
PR作ってる最中はこんな感じでデバッグする
name: bump-version
on:
# pull_request:
# branches:
# - master
# types: [closed]
push:
やりたいこと:このブログのシェルスクリプトをgithub actionsで再現したい
gobumpをgithub actionsで動かせるところまで行ってみる
jobs:
gobump:
# if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14.x
-
name: Install gobump
run: go get github.com/x-motemen/gobump/cmd/gobump
-
name: bump minor version
run: gobump patch -w -v
actions/setup-go@v2
はGOBINをPATHに通してくれるとのことなので、特に考えずこれで行けそうな予感
動いた!簡単やないか!
続いてgithub actions上からcommitするのを試してみる
pushのためのライブラリがあるとのこと
https://github.com/ad-m/github-push-action
とりあえずこんな感じに
git:
needs: gobump
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: git add and git commit
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "hoge" -a
動かなかった
gobumpの変更が反映できてなさそう
めんどくさそうなのでjobを一つにまとめてしまおうか
gobumpのしたに持ってきた
-
name: Install gobump
run: go get github.com/x-motemen/gobump/cmd/gobump
-
name: bump minor version
run: gobump patch -w util/constants
-
name: git add and git commit
run: |
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add .
git commit -m "hoge"
動いた!嬉しい
一旦コミットメッセージは保留
pushをしていく
-
name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
これも動いた!嬉しいね
最後にgit tagを打つぞ
https://github.com/ad-m/github-push-action はtagsも打つことが可能
まずはbumpしたバージョンを取得する
gobump show
で現在のバージョンが {"Version":"1.0.5"}
こんな感じのjsonで手に入る
github actionsではfromJson関数が用意されてるからこれで取り出せそうな予感
いろいろ悩んだ結果こうなった
-
name: show json
id: show_json
run: |
json=$(gobump show)
echo "::set-output name=VERSION_JSON::$json"
-
name: show version
id: set_version
run: |
echo "::set-output name=VERSION::${{fromJson(steps.show_json.outputs.VERSION_JSON).Version}}"
一発で行けそうな気がするけど動くのでとりあえずいいや〜
tag打ってpush
-
name: git tag
run: |
git tag "{{ steps.set_version.outputs.VERSION }}"
-
name: Push tag
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
tags: true
このスクラップは2021/12/15にクローズされました