Skip to content

Trying stackoverflow answer #6

Trying stackoverflow answer

Trying stackoverflow answer #6

Workflow file for this run

name: Build and Release
on:
push:
branches:
- "gh-actions"
pull_request:
branches:
- "main"
paths:
- ".github/workflows/release.yaml"
jobs:
extract_version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Extract version from pubspec.yaml
id: extract_version
run: |
# Extract version string from pubspec.yaml
VERSION=$(grep '^version:' pubspec.yaml | sed 's/version: //')
echo "Pubspec.yml version: $VERSION"
# Split VERSION into version name and build number
BUILD_NAME=$(echo $VERSION | cut -d "+" -f 1)
BUILD_NUMBER=$(echo $VERSION | cut -d "+" -f 2)
echo "Build-Name: $BUILD_NAME"
echo "Build-Number: $BUILD_NUMBER"
# Set the extracted values as environment variables
echo "BUILD_NAME=$BUILD_NAME" >> $GITHUB_ENV
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
build_android:
runs-on: ubuntu-latest
needs: extract_version
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.16.9' # Specify the Flutter version explicitly
- name: Decode keystore
run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > release-keystore.jks
- name: Set up JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build Android APK
run: |
flutter build apk --release --no-tree-shake-icons \
--build-name=${{ env.BUILD_NAME }} \
--build-number=${{ env.BUILD_NUMBER }}
- name: Build Android App Bundle
run: |
flutter build appbundle --release --no-tree-shake-icons \
--build-name=${{ env.BUILD_NAME }} \
--build-number=${{ env.BUILD_NUMBER }}
- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: app-release.apk
path: build/app/outputs/flutter-apk/app-release.apk
- name: Upload AAB
uses: actions/upload-artifact@v3
with:
name: app-release.aab
path: build/app/outputs/bundle/release/app-release.aab
build_ios:
runs-on: macos-latest
needs: build_android
steps:
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
flutter-version: '3.16.9' # Specify the Flutter version explicitly
- name: Set up CocoaPods
run: pod install --project-directory=ios/
- name: Decode certificates and profiles
run: |
echo "${{ secrets.IOS_CERTIFICATE }}" | base64 --decode > ios_certificate.p12
echo "${{ secrets.IOS_PROFILE }}" | base64 --decode > ios_profile.mobileprovision
- name: Install Fastlane
run: gem install fastlane
- name: Build iOS App
env:
APP_STORE_CONNECT_KEY_ID: ${{ secrets.APP_STORE_CONNECT_KEY_ID }}
APP_STORE_CONNECT_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_ISSUER_ID }}
APP_STORE_CONNECT_PRIVATE_KEY: ${{ secrets.APP_STORE_CONNECT_PRIVATE_KEY }}
IOS_CERTIFICATE_PASSWORD: ${{ secrets.IOS_CERTIFICATE_PASSWORD }}
run: |
fastlane run unlock_keychain
flutter build ipa --release --no-tree-shake-icons \
--build-name=${{ env.BUILD_NAME }} \
--build-number=${{ env.BUILD_NUMBER }}
- name: Upload IPA
uses: actions/upload-artifact@v3
with:
name: app-release.ipa
path: build/ios/ipa/*.ipa