|
| 1 | +name: 构建发布Flutter应用 |
| 2 | + |
| 3 | +#on: |
| 4 | +# push: |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - main |
| 10 | +jobs: |
| 11 | + pre-build: |
| 12 | + name: 预构建 |
| 13 | + runs-on: ubuntu-latest |
| 14 | + outputs: |
| 15 | + APP_VERSION: ${{ steps.output-version.outputs.APP_VERSION }} |
| 16 | + APP_LAST_VERSION: ${{ steps.output-tag-version.outputs.APP_VERSION }} |
| 17 | + steps: |
| 18 | + - name: 拉取代码 |
| 19 | + uses: actions/checkout@v3 |
| 20 | + with: |
| 21 | + sparse-checkout: | |
| 22 | + pubspec.yaml |
| 23 | + sparse-checkout-cone-mode: false |
| 24 | + fetch-depth: 0 |
| 25 | + - name: 读取当前版本号 |
| 26 | + id: output-version |
| 27 | + run: | |
| 28 | + VERSION=`grep -iE --regexp="version: ([0-9\.+]*)" pubspec.yaml | grep -io "[0-9\.+]*"` |
| 29 | + echo "Version: $VERSION" |
| 30 | + echo "APP_VERSION=$VERSION" >> $GITHUB_OUTPUT |
| 31 | + - name: 获取最新的TAG |
| 32 | + id: output-tag-version |
| 33 | + run: | |
| 34 | + LAST_VERSION=`git tag --sort=-creatordate | head -1` |
| 35 | + echo "Version: $LAST_VERSION" |
| 36 | + echo "APP_LAST_VERSION=$LAST_VERSION" >> $GITHUB_OUTPUT |
| 37 | + build-apk: |
| 38 | + name: 编译android |
| 39 | + runs-on: ubuntu-latest |
| 40 | + needs: [ pre-build ] |
| 41 | + steps: |
| 42 | + - name: 设置Flutter环境 |
| 43 | + uses: subosito/flutter-action@v2 |
| 44 | + with: |
| 45 | + channel: "stable" |
| 46 | + |
| 47 | + - name: 拉取代码 |
| 48 | + uses: actions/checkout@v4 |
| 49 | + |
| 50 | + - name: 安装依赖项 |
| 51 | + run: flutter pub get |
| 52 | + |
| 53 | + - name: 设置java环境 |
| 54 | + uses: actions/setup-java@v4 |
| 55 | + with: |
| 56 | + distribution: "adopt" |
| 57 | + java-version: "21" |
| 58 | + |
| 59 | + - name: 运行代码生成器 |
| 60 | + run: dart run build_runner build |
| 61 | + |
| 62 | + - name: 初始化签名 |
| 63 | + run: | |
| 64 | + touch ./android/key.properties |
| 65 | + echo keyPassword='${{ secrets.KEYPASSWORD }}' >> ./android/key.properties |
| 66 | + echo storePassword='${{ secrets.STOREPASSWORD }}' >> ./android/key.properties |
| 67 | + echo keyAlias='${{ secrets.KEYALIAS }}' >> ./android/key.properties |
| 68 | + echo storeFile='./key.jks' >> ./android/key.properties |
| 69 | + echo ${{ secrets.KEY_STORE }} | base64 --decode > ./android/app/key.jks |
| 70 | + - name: 编译apk |
| 71 | + run: flutter build apk --split-per-abi --obfuscate --split-debug-info=build/app/outputs/symbols/release |
| 72 | + |
| 73 | + - name: 上传apk到工作流程 |
| 74 | + uses: actions/upload-artifact@v4 |
| 75 | + with: |
| 76 | + name: build-apk |
| 77 | + path: build/app/outputs/apk/release/* |
| 78 | + |
| 79 | + build-linux: |
| 80 | + name: 编译linux |
| 81 | + runs-on: ubuntu-latest |
| 82 | + needs: [ pre-build ] |
| 83 | + steps: |
| 84 | + - name: 拉取代码 |
| 85 | + uses: actions/checkout@v4 |
| 86 | + |
| 87 | + - name: 设置Flutter环境 |
| 88 | + uses: subosito/flutter-action@v2 |
| 89 | + with: |
| 90 | + channel: "stable" |
| 91 | + |
| 92 | + - name: 安装ninja、libgtk |
| 93 | + run: | |
| 94 | + sudo apt-get update -y |
| 95 | + sudo apt-get install -y ninja-build libgtk-3-dev libmpv-dev mpv |
| 96 | +
|
| 97 | + - name: 安装依赖项 |
| 98 | + run: flutter pub get |
| 99 | + |
| 100 | + - name: 配置桌面 |
| 101 | + run: flutter config --enable-linux-desktop |
| 102 | + |
| 103 | + - name: 运行代码生成器 |
| 104 | + run: dart run build_runner build |
| 105 | + |
| 106 | + - name: 编译linux |
| 107 | + run: flutter build linux |
| 108 | + |
| 109 | + - name: 压缩生成的文件 |
| 110 | + run: tar -zcvf "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-linux-x86_64-release.tar.gz" --directory=build/linux/x64/release/bundle . |
| 111 | + |
| 112 | + - name: 上传到工作流程 |
| 113 | + uses: actions/upload-artifact@v4 |
| 114 | + with: |
| 115 | + name: build-linux |
| 116 | + path: "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-linux-x86_64-release.tar.gz" |
| 117 | + |
| 118 | + build-windows: |
| 119 | + name: 编译windows |
| 120 | + runs-on: windows-latest |
| 121 | + needs: [ pre-build ] |
| 122 | + steps: |
| 123 | + - name: 拉取代码 |
| 124 | + uses: actions/checkout@v4 |
| 125 | + |
| 126 | + - name: 设置Flutter环境 |
| 127 | + uses: subosito/flutter-action@v2 |
| 128 | + with: |
| 129 | + channel: "stable" |
| 130 | + |
| 131 | + - name: 安装依赖项 |
| 132 | + run: flutter pub get |
| 133 | + |
| 134 | + - name: 启动windows桌面 |
| 135 | + run: flutter config --enable-windows-desktop |
| 136 | + |
| 137 | + - name: 运行代码生成器 |
| 138 | + run: dart run build_runner build |
| 139 | + |
| 140 | + - name: 编译windows |
| 141 | + run: flutter build windows |
| 142 | + |
| 143 | + - name: 压缩生成的文件 |
| 144 | + run: | |
| 145 | + $sourceFolder = "build\windows\x64\runner\Release" |
| 146 | + $destinationPath = "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-windows-x86_64-release.zip" |
| 147 | + Compress-Archive -Path $sourceFolder -DestinationPath $destinationPath |
| 148 | +
|
| 149 | + - name: 上传到工作流程 |
| 150 | + uses: actions/upload-artifact@v4 |
| 151 | + with: |
| 152 | + name: build-windows |
| 153 | + path: "MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-windows-x86_64-release.zip" |
| 154 | + |
| 155 | + build-macos: |
| 156 | + name: 编译macOS |
| 157 | + runs-on: macos-latest |
| 158 | + needs: [ pre-build ] |
| 159 | + steps: |
| 160 | + - name: 拉取代码 |
| 161 | + uses: actions/checkout@v4 |
| 162 | + |
| 163 | + - name: 设置Flutter环境 |
| 164 | + uses: subosito/flutter-action@v2 |
| 165 | + with: |
| 166 | + channel: "stable" |
| 167 | + |
| 168 | + - name: 安装依赖项 |
| 169 | + run: flutter pub get |
| 170 | + |
| 171 | + - name: 启动桌面 |
| 172 | + run: flutter config --enable-macos-desktop |
| 173 | + |
| 174 | + - name: 运行代码生成器 |
| 175 | + run: dart run build_runner build |
| 176 | + |
| 177 | + - name: 编译macOS |
| 178 | + run: flutter build macos |
| 179 | + |
| 180 | + - name: 压缩生成的文件 |
| 181 | + run: | |
| 182 | + cd build/macos/Build/Products/Release |
| 183 | + zip -rq MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip MoeKey.app |
| 184 | + mv MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip $GITHUB_WORKSPACE |
| 185 | +
|
| 186 | + - name: 上传到工作流程 |
| 187 | + uses: actions/upload-artifact@v4 |
| 188 | + with: |
| 189 | + name: build-macos |
| 190 | + path: | |
| 191 | + MoeKey-${{ needs.pre-build.outputs.APP_VERSION }}-macOS-universal-release.zip |
| 192 | +
|
| 193 | +# release: |
| 194 | +# name: 上传包 |
| 195 | +# needs: [build-apk, build-linux, build-windows, build-macos, pre-build] |
| 196 | +# runs-on: ubuntu-latest |
| 197 | +# permissions: |
| 198 | +# contents: write |
| 199 | +# steps: |
| 200 | +# - name: 下载apk |
| 201 | +# uses: actions/download-artifact@v4 |
| 202 | +# with: |
| 203 | +# name: build-apk |
| 204 | +# path: artifact |
| 205 | +# |
| 206 | +# - name: 下载linux |
| 207 | +# uses: actions/download-artifact@v4 |
| 208 | +# with: |
| 209 | +# name: build-linux |
| 210 | +# path: artifact |
| 211 | +# |
| 212 | +# - name: 下载windows |
| 213 | +# uses: actions/download-artifact@v4 |
| 214 | +# with: |
| 215 | +# name: build-windows |
| 216 | +# path: artifact |
| 217 | +# |
| 218 | +# - name: 下载macOS |
| 219 | +# uses: actions/download-artifact@v4 |
| 220 | +# with: |
| 221 | +# name: build-macos |
| 222 | +# path: artifact |
| 223 | +# |
| 224 | +# - name: 创建releases |
| 225 | +# id: create_release |
| 226 | +# uses: softprops/action-gh-release@v2 |
| 227 | +# with: |
| 228 | +# tag_name: ${{ needs.pre-build.outputs.APP_VERSION }} |
| 229 | +# files: ./artifact/* |
| 230 | +# body: "[CHANGELOG.md](CHANGELOG.md)" |
0 commit comments