Skip to content

Instantly share code, notes, and snippets.

@damiancipolat
Last active August 5, 2020 01:38
Show Gist options
  • Save damiancipolat/97b965157b6bb7a6e240aa19a8eb5b3d to your computer and use it in GitHub Desktop.
Save damiancipolat/97b965157b6bb7a6e240aa19a8eb5b3d to your computer and use it in GitHub Desktop.
An example of create a flutte CICD using gitlabCI
stages:
- test
- build
- deploy
- notify
run_test:
stage: test
image: cirrusci/flutter:stable
script:
- flutter pub get
- echo "Running unit test..."
- flutter test
build_android:
stage: build
image: cirrusci/flutter:stable
only:
- develop
- staging
- master
- merge_requests
script:
- echo "Processing branch $CI_COMMIT_REF_NAME"
- echo "Extracting project version..."
- source deploy/yaml.sh
- create_variables pubspec.yaml
- export PKG_VERSION= $version #Extract from pubspect.yaml
- echo "Version $PKG_VERSION"
- echo $PKG_VERSION >> .version #Save the project version to be used in the next job
- echo "Installing npm modules.."
- flutter pub get
- echo "Buildindg APK..." -
- if [ $CI_COMMIT_REF_NAME == "master" ]; then flutter build apk --release; else flutter build apk; fi #Build debug or release version
artifacts:
paths:
- .version
- android/app/build/outputs/apk/
deploy_android:
stage: deploy
only:
- develop
- staging
- master
- merge_requests
image:
name: amazon/aws-cli
entrypoint: [""]
script:
- echo "Reading project version..."
- export PKG_VERSION=$(cat .version) #Get version from the artifact file.
- echo "Uploading to S3..."
- aws configure set region us-east-1 #Configure region and upload to s3, depending the branch.
- if [ $CI_COMMIT_REF_NAME == "master" ]; then
aws s3 cp android/app/build/outputs/apk/release/app-release.apk s3://jupitec-mobile-repository/android/${CI_COMMIT_REF_NAME}/${PKG_VERSION}/flutter/app.apk;
else
aws s3 cp android/app/build/outputs/apk/debug/app-debug.apk s3://jupitec-mobile-repository/android/${CI_COMMIT_REF_NAME}/${PKG_VERSION}/flutter/app.apk;
fi
- echo "Get download signed URL"
- export SIGNED_URL=$(aws s3 presign s3://jupitec-mobile-repository/android/${CI_COMMIT_REF_NAME}/${PKG_VERSION}/flutter/app.apk --expires-in 300000)
- echo $SIGNED_URL
- echo $SIGNED_URL > .url #Save the signed url in a file to use in the next job.
artifacts:
paths:
- .url
notify_android:
stage: notify
only:
- develop
- staging
- master
- merge_requests
image:
name: curlimages/curl
entrypoint: [""]
script:
- echo "Reading download url..."
- export DOWNLOAD_URL=$(cat .url) #Get download url from file.
- export PKG_VERSION=$(cat .version) #Get version url from file.
- echo "Sending to slack..."
- export MESSAGE="New Flutter APK release available :+1:! - ENV $CI_COMMIT_REF_NAME - version $PKG_VERSION - dowload link $DOWNLOAD_URL"
- |
curl -X POST "https://hooks.slack.com/services/xxxx/xxxx/xxxxx" \
--header "Content-Type: application/json" \
--data "{\"text\": \"${MESSAGE}\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment