Update build_and_release.yml #27
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: Flutter Build and Release | |
on: | |
push: | |
branches: [ main, dev ] | |
pull_request: | |
branches: [ main, dev ] | |
jobs: | |
version-bump: | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' | |
outputs: | |
new_version: ${{ steps.bump_version.outputs.new_version }} | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Get latest tag | |
id: get_latest_tag | |
run: echo "latest_tag=$(git describe --tags --abbrev=0 || echo v0.0.0)" >> $GITHUB_OUTPUT | |
- name: Bump version | |
id: bump_version | |
run: | | |
latest_tag=${{ steps.get_latest_tag.outputs.latest_tag }} | |
major=$(echo $latest_tag | cut -d. -f1 | tr -d v) | |
minor=$(echo $latest_tag | cut -d. -f2) | |
patch=$(echo $latest_tag | cut -d. -f3) | |
new_patch=$((patch + 1)) | |
new_version="$major.$minor.$new_patch" | |
echo "new_version=$new_version" >> $GITHUB_OUTPUT | |
- name: Update pubspec.yaml | |
run: | | |
sed -i 's/^version: .*/version: ${{ steps.bump_version.outputs.new_version }}+${{ github.run_number }}/g' pubspec.yaml | |
- name: Commit changes | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "TheGuyDangerous" | |
git add pubspec.yaml | |
git commit -m "Bump version to ${{ steps.bump_version.outputs.new_version }}+${{ github.run_number }}" | |
- name: Push changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.ref }} | |
build_and_release: | |
needs: version-bump | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev' | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: '17' | |
- name: Setup Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
flutter-version: '3.24.3' | |
channel: 'stable' | |
- name: Cache Gradle packages | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: Cache Pub dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ${{ env.FLUTTER_HOME }}/.pub-cache | |
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }} | |
restore-keys: | | |
${{ runner.os }}-pub- | |
- name: Get dependencies | |
run: flutter pub get | |
- name: Build APK | |
run: flutter build apk --release --split-per-abi | |
- name: Create Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
tag_name: v${{ needs.version-bump.outputs.new_version }} | |
release_name: Release v${{ needs.version-bump.outputs.new_version }} | |
draft: false | |
prerelease: ${{ github.ref == 'refs/heads/dev' }} | |
- name: Upload armeabi-v7a APK | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk | |
asset_name: freelexity-v${{ needs.version-bump.outputs.new_version }}-armeabi-v7a.apk | |
asset_content_type: application/vnd.android.package-archive | |
- name: Upload arm64-v8a APK | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./build/app/outputs/flutter-apk/app-arm64-v8a-release.apk | |
asset_name: Freelexity-v${{ needs.version-bump.outputs.new_version }}-arm64-v8a.apk | |
asset_content_type: application/vnd.android.package-archive | |
- name: Upload x86_64 APK | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./build/app/outputs/flutter-apk/app-x86_64-release.apk | |
asset_name: freelexity-v${{ needs.version-bump.outputs.new_version }}-x86_64.apk | |
asset_content_type: application/vnd.android.package-archive |