Build Window, Liunx, macOS, Android (GH hosted) #8
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: Build Window, Liunx, macOS, Android (GH hosted) | |
on: | |
workflow_dispatch: | |
workflow_call: | |
outputs: | |
version: | |
description: "Version string extracted from pubspec.yaml" | |
value: ${{ jobs.build.outputs.version }} | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
outputs: | |
version: ${{ env.VERSION }} | |
strategy: | |
matrix: | |
os: [macos-latest, ubuntu-latest, windows-latest] | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Extract secrets | |
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' | |
run: | | |
echo "${{ secrets.SECRET_FILES }}" | base64 -d > secret_files.zip | |
unzip secret_files.zip -d . | |
- name: Extract secrets | |
if: matrix.os == 'windows-latest' | |
env: | |
secretfiles: "${{ secrets.SECRET_FILES }}" | |
run: | | |
$secretFiles = $env:secretfiles | |
$secretFilesBytes = [System.Convert]::FromBase64String($secretFiles) | |
$secretFilesZip = "secret_files.zip" | |
[IO.File]::WriteAllBytes($secretFilesZip, $secretFilesBytes) | |
unzip $secretFilesZip -d . | |
- name: Set up Java | |
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'zulu' | |
java-version: "17.*" | |
cache: gradle | |
- name: Install Flutter | |
uses: subosito/flutter-action@v2 | |
with: | |
channel: 'stable' | |
#architecture: x64 | |
cache: true | |
cache-key: 'flutter-:os:-:channel:-:version:-:arch:' | |
- name: Check Flutter Version | |
run: flutter --version | |
- name: Upgrade Flutter | |
run: flutter upgrade | |
- name: Get Dependencies | |
run: flutter pub get | |
- name: Install Linux build dependancies | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
sudo apt-get update -y | |
sudo sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev imagemagick | |
- name: Run tests | |
run: flutter test --coverage | |
- name: Build for Windows | |
if: matrix.os == 'windows-latest' | |
run: flutter build windows | |
- name: Build for Linux | |
if: matrix.os == 'ubuntu-latest' | |
run: flutter build linux | |
- name: Build for macOS | |
if: matrix.os == 'macos-latest' | |
run: flutter build macos | |
- name: Get Android keystore | |
if: matrix.os == 'ubuntu-latest' | |
id: android_keystore | |
uses: timheuer/base64-to-file@v1.2 | |
with: | |
fileName: keystore.jks | |
encodedString: ${{ secrets.STOREFILE }} | |
- name: Create key.properties for Android | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
echo "storeFile=${{ steps.android_keystore.outputs.filePath }}" > android/key.properties | |
echo "storePassword=${{ secrets.STOREPASSWORD }}" >> android/key.properties | |
echo "keyPassword=${{ secrets.KEYPASSWORD }}" >> android/key.properties | |
echo "keyAlias=${{ secrets.KEYALIAS }}" >> android/key.properties | |
- name: Build Android (aab) | |
if: matrix.os == 'ubuntu-latest' | |
run: flutter build appbundle | |
- name: Build Android (apk) | |
if: matrix.os == 'ubuntu-latest' | |
run: flutter build apk | |
- name: Extract version from pubspec.yaml (macOS and Linux) | |
if: matrix.os == 'macos-latest' || matrix.os == 'ubuntu-latest' | |
run: | | |
echo "VERSION=$(sed -n 's/^version: *//p' pubspec.yaml)" >> $GITHUB_ENV | |
shell: bash | |
- name: Extract version from pubspec.yaml (Windows) | |
if: matrix.os == 'windows-latest' | |
run: | | |
$version = (Select-String -Path "pubspec.yaml" -Pattern 'version: (.+)$').Matches.Groups[1].Value.Trim() | |
"VERSION=$version" >> $env:GITHUB_ENV | |
shell: powershell | |
- name: Rename Android aab and apk | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
mv build/app/outputs/bundle/release/app-release.aab build/app/outputs/bundle/release/dikt-android-${{ env.VERSION }}.aab | |
mv build/app/outputs/flutter-apk/app-release.apk build/app/outputs/flutter-apk/dikt-android-${{ env.VERSION }}.apk | |
# Using tar to keep 'execute' attribute of binary, this one is lost when simply uploading folder as artefact and getting it as .zip | |
- name: Compress and package the artifact (Linux) | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
cd build/linux/x64/release/bundle | |
tar -czf ../../../../dikt-linux-x64-${{ env.VERSION }}.tar ./ | |
- name: Compress and package the artifact (macOS) | |
if: matrix.os == 'macos-latest' | |
run: | | |
cd build/macos/Build/Products/Release/ | |
zip -r -D -y dikt-macOS-${{ env.VERSION }}.zip dikt.app | |
mv dikt-macOS-${{ env.VERSION }}.zip ../../../../dikt-macOS-${{ env.VERSION }}.zip | |
# zip -r -D -y dikt-macOS-x64-${{ env.VERSION }}.zip dikt.app | |
# mv dikt-macOS-x64-${{ env.VERSION }}.zip ../../../../dikt-macOS-x64-${{ env.VERSION }}.zip | |
# Zip file will be zipped by GH when creating artifcat, no need | |
# - name: Compress and package the artifact (Windows) | |
# if: matrix.os == 'windows-latest' | |
# run: Compress-Archive -Path ".\build\windows\runner\Release\" -DestinationPath ".\build\dikt-windows-x64-${{ env.VERSION }}.zip" | |
# shell: powershell | |
- name: List contents of the Release directory (Windows) | |
if: matrix.os == 'windows-latest' | |
run: Get-ChildItem -Path ".\build\windows\x64\runner\Release\" -Name | |
shell: powershell | |
- name: Smoketest/run app (Windows) | |
if: matrix.os == 'windows-latest' | |
run: Start-Process -FilePath ".\build\windows\x64\runner\Release\dikt.exe" | |
shell: powershell | |
- name: Smoketest/run app (macOS) | |
if: matrix.os == 'macos-latest' | |
run: | | |
open build/macos/Build/Products/Release/dikt.app --stdout build/stdout_dikt.txt --args build/ | |
# sleep 3 | |
# For some reasons the app shows empty window | |
# - name: Upload stdout (macOS) | |
# if: matrix.os == 'macos-latest' | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: stdout_dikt.txt | |
# path: build/stdout_dikt.txt | |
# if-no-files-found: error | |
# - name: Make screenshot (macOS) | |
# if: matrix.os == 'macos-latest' | |
# uses: OrbitalOwen/desktop-screenshot-action@0.1 | |
# with: | |
# file-name: 'macOS.jpg' | |
- name: Smoketest/run app (Linux) | |
if: matrix.os == 'ubuntu-latest' | |
run: | | |
nohup build/linux/x64/release/bundle/dikt & | |
# Action doesn't work on Linux, no desktop environment likely | |
# - name: Make screenshot (Linux) | |
# if: matrix.os == 'ubuntu-latest' | |
# uses: OrbitalOwen/desktop-screenshot-action@0.1 | |
# with: | |
# file-name: 'Linux.jpg' | |
- name: Upload Artifact (Windows) | |
if: matrix.os == 'windows-latest' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dikt-windows-x64-${{ env.VERSION }} | |
path: build/windows/x64/runner/Release/ | |
if-no-files-found: error | |
- name: Upload Artifact (Linux) | |
if: matrix.os == 'ubuntu-latest' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dikt-linux-x64-${{ env.VERSION }}.tar | |
path: build/dikt-linux-x64-${{ env.VERSION }}.tar | |
if-no-files-found: error | |
- name: Upload Artifact (Android aab) | |
if: matrix.os == 'ubuntu-latest' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dikt-android-${{ env.VERSION }}.aab | |
path: build/app/outputs/bundle/release/dikt-android-${{ env.VERSION }}.aab | |
if-no-files-found: error | |
- name: Upload Artifact (Android apk) | |
if: matrix.os == 'ubuntu-latest' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dikt-android-${{ env.VERSION }}.apk | |
path: build/app/outputs/flutter-apk/dikt-android-${{ env.VERSION }}.apk | |
if-no-files-found: error | |
- name: Upload Artifact (macOS) | |
if: matrix.os == 'macos-latest' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: dikt-macOS-${{ env.VERSION }} | |
path: build/dikt-macOS-${{ env.VERSION }}.zip | |
# name: dikt-macOS-x64-${{ env.VERSION }} | |
# path: build/dikt-macOS-x64-${{ env.VERSION }}.zip | |
if-no-files-found: error |