@@ -3,6 +3,17 @@ name: Build and Release APKs
33on :
44 release :
55 types : [created]
6+ workflow_dispatch :
7+ inputs :
8+ version :
9+ description : ' Version to build (e.g., 1.0.11, leave empty to use pubspec.yaml)'
10+ required : false
11+ default : ' '
12+ skip_tests :
13+ description : ' Skip running tests'
14+ required : false
15+ default : false
16+ type : boolean
617
718jobs :
819 build-and-release :
@@ -62,33 +73,67 @@ jobs:
6273 echo "Analysis completed successfully!"
6374
6475 - name : Run tests
76+ if : ${{ !inputs.skip_tests }}
6577 run : |
6678 echo "Running Flutter tests..."
6779 flutter test
6880 echo "Tests completed successfully!"
6981
7082 - name : Update pubspec version
7183 run : |
72- # Extract version from tag (e.g., v1.2.3 -> 1.2.3, also handles 1.2.3)
73- TAG_VERSION=$(echo "$GITHUB_REF_NAME" | sed 's/^v//')
84+ # For workflow_dispatch, use input version or keep current
85+ if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
86+ INPUT_VERSION="${{ inputs.version }}"
87+ if [[ -n "$INPUT_VERSION" ]]; then
88+ # Use the provided version
89+ TAG_VERSION="$INPUT_VERSION"
90+
91+ # Fix: If version is format 1.2, append .0 to make it 1.2.0
92+ if [[ "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
93+ TAG_VERSION="${TAG_VERSION}.0"
94+ echo "Formatted version to semantic version: $TAG_VERSION"
95+ fi
96+
97+ # Validate version format
98+ if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
99+ echo "Error: Invalid version format: $TAG_VERSION"
100+ echo "Expected semantic version format (e.g., 1.2.3)"
101+ exit 1
102+ fi
103+
104+ # Use run_number as build number
105+ BUILD_NUMBER=${{ github.run_number }}
106+ # Update version in pubspec.yaml
107+ sed -i "s/^version: .*/version: ${TAG_VERSION}+${BUILD_NUMBER}/" pubspec.yaml
108+ echo "Updated version to: $TAG_VERSION+$BUILD_NUMBER"
109+ else
110+ echo "No version specified, using current version from pubspec.yaml"
111+ CURRENT_VERSION=$(grep "^version:" pubspec.yaml | sed 's/^version: //')
112+ echo "Current version: $CURRENT_VERSION"
113+ fi
114+ else
115+ # For release events, extract version from tag
116+ # Extract version from tag (e.g., v1.2.3 -> 1.2.3, also handles 1.2.3)
117+ TAG_VERSION=$(echo "$GITHUB_REF_NAME" | sed 's/^v//')
74118
75- # Fix: If version is format 1.2, append .0 to make it 1.2.0
76- if [[ "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
77- TAG_VERSION="${TAG_VERSION}.0"
78- echo "Formatted version to semantic version: $TAG_VERSION"
79- fi
119+ # Fix: If version is format 1.2, append .0 to make it 1.2.0
120+ if [[ "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+$ ]]; then
121+ TAG_VERSION="${TAG_VERSION}.0"
122+ echo "Formatted version to semantic version: $TAG_VERSION"
123+ fi
80124
81- # Validate version format
82- if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
83- echo "Error: Invalid version format: $TAG_VERSION"
84- echo "Expected semantic version format (e.g., 1.2.3)"
85- exit 1
125+ # Validate version format
126+ if [[ ! "$TAG_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
127+ echo "Error: Invalid version format: $TAG_VERSION"
128+ echo "Expected semantic version format (e.g., 1.2.3)"
129+ exit 1
130+ fi
131+ # Use run_number as build number
132+ BUILD_NUMBER=${{ github.run_number }}
133+ # Update version in pubspec.yaml
134+ sed -i "s/^version: .*/version: ${TAG_VERSION}+${BUILD_NUMBER}/" pubspec.yaml
135+ echo "Updated version to: $TAG_VERSION+$BUILD_NUMBER"
86136 fi
87- # Use run_number as build number
88- BUILD_NUMBER=${{ github.run_number }}
89- # Update version in pubspec.yaml
90- sed -i "s/^version: .*/version: ${TAG_VERSION}+${BUILD_NUMBER}/" pubspec.yaml
91- echo "Updated version to: $TAG_VERSION+$BUILD_NUMBER"
92137 grep "^version:" pubspec.yaml
93138
94139 - name : Build all APKs
@@ -104,8 +149,17 @@ jobs:
104149 mv build/app/outputs/flutter-apk/app-armeabi-v7a-release.apk release-artifacts/openlib-extended-armeabi-v7a-release.apk
105150
106151 - name : Upload Release Assets
152+ if : github.event_name == 'release'
107153 uses : softprops/action-gh-release@v1
108154 with :
109155 files : release-artifacts/*.apk
110156 env :
111157 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
158+
159+ - name : Upload Build Artifacts
160+ if : github.event_name == 'workflow_dispatch'
161+ uses : actions/upload-artifact@v4
162+ with :
163+ name : apk-builds
164+ path : release-artifacts/*.apk
165+ retention-days : 7
0 commit comments