update build gradle #63
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: Gonpa Tour CICD | |
on: | |
push: | |
branches: ["main"] | |
# pull_request: | |
# branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Needed for version generation | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
cache: gradle | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: "3.24.4" | |
channel: "stable" | |
cache: true | |
- name: Check Flutter version | |
run: flutter --version | |
- name: Get dependencies | |
run: flutter pub get | |
- name: Generate version number | |
id: version | |
run: | | |
# Get the latest tag | |
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` 2>/dev/null || echo "v0.0.0") | |
# Extract version numbers | |
MAJOR=$(echo $LATEST_TAG | cut -d. -f1 | tr -d 'v') | |
MINOR=$(echo $LATEST_TAG | cut -d. -f2) | |
PATCH=$(echo $LATEST_TAG | cut -d. -f3) | |
# Increment patch version | |
NEW_PATCH=$((PATCH + 1)) | |
NEW_VERSION="v$MAJOR.$MINOR.$NEW_PATCH" | |
# Set output | |
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT | |
- name: Build APK | |
run: flutter build apk --debug | |
- name: Get PR message | |
if: github.event_name == 'pull_request' | |
id: pr_message | |
run: echo "pr_message=$(jq -r .pull_request.body < $GITHUB_EVENT_PATH)" >> $GITHUB_ENV | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.version.outputs.new_version }} | |
release_name: Release ${{ steps.version.outputs.new_version }} | |
body: ${{ env.pr_message || 'No changelog provided.' }} | |
draft: false | |
prerelease: false | |
- name: Upload Release APK | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: build/app/outputs/flutter-apk/app-debug.apk | |
asset_name: app-debug.apk | |
asset_content_type: application/vnd.android.package-archive | |
# Optional: Upload artifact for debugging | |
- name: Upload APK Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-apk | |
path: build/app/outputs/flutter-apk/app-debug.apk | |
retention-days: 5 | |
ios-build: | |
runs-on: macos-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # Needed for version generation | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: "17" | |
distribution: "temurin" | |
cache: gradle | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: "3.24.4" | |
channel: "stable" | |
cache: true | |
- name: Check Flutter version | |
run: flutter --version | |
- name: Get dependencies | |
run: flutter pub get | |
- name: Build iOS | |
run: flutter build ios --no-codesign | |
- name: Upload iOS Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: release-ios | |
path: build/ios/ipa | |
retention-days: 5 |