|
| 1 | +name: Build & Release |
| 2 | + |
| 3 | +# Trigger on push to master branch or with a tag |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - '**' |
| 8 | + tags: |
| 9 | + - 'V*' |
| 10 | + |
| 11 | +# If previous workflow is still running, we push again, we will cancel the previous workflow |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.ref_name }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + Build: |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + include: |
| 22 | + - target: Android |
| 23 | + os: ubuntu-latest |
| 24 | + artifact_name: release-Android |
| 25 | + artifact_path: build/app/outputs/flutter-apk/*.apk |
| 26 | + - target: Windows |
| 27 | + os: windows-latest |
| 28 | + artifact_name: release-Windows |
| 29 | + artifact_path: | |
| 30 | + build/windows/outputs/*.zip |
| 31 | + build/windows/outputs/*.exe |
| 32 | + outputs: |
| 33 | + version: ${{ steps.get_version.outputs.version }} |
| 34 | + date: ${{ steps.get_version.outputs.date}} |
| 35 | + runs-on: ${{ matrix.os }} |
| 36 | + env: |
| 37 | + FLUTTER_VERSION: 3.24.0 |
| 38 | + steps: |
| 39 | + # Checkout branch |
| 40 | + - name: Checkout |
| 41 | + uses: actions/checkout@v4 |
| 42 | + |
| 43 | + # Add Android keystore |
| 44 | + - name: Setup Android keystore |
| 45 | + if: matrix.target == 'Android' |
| 46 | + run: | |
| 47 | + echo "${{ secrets.ENCODED_KEYSTORE }}" | base64 -di > android/app/cloudchewie.jks |
| 48 | + echo "${{ secrets.KEY_PROPERTIES }}" > android/key.properties |
| 49 | +
|
| 50 | + # Setup Flutter |
| 51 | + - name: Setup Flutter |
| 52 | + uses: subosito/flutter-action@v2.16.0 |
| 53 | + with: |
| 54 | + flutter-version: ${{ env.FLUTTER_VERSION }} |
| 55 | + channel: 'stable' |
| 56 | + cache: true |
| 57 | + |
| 58 | + # Setup JDK |
| 59 | + - name: Setup JDK 17 (Android) |
| 60 | + if: matrix.target == 'Android' |
| 61 | + uses: actions/setup-java@v4 |
| 62 | + with: |
| 63 | + distribution: 'temurin' |
| 64 | + java-version: '17' |
| 65 | + cache: gradle |
| 66 | + |
| 67 | + # Flutter Pub Get |
| 68 | + - name: Flutter Pub Get |
| 69 | + run: | |
| 70 | + git config --global core.longpaths true |
| 71 | + flutter doctor -v |
| 72 | + flutter pub get |
| 73 | + dart run intl_utils:generate |
| 74 | +
|
| 75 | + # Get app version |
| 76 | + - name: Get app version |
| 77 | + id: get_version |
| 78 | + shell: bash |
| 79 | + run: | |
| 80 | + echo "version=$(head -n 2 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2 | cut -d '+' -f 1)" >> $GITHUB_OUTPUT |
| 81 | + echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT |
| 82 | +
|
| 83 | + # Build Android .apk |
| 84 | + - name: Build Android |
| 85 | + if: matrix.target == 'Android' |
| 86 | + run: | |
| 87 | + flutter build apk --release |
| 88 | + flutter build apk --release --split-per-abi |
| 89 | + cd build/app/outputs/flutter-apk |
| 90 | + mv app-release.apk Loftify-${{ steps.get_version.outputs.version }}-android-universal.apk |
| 91 | + mv app-arm64-v8a-release.apk Loftify-${{ steps.get_version.outputs.version }}-android-arm64-v8a.apk |
| 92 | + mv app-armeabi-v7a-release.apk Loftify-${{ steps.get_version.outputs.version }}-android-armeabi-v7a.apk |
| 93 | + mv app-x86_64-release.apk Loftify-${{ steps.get_version.outputs.version }}-android-x86_64.apk |
| 94 | +
|
| 95 | + # Build Windows .zip |
| 96 | + - name: Build Windows |
| 97 | + if: matrix.target == 'Windows' |
| 98 | + run: | |
| 99 | + flutter build windows --release |
| 100 | + $DestDir = "build\windows\outputs\Loftify-${{ steps.get_version.outputs.version }}-windows-x86_64" |
| 101 | + $SrcDir = "build\windows\x64\runner\Release" |
| 102 | + $dllDir = "tools\windows_dll" |
| 103 | + |
| 104 | + Copy-Item -Filter *.dll -Path $dllDir\* -Destination $SrcDir -Force |
| 105 | + New-Item -Path $DestDir -ItemType Directory |
| 106 | + Copy-Item $SrcDir\* -Recurse $DestDir |
| 107 | + |
| 108 | + Compress-Archive $DestDir build\windows\outputs\Loftify-${{ steps.get_version.outputs.version }}-windows-x86_64.zip |
| 109 | + |
| 110 | + (Get-Content tools/windows_tools/Loftify.iss) -replace '#define MyAppVersion ".*"', '#define MyAppVersion "${{ steps.get_version.outputs.version }}"' | Set-Content tools/windows_tools/Loftify.iss |
| 111 | +
|
| 112 | + # Build Windows .exe |
| 113 | + - name: Build Windows Installer |
| 114 | + if: matrix.target == 'Windows' |
| 115 | + uses: Minionguyjpro/Inno-Setup-Action@v1.2.5 |
| 116 | + with: |
| 117 | + path: tools/windows_tools/Loftify.iss |
| 118 | + |
| 119 | + # Upload Artifacts |
| 120 | + - name: Upload Artifacts |
| 121 | + uses: actions/upload-artifact@v4 |
| 122 | + with: |
| 123 | + name: ${{ matrix.artifact_name }} |
| 124 | + path: ${{ matrix.artifact_path }} |
| 125 | + |
| 126 | + Publish: |
| 127 | + if: startsWith(github.ref, 'refs/tags/') |
| 128 | + name: Publish |
| 129 | + needs: Build |
| 130 | + runs-on: ubuntu-latest |
| 131 | + steps: |
| 132 | + - name: Checkout |
| 133 | + uses: actions/checkout@v4 |
| 134 | + - name: Get app version |
| 135 | + id: get_version |
| 136 | + shell: bash |
| 137 | + run: | |
| 138 | + echo "version=$(head -n 2 pubspec.yaml | tail -n 1 | cut -d ' ' -f 2 | cut -d '+' -f 1)" >> $GITHUB_OUTPUT |
| 139 | + - name: Make tmp dir |
| 140 | + run: mkdir /tmp/artifacts |
| 141 | + - name: Download all Artifacts |
| 142 | + uses: actions/download-artifact@v4 |
| 143 | + with: |
| 144 | + path: /tmp/artifacts |
| 145 | + - name: List and move all Artifacts |
| 146 | + run: | |
| 147 | + mkdir -p /tmp/artifacts/final |
| 148 | + mv /tmp/artifacts/release-Android/*.apk /tmp/artifacts/final/ |
| 149 | + mv /tmp/artifacts/release-Windows/*.zip /tmp/artifacts/final/ |
| 150 | + mv /tmp/artifacts/release-Windows/*.exe /tmp/artifacts/final/ |
| 151 | +
|
| 152 | + cd /tmp/artifacts/final |
| 153 | + for file in *; do |
| 154 | + if [ -f "$file" ]; then |
| 155 | + sha1sum "$file" | awk '{ print $1 }' > "$file.sha1" |
| 156 | + fi |
| 157 | + done |
| 158 | + ls -R /tmp/artifacts/final |
| 159 | +
|
| 160 | + - name: Upload to S3 |
| 161 | + uses: Robert-Stackflow/upload-s3-action@master |
| 162 | + with: |
| 163 | + endpoint: ${{ secrets.AWS_ENDPOINT }} |
| 164 | + aws_key_id: ${{ secrets.AWS_KEY_ID }} |
| 165 | + aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY}} |
| 166 | + aws_bucket: ${{ secrets.AWS_BUCKET }} |
| 167 | + source_dir: /tmp/artifacts/final |
| 168 | + destination_dir: Loftify/${{ steps.get_version.outputs.version }} |
| 169 | + - name: Upload to release |
| 170 | + uses: Robert-Stackflow/release-action@master |
| 171 | + with: |
| 172 | + tag: ${{ github.ref_name }} |
| 173 | + allowUpdates: true |
| 174 | + generateReleaseNotes: true |
| 175 | + artifacts: /tmp/artifacts/final/* |
| 176 | + artifactErrorsFailBuild: true |
| 177 | + replacesArtifacts: true |
| 178 | + makeLatest: true |
| 179 | + draft: true |
| 180 | + updateOnlyUnreleased: true |
0 commit comments