๐ 5๋ถ ์์ Git ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ Flutter CI/CD
๋ชฉ์ฐจ
ํ์ํ ๊ฒ
๋ ๋ญ ํ ๊ฑฐ์ผ
์ ์ฑ ๋ฒ์ ์ด ํฌํจ๋ git ํ๊ทธ๋ฅผ ๋ง๋ ๋ค์ ๋ฆฌํฌ์งํ ๋ฆฌ์ ํธ์ํฉ๋๋ค. ์๋์ผ๋ก Codemagic ๋น๋๋ฅผ ํธ๋ฆฌ๊ฑฐํ๊ณ Play ์คํ ์ด ๐์์ ์ฑ์ ์ถ์ํฉ๋๋ค.
1๋จ๊ณ: ๋ฐฐํฌ ์คํฌ๋ฆฝํธ ๋ง๋ค๊ธฐ ๐
Below you'll find code to configure the CI/CD. You just have to add it to the root of your repository in a file named codemagic.yaml
I've used a script instead of the workflow editor (Codemagic GUI) for multiple reasons (versioned, faster...) but mainly because the version handling isn't possible using the editor.
# codemagic.yaml
# ... <- Here you will include the "reusable" parts that are described afterward
workflows:
play-store:
name: Play Store Release
max_build_duration: 30
cache: *caching
environment:
flutter: *flutter_version
xcode: latest
cocoapods: default
vars:
<<: *gcp_service_credentials
<<: *keystore_release
# ! THE IMPORTANT PART IS HERE !
triggering:
events:
- tag
branch_patterns:
- pattern: "master"
include: true
source: true
tag_patterns:
- pattern: "*"
include: true
scripts:
- *android_key_properties_setup
- *flutter_android_properties_setup
- *flutter_pub_get
- *flutter_test
- *flutter_build_play_store_release
artifacts:
- build/**/outputs/**/*.aab
publishing:
google_play:
credentials: *play_console_credentials
track: alpha
in_app_update_priority: 0
# codemagic.yaml
reusable:
flutter_version: &flutter_version 1.22.6
environment-variables:
- &keystore_release
FCI_KEYSTORE_PATH: /tmp/keystore.keystore
FCI_KEYSTORE: Encrypted(...)
FCI_KEYSTORE_PASSWORD: Encrypted(...)
FCI_KEY_PASSWORD: Encrypted(...)
FCI_KEY_ALIAS: Encrypted(...)
- &gcp_service_credentials
GCLOUD_SERVICE_ACCOUNT_CREDENTIALS: Encrypted(...)
- &play_console_credentials Encrypted(...)
scripts:
- &android_key_properties_setup
name: Android - Setup key.properties
script: |
echo $FCI_KEYSTORE | base64 --decode > $FCI_KEYSTORE_PATH
cat >> "$FCI_BUILD_DIR/android/key.properties" <<EOF
storePassword=$FCI_KEYSTORE_PASSWORD
keyPassword=$FCI_KEY_PASSWORD
keyAlias=$FCI_KEY_ALIAS
storeFile=/tmp/keystore.keystore
EOF
- &flutter_android_properties_setup
name: Flutter x Android - Setup local.properties
script: echo "flutter.sdk=$HOME/programs/flutter" > "$FCI_BUILD_DIR/android/local.properties"
- &flutter_pub_get
name: Flutter - Get dependencies
script: flutter packages pub get
- &flutter_test
name: Flutter - Run tests
script: flutter test --machine
# ! THE IMPORTANT PART IS HERE !
- &flutter_build_play_store_release
name: Build AAB for Play Store release
script: |
GCLOUD_SERVICE_ACCOUNT_CREDENTIALS=$(echo $GCLOUD_SERVICE_ACCOUNT_CREDENTIALS | base64 --decode)
NEW_BUILD_NUMBER=$(($(google-play get-latest-build-number --package-name 'com.company.example') + 1))
NEW_VERSION_NAME=$(git describe --tags)
echo $NEW_VERSION_NAME
echo $NEW_BUILD_NUMBER
flutter build appbundle --build-name=$NEW_VERSION_NAME --build-number=$NEW_BUILD_NUMBER --obfuscate --split-debug-info=$FCI_BUILD_DIR/debug_files
caching: &caching
cache_paths:
- $HOME/.gradle/caches
- $FLUTTER_ROOT/.pub-cache
# ... <- The workflow part described before should be here
์ด์ ์คํฌ๋ฆฝํธ์์ "flutter_build_play_store_release"์คํฌ๋ฆฝํธ๋ ๋ฒ์ ๊ด๋ฆฌ๋ฅผ ์ฒ๋ฆฌํฉ๋๋ค.
๋ฒ์ ์ ํ๊ทธ์์ ๊ฒ์๋ฉ๋๋ค.
๋น๋ ๋ฒํธ๋ ํ๋ ์ด ์ฝ์์์ ๊ฒ์๋ฉ๋๋ค(๊ฐ์ฅ ๋์ ๋น๋ ๋ฒํธ๋ฅผ ๊ฐ์ ธ์ค๊ณ ์ด๋ฒ ๋ฆด๋ฆฌ์ค์์๋ ์ฆ๊ฐ).
com.company.example์ ์ฑ ํจํค์ง ์ด๋ฆ์ผ๋ก ๋ฐ๊พธ๋ ๊ฒ์ ์์ง ๋ง์ธ์.
์ด์ ์ด ์คํฌ๋ฆฝํธ๋ฅผ ๋ฆฌํฌ์งํ ๋ฆฌ์ ํธ์ํ ์ ์์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ Codemagic์์ ๋ณผ ์ ์์ด์ผ ํ๋ฉฐ ์๋์ผ๋ก ํธ๋ฆฌ๊ฑฐํ ์ ์์ด์ผ ํฉ๋๋ค.
2๋จ๊ณ: git ํ๊ทธ ์ถ๊ฐ ๐ -> ํธ์ ๐
Creating a git tag is very easy. We will use 1.0.0 as our version, and tag.
You just have to run the following commands :
git tag -a 1.0.0 -m "Release 1.0.0"
git push origin 1.0.0
That's it! You should see a build running in Codemagic ๐โโ๏ธ
๋ฌด์ ํฅํ ๊ณํ?
Codemagic์ ์ฌ์ฉํ์ฌ ์ํ๋ ๋งํผ ์ํฌํ๋ก์ฐ๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค! GUI ํธ์ง๊ธฐ๋ฅผ ์ฌ์ฉํ ๋ค์ ์ฝ๋๋ฅผ ์ถ์ถํ์ฌ ์ฝ๋๋ฅผ ๋ ์ ์ ์ดํ ์ ์์ต๋๋ค.
์ฌ๊ธฐ์ ์ฐ๋ฆฌ๋ ์ํ์ ๋ฐฐํฌํ๋ฏ๋ก ์ค๋น๊ฐ ๋์๋ค๊ณ ๋๋ผ๋ฉด ํ๋ก๋์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ ๊ฑฐ์ ๋์ผํ ์ฝ๋๋ก iOS ์ํฌํ๋ก๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค.
์ด ํํ ๋ฆฌ์ผ์ ์๋ฃํ๋ค๋ฉด ๋๊ธ, ์ข์์ ๋๋ ์ ๋์ฝ ๐ฆ์ ๋จ๊ฒจ์ฃผ์ธ์! ๐๐
Reference
์ด ๋ฌธ์ ์ ๊ดํ์ฌ(๐ 5๋ถ ์์ Git ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ Flutter CI/CD), ์ฐ๋ฆฌ๋ ์ด๊ณณ์์ ๋ ๋ง์ ์๋ฃ๋ฅผ ๋ฐ๊ฒฌํ๊ณ ๋งํฌ๋ฅผ ํด๋ฆญํ์ฌ ๋ณด์๋ค https://dev.to/monisnap/flutter-ci-cd-using-git-tags-in-5-minutes-5bb1ํ ์คํธ๋ฅผ ์์ ๋กญ๊ฒ ๊ณต์ ํ๊ฑฐ๋ ๋ณต์ฌํ ์ ์์ต๋๋ค.ํ์ง๋ง ์ด ๋ฌธ์์ URL์ ์ฐธ์กฐ URL๋ก ๋จ๊ฒจ ๋์ญ์์ค.
์ฐ์ํ ๊ฐ๋ฐ์ ์ฝํ ์ธ ๋ฐ๊ฒฌ์ ์ ๋ (Collection and Share based on the CC Protocol.)
์ข์ ์นํ์ด์ง ์ฆ๊ฒจ์ฐพ๊ธฐ
๊ฐ๋ฐ์ ์ฐ์ ์ฌ์ดํธ ์์ง
๊ฐ๋ฐ์๊ฐ ์์์ผ ํ ํ์ ์ฌ์ดํธ 100์ ์ถ์ฒ ์ฐ๋ฆฌ๋ ๋น์ ์ ์ํด 100๊ฐ์ ์์ฃผ ์ฌ์ฉํ๋ ๊ฐ๋ฐ์ ํ์ต ์ฌ์ดํธ๋ฅผ ์ ๋ฆฌํ์ต๋๋ค