-
-
Notifications
You must be signed in to change notification settings - Fork 0
171 lines (149 loc) · 5.87 KB
/
build_and_release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Flutter CI/CD
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
jobs:
build-and-release:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get latest tag
id: get_latest_tag
if: github.ref == 'refs/heads/main'
run: echo "latest_tag=$(git describe --tags --abbrev=0 || echo v0.0.0)" >> $GITHUB_OUTPUT
- name: Bump version
id: bump_version
if: github.ref == 'refs/heads/main'
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
if: github.ref == 'refs/heads/main'
run: |
sed -i 's/^version: .*/version: ${{ steps.bump_version.outputs.new_version }}+${{ github.run_number }}/g' pubspec.yaml
- name: Commit changes
if: github.ref == 'refs/heads/main'
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
if: github.ref == 'refs/heads/main'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
- name: Setup Java
uses: actions/setup-java@v4
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.PUB_CACHE }}
key: ${{ runner.os }}-pub-${{ hashFiles('**/pubspec.lock') }}
restore-keys: |
${{ runner.os }}-pub-
- name: Get dependencies
run: flutter pub get
- name: Debug Pub Cache
run: |
echo "PUB_CACHE: $PUB_CACHE"
ls -R $PUB_CACHE || echo "PUB_CACHE directory not found"
- name: Build APK
run: flutter build apk --release --split-per-abi
- name: Upload armeabi-v7a APK
if: github.ref == 'refs/heads/dev'
uses: actions/upload-artifact@v4
with:
name: app-armeabi-v7a-release
path: build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk
retention-days: 5
- name: Upload arm64-v8a APK
if: github.ref == 'refs/heads/dev'
uses: actions/upload-artifact@v4
with:
name: app-arm64-v8a-release
path: build/app/outputs/flutter-apk/app-arm64-v8a-release.apk
retention-days: 5
- name: Upload x86_64 APK
if: github.ref == 'refs/heads/dev'
uses: actions/upload-artifact@v4
with:
name: app-x86_64-release
path: build/app/outputs/flutter-apk/app-x86_64-release.apk
retention-days: 5
- name: Create Release
if: github.ref == 'refs/heads/main'
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
with:
tag_name: v${{ steps.bump_version.outputs.new_version }}
release_name: Release ${{ steps.bump_version.outputs.new_version }}
draft: false
prerelease: false
- name: Upload armeabi-v7a APK
if: github.ref == 'refs/heads/main'
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${{ steps.bump_version.outputs.new_version }}-armeabi-v7a.apk
asset_content_type: application/vnd.android.package-archive
- name: Upload arm64-v8a APK
if: github.ref == 'refs/heads/main'
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${{ steps.bump_version.outputs.new_version }}-arm64-v8a.apk
asset_content_type: application/vnd.android.package-archive
- name: Upload x86 APK
if: github.ref == 'refs/heads/main'
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${{ steps.bump_version.outputs.new_version }}-x86_64.apk
asset_content_type: application/vnd.android.package-archive
- name: Final Debug
if: always()
run: |
echo "Gradle cache:"
ls -R ~/.gradle/caches || echo "Gradle cache not found"
echo "Pub cache:"
ls -R $PUB_CACHE || echo "Pub cache not found"