LoginSignup
0
0

More than 1 year has passed since last update.

Flutterアプリのversionを更新するためのスクリプト

Last updated at Posted at 2022-11-09

概要

Flutterで作ったアプリのバージョンはpubspec.yamlの中で定義しているため、CIなどで自動更新するにはスクリプトなどを書く必要がある。
覚書程度に残しておく。

スクリプト

# Versionの更新
perl -i -pe 's/^(version:)(\s+\d+\.\d+\.)(\d+)(\+)(\d+)$/$1.$2.($3+1).$4.$5/e' pubspec.yaml

自分はGithub Actionsで実行している。
具体の実装は下記。

- name: update app version
  run: |
    # Versionの更新
    perl -i -pe 's/^(version:)(\s+\d+\.\d+\.)(\d+)(\+)(\d+)$/$1.$2.($3+1).$4.$5/e' pubspec.yaml

    # 別のstepで更新されたVerisonを利用するための後処理
    VAR=`perl -ne 'print if /^(version:)(\s+\d+\.\d+\.)(\d+)(\+)(\d+)$/' pubspec.yaml`
    VAR_APP_VERSION=`echo $VAR | grep -o -E "([0-9]+\.){1}[0-9]+(\.[0-9]+)?" | head -n1`
    echo "::set-output name=APP_VERSION::${VAR_APP_VERSION}"

ついでに

build number も更新したくなってくるが、これはbuildオプションの --build-number で渡せるようになっているので、それを利用すれば良い。

flutter build ipa -h の出力結果.
build-h をつけても表示されないので注意。

--build-number                                  

An identifier used as an internal version number.
Each build must have a unique identifier to differentiate it from previous builds.
It is used to determine whether one build is more recent than another, with higher numbers indicating more recent build.
On Android it is used as "versionCode".
On Xcode builds it is used as "CFBundleVersion".

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