Skip to content

Update set up Flutter environment for Windows #34

Update set up Flutter environment for Windows

Update set up Flutter environment for Windows #34

name: Build and Release Flutter Packages
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
build:
strategy:
fail-fast: false
matrix:
platform: [linux, windows, macos, android, ios]
arch: [x64, arm64]
exclude:
- platform: windows
arch: arm64
- platform: ios
arch: x64
- platform: android
arch: x64
include:
- platform: macos
arch: x64
- platform: macos
arch: arm64
- platform: linux
arch: x64
- platform: linux
arch: arm64
- platform: android
arch: arm64
- platform: ios
arch: arm64
- platform: windows
arch: x64
runs-on: ${{
matrix.platform == 'windows' && 'windows-latest' ||
matrix.platform == 'linux' && 'ubuntu-latest' ||
matrix.platform == 'android' && 'ubuntu-latest' ||
matrix.platform == 'macos' && 'macos-latest' ||
matrix.platform == 'ios' && 'macos-latest' }}
env:
PLATFORM: ${{ matrix.platform }}
ARCH: ${{ matrix.arch }}
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Set up Flutter environment for Linux/Android
if: ${{ matrix.platform == 'linux' || matrix.platform == 'android' }}
run: |
sudo apt-get update
sudo apt-get install -y snapd # Install snap if not already installed
sudo snap install flutter --classic # Install Flutter using snap
export PATH="$PATH:/snap/bin" # Add snap binaries to PATH
flutter doctor # Check Flutter installation
- name: Set up Flutter environment for macOS/iOS
if: ${{ matrix.platform == 'macos' || matrix.platform == 'ios' }}
run: |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)" # For Apple Silicon
else
eval "$(/usr/local/bin/brew shellenv)" # For Intel
fi
brew install --cask flutter
export PATH="$PATH:/Users/runner/Library/Flutter/bin"
flutter doctor
- name: Set up Flutter environment for Windows
if: ${{ matrix.platform == 'windows' }}
run: |
choco install flutter
echo "C:\\flutter\\bin" >> $GITHUB_ENV # 使用 GITHUB_ENV 添加 flutter 到 PATH
- name: Show workflow information
run: |
echo "Platform: $PLATFORM, Architecture: $ARCH"
- name: Build Flutter packages
run: |
case $PLATFORM in
"linux")
flutter build linux --release
;;
"windows")
flutter build windows --release
;;
"macos")
flutter build macos --release
flutter build ios --release --no-codesign
;;
"android")
flutter build apk --release
;;
"ios")
flutter build ios --release --no-codesign
;;
esac
- name: List built files
run: ls -R build
- name: Check if tag exists
id: check_tag
run: |
TAG_EXISTS=$(git tag --list "v${{ github.run_number }}-${{ github.run_id }}")
echo "tag_exists=$TAG_EXISTS" >> $GITHUB_ENV
- name: Create Release
if: env.tag_exists != 'v*' # 只有在标签不存在时才创建
id: create_release
uses: actions/create-release@v1
with:
tag_name: v${{ github.run_number }}-${{ github.run_id }}
release_name: Release v${{ github.run_number }}-${{ github.run_id }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload built packages to Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ github.run_number }}-${{ github.run_id }}
files: |
build/linux/x64/release/bundle/*
build/linux/arm64/release/bundle/*
build/windows/runner/Release/XStream.exe
build/macos/Build/Products/Release/XStream.app
build/app/outputs/flutter-apk/app-release.apk
build/ios/iphoneos/XStream.app
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}