Skip to content

Merge pull request #881 from YumNumm/chore/pub-workspace-melos #10

Merge pull request #881 from YumNumm/chore/pub-workspace-melos

Merge pull request #881 from YumNumm/chore/pub-workspace-melos #10

Workflow file for this run

name: Deploy
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
on:
push:
branches:
- main
- develop
- chore/env # TODO(YumNumm): デバッグ用なので後で消す
workflow_dispatch:
inputs:
ios:
description: "Build iOS app"
required: false
default: true
type: boolean
android:
description: "Build Android app"
required: false
default: true
type: boolean
jobs:
define-matrix:
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
deploy-ios: ${{ steps.define-environment-matrix.outputs.deploy-ios }}
deploy-android: ${{ steps.define-environment-matrix.outputs.deploy-android }}
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Decide which app to deploy
id: define-environment-matrix
run: |
platforms=()
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
if [ "${{ inputs.ios }}" = "true" ]; then
platforms+=("ios")
fi
if [ "${{ inputs.android }}" = "true" ]; then
platforms+=("android")
fi
elif [ "${{ github.event_name }}" = "push" ]; then
# コミットメッセージに [release only $platform] を含む場合は、
# そのプラットフォームのみデプロイする
if [[ github.event.head_commit.message =~ \[release[[:space:]]+only[[:space:]]+([a-z,[:space:]]+)\] ]]; then
# [release only platform1,platform2] の形式からプラットフォームを抽出
IFS=',' read -ra selected_platforms <<< "${BASH_REMATCH[1]}"
# 空白を削除して配列に追加
for platform in "${selected_platforms[@]}"; do
platform=$(echo "$platform" | tr -d '[:space:]')
if [[ " ios android" =~ " $platform " ]]; then
platforms+=("$platform")
fi
echo "platform: $platform"
done
else
# [release only] タグがない場合は全プラットフォームをデプロイ
echo "commit message does not contain [release only platform], deploy all platforms"
platforms+=("ios" "android")
fi
else
echo "Unknown event name: ${{ github.event_name }}"
exit 1
fi
echo "デプロイするプラットフォーム: ${platforms[@]}"
for platform in "${platforms[@]}"; do
echo "deploy-${platform}=true" >> $GITHUB_OUTPUT
done
build-ios:
needs: define-matrix
if: ${{ needs.define-matrix.outputs.deploy-ios }}
runs-on: macos-latest
timeout-minutes: 15
steps:
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Setup application runtime & Resolve dependencies
uses: ./.github/actions/setup-application-runtime
- name: Setup macOS Environment
uses: ./.github/actions/setup-macos-environment
- name: Create App Store Connect API Token
uses: ./.github/actions/generate-app-store-connect-jwt
with:
app_store_connect_api_key_id: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}
app_store_connect_api_key_base64: ${{ secrets.APP_STORE_CONNECT_API_KEY_BASE64 }}
- name: Fetch latest build number
id: fetch-latest-build-number
run: |
platform=IOS
app_id=6447546703
build_number=$(
curl -s https://api.appstoreconnect.apple.com/v1/builds \
-G \
-d "filter[platform]=${platform}" \
-d "filter[id]=${app_id}" \
-d "sort=-version" \
-d "fields[builds]=version" \
-d "limit=1" | \
jq -r '.data | if length == 0 then 0 else .[0].attributes.version end'
)
build_number=$((build_number + 1))
echo "build_number=${build_number}" >> $GITHUB_OUTPUT
echo "Build Number set to ${build_number}."
- name: Extract Dotenv
run: |
echo "${{ secrets.DOTENV }}" | base64 -d > environment.tar.gz
tar -xzf environment.tar.gz
rm environment.tar.gz
ls -l environment/
- name: Build iOS
working-directory: app
env:
BUILD_NUMBER: ${{ steps.fetch-latest-build-number.outputs.build_number }}
run: |
echo "BUILD_NUMBER=${BUILD_NUMBER}"
flutter build ipa \
--no-codesign \
--build-number=${BUILD_NUMBER} \
--dart-define-from-file=../environment/.env.prod
- name: Extract App Store Connect API Key
working-directory: app/ios
run: echo "${{ secrets.APP_STORE_CONNECT_API_KEY_BASE64 }}" | base64 -d > AuthKey.p8
- name: Archive
working-directory: app
run: |
xcodebuild -workspace ios/Runner.xcworkspace \
-scheme Runner \
-sdk iphoneos \
-configuration Release archive \
-archivePath build/ios/Runner.xcarchive \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO | xcbeautify
xcodebuild -exportArchive \
-archivePath build/ios/Runner.xcarchive \
-exportOptionsPlist ios/ExportOptions.plist \
-exportPath . \
-allowProvisioningUpdates \
-authenticationKeyIssuerID ${{ secrets.APP_STORE_CONNECT_API_KEY_ISSUER_ID }} \
-authenticationKeyID ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }} \
-authenticationKeyPath ${{ github.workspace }}/app/ios/AuthKey.p8 | xcbeautify
- name: Upload ipa as artifact
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: EQMonitor-ios.ipa
path: app/eqdashboard.ipa
deploy-ios:
needs: build-ios
name: Deploy iOS
runs-on: macos-latest
timeout-minutes: 10
steps:
# https://github.com/actions/checkout
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
# https://github.com/actions/download-artifact
- name: Download ipa
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
name: EQDashboard-ios.ipa
path: build
- name: List files
run: ls -lah build/
- name: Setup macOS Environment
uses: ./.github/actions/setup-macos-environment
- name: Extract App Store Connect API Key
run: |
mkdir ~/.private_keys
echo "${{ secrets.APP_STORE_CONNECT_API_KEY_BASE64 }}" | base64 -d \
> ~/.private_keys/AuthKey_${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}.p8
ls -l ~/.private_keys/AuthKey_${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}.p8
- name: Upload Ipa to App Store Connect
run: |
xcrun altool \
--upload-app \
-f build/eqdashboard.ipa \
--type ios \
--apiIssuer ${{ secrets.APP_STORE_CONNECT_API_KEY_ISSUER_ID }} \
--apiKey ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}
build-android:
needs: define-matrix
if: ${{ needs.define-matrix.outputs.deploy-android }}
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Setup application runtime & Resolve dependencies
uses: ./.github/actions/setup-application-runtime
- name: Extract Dotenv
run: |
echo "${{ secrets.DOTENV }}" | base64 -d > environment.tar.gz
tar -xzf environment.tar.gz
rm environment.tar.gz
ls -l environment/
- name: Build Android
working-directory: app
run: flutter build appbundle \
--release \
--dart-define-from-file=../environment/.env.prod
- name: Upload apk as artifact
uses: actions/upload-artifact@6f51ac03b9356f520e9adb1b1b7802705f340c2b # v4.5.0
with:
name: EQMonitor-android.apk
path: build/app/outputs/flutter-apk/app-release.apk