Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AristideVB/147f9724e2b1fb420c74d7bc60aa1249 to your computer and use it in GitHub Desktop.
Save AristideVB/147f9724e2b1fb420c74d7bc60aa1249 to your computer and use it in GitHub Desktop.
Example of CI/CD for Flutter
name: Flutter publish release
on:
push:
tags:
- android-v[0-9]+.[0-9]+.[0-9]+
- ios-v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+
jobs:
lint-and-test:
name: Static code analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
- run: flutter pub get
- name: Lint analysis
run: flutter analyze
- name: Run tests
run: flutter test
parse-tag:
needs: lint-and-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- id: step1
name: Get BUILD_NAME BUILD_NUMBER and DEVICE
run: |
source .github/scripts/parse-tag.sh
echo "::set-output name=BUILD_NAME::$BUILD_NAME"
echo "::set-output name=BUILD_NUMBER::$BUILD_NUMBER"
echo "::set-output name=DEVICE::$DEVICE"
outputs:
BUILD_NAME: ${{ steps.step1.outputs.BUILD_NAME }}
BUILD_NUMBER: ${{ steps.step1.outputs.BUILD_NUMBER }}
DEVICE: ${{ steps.step1.outputs.DEVICE }}
deploy-android:
needs: parse-tag
if: contains(needs.parse-tag.outputs.DEVICE, 'android')
name: Build and Deploy Android
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-java@v1
with:
java-version: '12.x'
- uses: subosito/flutter-action@v1
- name: Build Android with prod flavor
run: |
BUILD_NAME=${{needs.parse-tag.outputs.BUILD_NAME}}
BUILD_NUMBER=${{needs.parse-tag.outputs.BUILD_NUMBER}}
flutter pub get
flutter build appbundle -t lib/main_prod.dart --flavor prod --build-name $BUILD_NAME --build-number $BUILD_NUMBER
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
files: |
build/app/outputs/bundle/prodRelease/app-prod-release.aab
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Deploy to Internal
uses: r0adkll/upload-google-play@v1
with:
serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
packageName: com.threebee.threebee_flutter
releaseFile: build/app/outputs/bundle/prodRelease/app-prod-release.aab
track: internal
whatsNewDirectory: release_notes/
mappingFile: build/app/outputs/mapping/prodRelease/mapping.txt
deploy-ios:
needs: parse-tag
if: contains(needs.parse-tag.outputs.DEVICE, 'ios')
name: Build and Deploy iOS
runs-on: macos-latest
steps:
- name: Update Xcode to latest stable version
uses: maxim-lobanov/setup-xcode@v1.1
with:
xcode-version: latest-stable
- name: Checkout project
uses: actions/checkout@v1
- name: Import signing certificate
env:
SIGNING_CERTIFICATE_P12_DATA: ${{ secrets.SIGNING_CERTIFICATE_P12_DATA }}
SIGNING_CERTIFICATE_PASSWORD: ${{ secrets.SIGNING_CERTIFICATE_PASSWORD }}
run: |
exec .github/scripts/import-certificate.sh
- name: Import provisioning profile
env:
PROVISIONING_PROFILE_DATA: ${{ secrets.PROVISIONING_PROFILE_DATA }}
run: |
exec .github/scripts/import-profile.sh
- uses: subosito/flutter-action@v1
- name: Build iOS with prod flavor
run: |
BUILD_NAME=${{needs.parse-tag.outputs.BUILD_NAME}}
BUILD_NUMBER=${{needs.parse-tag.outputs.BUILD_NUMBER}}
flutter pub get
flutter build ios -t lib/main_prod.dart --flavor prod --build-name $BUILD_NAME --build-number $BUILD_NUMBER
- name: Create ipa from app
run: |
xcodebuild archive -workspace ios/Runner.xcworkspace -scheme Prod -sdk iphoneos -configuration Release-Prod -archivePath build/ios/Runner.xcarchive
xcodebuild -exportArchive -archivePath build/ios/Runner.xcarchive -exportOptionsPlist ios/exportOptions.plist -exportPath build/ios/Runner.ipa
ls -al build/ios/Runner.ipa
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
files: |
build/ios/Runner.ipa/3Bee.ipa
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload app to App Store Connect
env:
APP_STORE_CONNECT_USERNAME: ${{ secrets.APP_STORE_CONNECT_USERNAME }}
APP_STORE_CONNECT_PASSWORD: ${{ secrets.APP_STORE_CONNECT_PASSWORD }}
run: xcrun altool --upload-app -t ios -f "build/ios/Runner.ipa/3Bee.ipa" -u "$APP_STORE_CONNECT_USERNAME" -p "$APP_STORE_CONNECT_PASSWORD"
#!/bin/bash
set -euo pipefail
security create-keychain -p "" build.keychain
security list-keychains -s build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p "" build.keychain
security set-keychain-settings
security import <(echo $SIGNING_CERTIFICATE_P12_DATA | base64 --decode) \
-f pkcs12 \
-k build.keychain \
-P $SIGNING_CERTIFICATE_PASSWORD \
-T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple: -s -k "" build.keychain
#!/bin/bash
set -euo pipefail
echo "$PROVISIONING_PROFILE_DATA" | base64 --decode > profile.mobileprovision
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
uuid=`grep UUID -A1 -a profile.mobileprovision | grep -io "[-A-F0-9]\{36\}"`
cp profile.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/$uuid.mobileprovision
echo "Provisioning profile UUID: $uuid"
#!/bin/bash
echo "GITHUB_REF: $GITHUB_REF"
tag=${GITHUB_REF##*/}
DEVICE=${tag%-v*}
BUILD_NAME=${tag#*v}
first=${BUILD_NAME%%.*}
tmp=${BUILD_NAME%.*}
second=${tmp#*.}
third=${BUILD_NAME##*.}
if [[ ${#first} -lt 2 ]] ; then
first="00${first}"
first="${first: -2}"
fi
if [[ ${#second} -lt 2 ]] ; then
second="00${second}"
second="${second: -2}"
fi
if [[ ${#third} -lt 2 ]] ; then
third="00${third}"
third="${third: -2}"
fi
BUILD_NUMBER=$first$second$third
BUILD_NUMBER=$(expr $BUILD_NUMBER + 0)
if [ "$DEVICE" != "android" ] && [ "$DEVICE" != "ios" ] ; then
DEVICE="android-ios"
fi
echo "BUILD_NAME: $BUILD_NAME"
echo "BUILD_NUMBER: $BUILD_NUMBER"
echo "DEVICE: $DEVICE"
#!/bin/bash
set -euo pipefail
mkdir Payload
cp -r build/ios/iphoneos/Runner.app Payload/
zip -r Payload.zip Payload
mv Payload.zip Payload.ipa
xcrun altool --upload-app -t ios -f "Payload.ipa" -u <INSERT_EMAIL> -p <INSERT_PASSWORD>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment