くらげになりたい。

くらげのようにふわふわ生きたい日曜プログラマなブログ。趣味の備忘録です。

GitHub ActionsでSHORT_SHAを環境変数に設定する

前書いたのの別バージョン。開発中はタグ名じゃなくて、SHORT_SHAにしたい。

www.memory-lovers.blog

"on":
  push:
    branches:
      - develop
jobs:
  build_and_deploy:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - name: Checuout
        uses: actions/checkout@v2
      - name: Get the version
        id: get_version
        # gitコマンドを使ってSHORT SHAを取得
        run: echo ::set-output name=VERSION::$(git rev-parse --short HEAD)
      - name: Do something
        run: ...
        env:
          # stepIdの"get_version"を使って、outputs.VERSIONを取得
          VERSION: ${{ steps.get_version.outputs.VERSION }}

GITHUB_SHAであれば、環境変数に設定されているので、そのまま使える。
環境変数 - GitHub Docs

参考にしたサイト様