Closed17

masterにPRがマージされたらgobumpでバージョン上げてgit tagを打つgithub actions

Hirotaka MiyagiHirotaka Miyagi

しかしgithub actions、このあたりの発火タイミングのデバッグって難しくないですか?PRマージしないとちゃんと動いてるか試せないというか…

PR作ってる最中はこんな感じでデバッグする

name: bump-version

on:
#  pull_request:
#    branches:
#      - master
#    types: [closed]
  push:
Hirotaka MiyagiHirotaka Miyagi

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に通してくれるとのことなので、特に考えずこれで行けそうな予感

Hirotaka MiyagiHirotaka Miyagi

とりあえずこんな感じに

  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
Hirotaka MiyagiHirotaka Miyagi

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"

動いた!嬉しい
一旦コミットメッセージは保留

Hirotaka MiyagiHirotaka Miyagi

pushをしていく

      -  
        name: Push changes
        uses: ad-m/github-push-action@master
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          branch: ${{ github.ref }}
Hirotaka MiyagiHirotaka Miyagi

いろいろ悩んだ結果こうなった

      -
        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}}"

一発で行けそうな気がするけど動くのでとりあえずいいや〜

Hirotaka MiyagiHirotaka Miyagi

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にクローズされました