Build & Release Flutter Android App #13
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: "Build & Release Flutter APP" | |
# Define when to trigger the workflow (on each push to the main branch) | |
## Whatever push changes occurs to main branch, this workflow will trigger. | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
flutterBuildRelease: | |
runs-on: ubuntu-latest | |
env: | |
GIT_ORG: Ramiiyan | |
REPOSITORY: agri_io_app | |
TARGET_PATH: build/app/outputs/flutter-apk | |
TARGET_FILE_TYPE: apk | |
steps: | |
# Checkout to current | |
- name: Checkout | |
uses: actions/checkout@v4 | |
# Use the setup-java action to configure the Java environment | |
- name: 'Set up JDK 17' | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
cache: 'gradle' | |
# Setup Flutter in the VM | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: 3.19.6 | |
cache: true | |
# Run flutter commands | |
- name: Run flutter pub get | |
run: flutter pub get | |
- name: 📦 Install dependencies | |
run: flutter pub get | |
# - name: 🕵️ Analyze to check for bad Dart/Flutter practices | |
# run: flutter analyze | |
# - run: flutter format --set-exit-if-changed . | |
# - run: flutter analyze . | |
# Build Android APK release file | |
- name: Build Android APK | |
run: flutter build apk --split-per-abi | |
- name: Release GitHub Artifacts | |
id: release_github_artifacts | |
run: | | |
echo "${{secrets.GIT_ACTION_PAT}}" | gh auth login --with-token # GitHub cli login with PAT | |
current_tag_name=$(gh release view --repo ${{ env.GIT_ORG }}/${{ env.REPOSITORY }} --json tagName --jq '.tagName' || true) | |
if [ -z $current_tag_name ]; then | |
echo "No Release found." | |
gh release create v0.1 --title "${{ env.REPOSITORY }} - v0.1" --notes "Release notes for version v0.1" | |
echo "New Github Release Published. Tag Version:v0.1" | |
updated_tag=0.1 | |
else | |
echo "current latest tag name: $current_tag_name" | |
output=$(echo $current_tag_name | grep -oP '\d+\.\d+') | |
echo "OUTPUT: $output" | |
tag_version=$(echo $current_tag_name | grep -oP '\d+\.\d+') | |
IFS="." read -ra ver_compo <<< "$tag_version" | |
# Extract major and minor versions | |
major_v="${ver_compo[0]}" | |
minor_v="${ver_compo[1]}" | |
# Increase the minor version by 1 | |
minor_v=$(($minor_v + 1)) | |
echo $minor_v | |
# New GitHub Release tag | |
new_github_tag_name="$major_v.$minor_v" | |
echo "Release Tag: $new_github_tag_name" | |
# Release the Pack | |
gh release create $new_github_tag_name --title "${{ env.REPOSITORY }} - $new_github_tag_name" --notes "Release notes for version $new_github_tag_name" | |
updated_tag=$new_github_tag_name | |
fi | |
echo "updated_tag: $updated_tag" | |
gh release upload $updated_tag ${{ env.TARGET_PATH }}/*.${{ env.TARGET_FILE_TYPE }} --repo ${{ env.GIT_ORG }}/${{ env.REPOSITORY }} | |
echo "Artifacts uploaded to GitHub release." | |
echo "NEW_TAG_VERSION=$updated_tag" |