Skip to content

Update main.yml

Update main.yml #4

Workflow file for this run

name: "Build"
on:
pull_request:
branches:
- master
workflow_dispatch: # 添加手动触发
jobs:
build:
name: Build & Release
runs-on: macos-latest
steps:
#1 Checkout Repository
- name: Checkout Repository
uses: actions/checkout@v3
#2 Setup Java
- name: Set Up Java
uses: actions/setup-java@v3.12.0
with:
distribution: 'oracle'
java-version: '17'
#3 Setup Flutter
- name: Set Up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: '3.27.0-0.1.pre'
channel: 'beta'
#4 Install Dependencies
- name: Install Dependencies
run: flutter pub get
#5 Setup Keystore
- name: Decode Keystore
run: |
echo "${{ secrets.ANDROID_KJS }}" | base64 --decode > android/app/key.jks
- name: Create local.properties
run: |
echo "storePassword=${{ secrets.ANDROID_STORE_PASSWORD }}" > android/local.properties
echo "keyPassword=${{ secrets.ANDROID_KEY_PASSWORD }}" >> android/local.properties
#6 Building APK
- name: Build APK
run: flutter build apk --obfuscate --split-debug-info=splitMap
#10 Extract Version
- name: Extract version from pubspec.yaml
id: extract_version
run: |
version=$(grep '^version: ' pubspec.yaml | cut -d ' ' -f 2 | tr -d '\r')
echo "VERSION=$version" >> $GITHUB_ENV
#11 Check if Tag Exists
- name: Check if Tag Exists
id: check_tag
run: |
if git rev-parse "v${{ env.VERSION }}" >/dev/null 2>&1; then
echo "TAG_EXISTS=true" >> $GITHUB_ENV
else
echo "TAG_EXISTS=false" >> $GITHUB_ENV
fi
#12 Modify Tag if it Exists
- name: Modify Tag
if: env.TAG_EXISTS == 'true'
id: modify_tag
run: |
new_version="${{ env.VERSION }}-build-${{ github.run_number }}"
echo "VERSION=$new_version" >> $GITHUB_ENV
#13 Create Release
- name: Create Release
uses: ncipollo/release-action@v1
with:
artifacts: "build/app/outputs/flutter-apk/app-release.apk"
tag: v${{ env.VERSION }}
token: ${{ secrets.TOKEN }}