Flutter Build #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Flutter Build | |
on: workflow_dispatch | |
permissions: write-all | |
env: | |
flutter_version: '3.19.2' | |
jobs: | |
build_android: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout the code | |
uses: actions/checkout@v4 | |
- name: Clear old cache - Cache APK | |
id: clear-cache-apk | |
uses: actions/cache@v4 | |
with: | |
path: | | |
build/app/outputs/flutter-apk/ | |
key: build-apk | |
enableCrossOsArchive: true | |
restore-keys: | | |
build-apk | |
- name: Clear old cache - Delete cache builds | |
if: steps.clear-cache-apk.outputs.cache-hit == 'true' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh cache delete build-apk | |
- name: Change version info | |
run: | | |
python3 ./build-tools/addBuildNumber.py | |
- name: Install JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Install and set Flutter version | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: ${{ env.flutter_version }} | |
channel: stable | |
cache: true | |
- name: Restore packages | |
run: | | |
flutter pub get | |
- name: Build APK | |
run: | | |
flutter build apk | |
- name: Sign APK | |
uses: r0adkll/sign-android-release@v1 | |
with: | |
releaseDirectory: build/app/outputs/flutter-apk | |
signingKeyBase64: ${{ secrets.APK_SIGN_JKS_BASE64 }} | |
alias: ${{ secrets.APK_SIGN_ALIAS }} | |
keyStorePassword: ${{ secrets.APK_SIGN_PASS }} | |
keyPassword: ${{ secrets.APK_SIGN_ALIAS_PASS }} | |
- name: Rename APK file | |
run: | | |
mkdir -p build/app/outputs/flutter-apk/publish/ | |
mv build/app/outputs/flutter-apk/app-release-signed.apk build/app/outputs/flutter-apk/publish/1-SITLife-release-signed.apk | |
touch build/app/outputs/flutter-apk/publish/.release | |
- name: Cache APK | |
id: cache-apk | |
uses: actions/cache@v4 | |
with: | |
path: | | |
build/app/outputs/flutter-apk/ | |
key: build-apk | |
enableCrossOsArchive: true | |
restore-keys: | | |
build-apk | |
- name: Publish Android Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: SITLife-Android-release | |
path: build/app/outputs/flutter-apk/1-SITLife-release-signed.apk | |
build_ios: | |
runs-on: macos-latest | |
steps: | |
- name: Checkout the code | |
uses: actions/checkout@v4 | |
- name: Clear old cache - Cache IPA | |
id: clear-cache-ipa | |
uses: actions/cache@v4 | |
with: | |
path: | | |
build-output/ios/ | |
key: build-ipa | |
enableCrossOsArchive: true | |
restore-keys: | | |
build-ipa | |
- name: Clear old cache - Delete cache builds | |
if: steps.clear-cache-ipa.outputs.cache-hit == 'true' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh cache delete build-ipa | |
- name: Change version info | |
run: | | |
python3 ./build-tools/addBuildNumber.py | |
- name: Change Develop to Distribution | |
run: | | |
python3 ./build-tools/toDistribution.py | |
- name: Install Apple Certificate | |
uses: apple-actions/import-codesign-certs@v2 | |
with: | |
p12-file-base64: ${{ secrets.P12_BASE64 }} | |
p12-password: ${{ secrets.P12_PASSWORD }} | |
- name: Install the provisioning profile | |
env: | |
PROVISIONING_CERTIFICATE_BASE64: ${{ secrets.PROVISIONING_PROFILE_BASE64 }} | |
run: | | |
PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision | |
echo -n "$PROVISIONING_CERTIFICATE_BASE64" | base64 --decode --output $PP_PATH | |
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles | |
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles | |
- name: Install and set Flutter version | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: ${{ env.flutter_version }} | |
channel: stable | |
cache: true | |
- name: Restore packages | |
run: | | |
flutter pub get | |
- name: Build iOS | |
run: | | |
flutter build ios --release --no-codesign | |
- name: Build resolve Swift dependencies | |
run: | | |
xcodebuild -resolvePackageDependencies -workspace ios/Runner.xcworkspace -scheme Runner -configuration Release | |
- name: Build xArchive | |
run: | | |
xcodebuild -workspace ios/Runner.xcworkspace -scheme Runner -configuration Release DEVELOPMENT_TEAM="M5APZD5CKA" -sdk 'iphoneos' -destination 'generic/platform=iOS' -archivePath build-output/app.xcarchive PROVISIONING_PROFILE="eb8b1f5f-3329-42a5-a18f-8254a2e85b41" clean archive CODE_SIGN_IDENTITY="Apple Distribution: ziqi wei" | |
- name: Export ipa | |
run: | | |
xcodebuild -exportArchive -archivePath build-output/app.xcarchive -exportPath build-output/ios -exportOptionsPlist ios/ExportOptions.plist | |
- name: Rename ipa file | |
run: | | |
mkdir -p build-output/ios/publish/ | |
mv build-output/ios/life.mysit.SITLife.ipa build-output/ios/publish/2-SITLife-release.ipa | |
# Debug only | |
# - name: (Debug) Publish ipa file | |
# run: | | |
# touch build-output/ios/publish/.release | |
# - name: (Debug) Cache ipa | |
# id: cache-ipa | |
# uses: actions/cache@v4 | |
# with: | |
# path: | | |
# build-output/ios/ | |
# key: build-ipa | |
# enableCrossOsArchive: true | |
# restore-keys: | | |
# build-ipa | |
# - name: (Debug) Publish iOS Artifact | |
# uses: actions/upload-artifact@v4 | |
# with: | |
# name: SITLife-iOS-release | |
# path: build-output/ios/publish/2-SITLife-release.ipa | |
# Release | |
- name: Deploy to App Store (Testflight) | |
uses: apple-actions/upload-testflight-build@v1 | |
with: | |
app-path: ${{ github.workspace }}/build-output/ios/publish/2-SITLife-release.ipa | |
issuer-id: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }} | |
api-key-id: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }} | |
api-private-key: ${{ secrets.APP_STORE_CONNECT_API_PRIVATE_KEY }} | |
after_build: | |
runs-on: ubuntu-latest | |
needs: [build_android, build_ios] | |
steps: | |
- name: Checkout the code | |
uses: actions/checkout@v4 | |
- name: Change version info | |
id: get_tag_name | |
run: | | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git config --global user.name "github-actions[bot]" | |
python3 ./build-tools/addBuildNumber.py ${{ github.server_url }} ${{ github.repository }} ${{ github.run_id }} ${{ github.run_attempt }} | |
- name: Get Git info | |
id: get_git_info | |
run: | | |
git fetch --tags | |
echo "RESOLVED_VERSION="$(git tag --sort=-v:refname | head -n 1) >> "$GITHUB_OUTPUT" | |
echo "PREVIOUS_TAG="$(git tag --sort=-v:refname | head -n 2 | tail -n 1) >> "$GITHUB_OUTPUT" | |
- name: Restore cache builds (apk) | |
id: cache-apk | |
uses: actions/cache@v4 | |
with: | |
path: | | |
build/app/outputs/flutter-apk/ | |
key: build-apk | |
enableCrossOsArchive: true | |
- name: Restore cache builds (ipa) | |
id: cache-ipa | |
uses: actions/cache@v4 | |
with: | |
path: | | |
build-output/ios/ | |
key: build-ipa | |
enableCrossOsArchive: true | |
- name: Check builds | |
id: builds | |
env: | |
RESOLVED_VERSION: ${{ steps.get_git_info.outputs.RESOLVED_VERSION }} | |
run: | | |
if [ -f "build/app/outputs/flutter-apk/publish/1-SITLife-release-signed.apk" ]; then | |
mv build/app/outputs/flutter-apk/publish/1-SITLife-release-signed.apk build/app/outputs/flutter-apk/publish/SITLife-${{ env.RESOLVED_VERSION }}.apk | |
fi | |
if [ -f "build-output/ios/publish/2-SITLife-release.ipa" ]; then | |
mv build-output/ios/publish/2-SITLife-release.ipa build-output/ios/publish/SITLife-${{ env.RESOLVED_VERSION }}.ipa | |
fi | |
if [ ! -f "build/app/outputs/flutter-apk/publish/.release" ]; then | |
rm -rf build/app/outputs/flutter-apk/publish/SITLife-${{ env.RESOLVED_VERSION }}.apk | |
echo "APK_SHA256=" >> "$GITHUB_OUTPUT" | |
else | |
echo "APK_SHA256=- \`SITLife-${{ env.RESOLVED_VERSION }}.apk\`: "$(sha256sum build/app/outputs/flutter-apk/publish/SITLife-${{ env.RESOLVED_VERSION }}.apk | awk '{print $1}') >> "$GITHUB_OUTPUT" | |
fi | |
if [ ! -f "build-output/ios/publish/.release" ]; then | |
rm -rf build-output/ios/publish/SITLife-${{ env.RESOLVED_VERSION }}.ipa | |
echo "IPA_SHA256=" >> "$GITHUB_OUTPUT" | |
else | |
echo "IPA_SHA256=- \`SITLife-${{ env.RESOLVED_VERSION }}.ipa\`: "$(sha256sum build-output/ios/publish/SITLife-${{ env.RESOLVED_VERSION }}.ipa | awk '{print $1}') >> "$GITHUB_OUTPUT" | |
fi | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
branch: ${{ github.ref }} | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
env: | |
RESOLVED_VERSION: ${{ steps.get_git_info.outputs.RESOLVED_VERSION }} | |
PREVIOUS_TAG: ${{ steps.get_git_info.outputs.PREVIOUS_TAG }} | |
with: | |
files: | | |
build/app/outputs/flutter-apk/publish/SITLife-${{ env.RESOLVED_VERSION }}.apk | |
build-output/ios/publish/SITLife-${{ env.RESOLVED_VERSION }}.ipa | |
tag_name: ${{ env.RESOLVED_VERSION }} | |
body: | | |
## Changes | |
### Features | |
- Foo | |
### Bug fixes | |
- Bar | |
## 更改 | |
### 新功能 | |
- Foo | |
### Bug 修复 | |
- Bar | |
## How to download | |
<!-- Android:main --> | |
<!-- - `Android`: Click the .apk files below.--> | |
<!-- iOS:main --> | |
<!-- - `iOS`: [Download on the App Store](https://apps.apple.com/cn/app/id6468989112).--> | |
<!-- iOS:TestFlight --> | |
<!-- - `iOS`: [Join the Test Flight](https://testflight.apple.com/join/ecafeulK).--> | |
<!-- iOS:Debug --> | |
<!-- - `iOS`: Click the .ipa files below.--> | |
- `Android`: Click the .apk files below. | |
- `iOS`: [Join the Test Flight](https://testflight.apple.com/join/ecafeulK). | |
## Checksum (sha256) | |
${{ steps.builds.outputs.APK_SHA256 }} | |
${{ steps.builds.outputs.IPA_SHA256 }} | |
Full Changelog: https://github.com/${{ github.repository }}/compare/${{ env.PREVIOUS_TAG }}...${{ env.RESOLVED_VERSION }} | |
draft: true | |
prerelease: false | |
- name: Delete cache builds (apk) | |
if: steps.cache-apk.outputs.cache-hit == 'true' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh cache delete build-apk | |
- name: Delete cache builds (ipa) | |
if: steps.cache-ipa.outputs.cache-hit == 'true' | |
env: | |
GH_TOKEN: ${{ github.token }} | |
run: | | |
gh cache delete build-ipa |