66 push :
77 branches :
88 - main
9+ workflow_dispatch :
910
1011jobs :
1112 build :
@@ -15,20 +16,70 @@ jobs:
1516 steps :
1617 - name : Checkout Repository
1718 uses : actions/checkout@v3
19+ with :
20+ fetch-depth : 2
21+ fetch-tags : true
22+
23+ - name : Check if version changed
24+ id : check_version_change
25+ run : |
26+ # Get current version
27+ CURRENT_VERSION=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
28+ echo "Current version: $CURRENT_VERSION"
29+
30+ # Get previous version (from previous commit) with safeguard for shallow history
31+ if git rev-parse --quiet --verify HEAD~1 >/dev/null; then
32+ git checkout HEAD~1 pubspec.yaml
33+ PREVIOUS_VERSION=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
34+ git checkout -q HEAD pubspec.yaml
35+ echo "Previous version: $PREVIOUS_VERSION"
36+ else
37+ echo "No previous commit - assuming version unchanged"
38+ PREVIOUS_VERSION=$CURRENT_VERSION
39+ fi
40+
41+ # Compare versions and set output
42+ if [ "$CURRENT_VERSION" != "$PREVIOUS_VERSION" ]; then
43+ echo "Version changed from $PREVIOUS_VERSION to $CURRENT_VERSION"
44+ echo "VERSION_CHANGED=true" >> $GITHUB_OUTPUT
45+ else
46+ echo "Version unchanged: $CURRENT_VERSION"
47+ echo "VERSION_CHANGED=false" >> $GITHUB_OUTPUT
48+ fi
49+
50+ # Always store the current version for later steps
51+ echo "VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
52+
53+ - name : Check if build should continue
54+ id : should_build
55+ run : |
56+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
57+ echo "Building because workflow was manually triggered"
58+ echo "SHOULD_BUILD=true" >> $GITHUB_OUTPUT
59+ elif [[ "${{ steps.check_version_change.outputs.VERSION_CHANGED }}" == "true" ]]; then
60+ echo "Building because version changed"
61+ echo "SHOULD_BUILD=true" >> $GITHUB_OUTPUT
62+ else
63+ echo "Skipping build because version did not change"
64+ echo "SHOULD_BUILD=false" >> $GITHUB_OUTPUT
65+ fi
1866
1967 - name : Set Up Java
68+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
2069 uses : actions/setup-java@v3.12.0
2170 with :
2271 distribution : ' oracle'
2372 java-version : ' 17'
2473
2574 - name : Set Up Flutter
75+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
2676 uses : subosito/flutter-action@v2
2777 with :
2878 flutter-version : ' 3.32.2'
2979 channel : ' stable'
3080
3181 - name : Cache Dart & Pub artifacts
82+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
3283 uses : actions/cache@v3
3384 with :
3485 path : |
@@ -37,32 +88,40 @@ jobs:
3788 key : ${{ runner.os }}-dart-${{ hashFiles('**/pubspec.yaml') }}
3889
3990 - name : Install Dependencies
91+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
4092 run : flutter pub get
4193
4294 - name : Generate localization and other required files
95+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
4396 run : dart run build_runner build -d
4497
4598 - name : Extract version from pubspec.yaml
99+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
46100 id : extract_version
47101 run : |
48102 version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
49103 echo "VERSION=$version" >> $GITHUB_ENV
50104
51105 - name : Build APK
106+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
52107 run : flutter build apk --release --dart-define=APP_VERSION=${{ env.VERSION }} --dart-define=GIT_COMMIT=${{ github.sha }}
53108
54109 - name : Build appBundle
110+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
55111 run : flutter build appbundle --release --dart-define=APP_VERSION=${{ env.VERSION }} --dart-define=GIT_COMMIT=${{ github.sha }}
56112
57113 - name : Build IPA
114+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
58115 run : flutter build ipa --no-codesign --dart-define=APP_VERSION=${{ env.VERSION }} --dart-define=GIT_COMMIT=${{ github.sha }}
59116
60117 - name : Compress Archives and IPAs
118+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
61119 run : |
62120 cd build
63121 tar -czf ios_build.tar.gz ios
64122
65123 - name : Upload Artifacts
124+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
66125 uses : actions/upload-artifact@v4
67126 with :
68127 name : Releases
72131 build/ios_build.tar.gz
73132
74133 - name : Check if Tag Exists
134+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
75135 id : check_tag
76136 run : |
77137 if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
@@ -81,13 +141,14 @@ jobs:
81141 fi
82142
83143 - name : Modify Tag
84- if : ${{ env.TAG_EXISTS }} == 'true'
144+ if : steps.should_build.outputs.SHOULD_BUILD == 'true' && env.TAG_EXISTS == 'true'
85145 id : modify_tag
86146 run : |
87147 new_version="${{ env.VERSION }}-alpha-${{ github.run_number }}"
88148 echo "VERSION=$new_version" >> $GITHUB_ENV
89-
149+
90150 - name : Create Release
151+ if : steps.should_build.outputs.SHOULD_BUILD == 'true'
91152 uses : ncipollo/release-action@v1
92153 with :
93154 artifacts : " build/app/outputs/flutter-apk/app-release.apk,build/app/outputs/bundle/release/app-release.aab,build/ios_build.tar.gz"
0 commit comments