0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

GitHubActionsで通し番号(バージョン番号など)を利用したい時

Last updated at Posted at 2022-09-02

概要

GitHubActionsでバージョン番号を管理したい時は github.run_number が便利です。
GooglePlayのバージョン管理、ビルドしたファイルのファイル名に通し番号をつけたりする時などに利用できそうです。

本文

github.run_number はGitHubActionsでワークフローが実行される度に1ずつ数が増えていきます。(初めての実行時は1)

例えば以下のコードはKotlinのversionCodeを自動更新するものですが、 ${{github.run_number}} の記述をすることで、カウントアップされる数字を当てはめることができます。

name: 'build product'

on: [workflow_dispatch]

jobs:
  manual_run:
    runs-on: ubuntu-latest
    steps:
    - name: checkout
      uses: actions/checkout@v3
    - name: set up JDK 11
      uses: actions/setup-java@v3
      with:
        java-version: '11'
        distribution: 'temurin'
        cache: gradle
    # https://github.com/marketplace/actions/increment-the-version-code-of-your-project
    - name: Bump version
      uses: chkfung/android-version-actions@v1.1
      with:
        gradlePath: app/build.gradle
        versionCode: ${{github.run_number}}

補足

github.run_number は1からスタートする数なので、もっと大きい数が欲しい時は以下のようにすると実現できます。(2022年8月現在 github.run_number は手動で変更することは出来ないようです)

    - name: echo message
      run: |
        echo $((${{github.run_number}}+23))
        echo "現在のバージョンは12.4.${{github.run_number}}です"

実行結果
スクリーンショット 2022-08-28 15.59.02.png

補足2

github.run_number を1にリセットしたい時はyamlファイルのファイル名を変更します。(コード内のname:部分を変えるだけではリセットされません)

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?