diff --git a/.github/workflows/flutter-build.yml b/.github/workflows/flutter-build.yml index 4848321f0..886ae376f 100644 --- a/.github/workflows/flutter-build.yml +++ b/.github/workflows/flutter-build.yml @@ -4,6 +4,8 @@ on: push: branches: - main + tags: + - 'v*' paths: - 'mobile/lib/**' - 'mobile/android/**' @@ -17,6 +19,7 @@ on: - 'mobile/ios/**' - 'mobile/pubspec.yaml' - '.github/workflows/flutter-build.yml' + workflow_call: workflow_dispatch: permissions: diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cb4fa2591..6e9f77b3f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -39,7 +39,8 @@ env: IMAGE_NAME: ${{ github.repository }} permissions: - contents: read + contents: write + packages: write jobs: ci: @@ -239,3 +240,157 @@ jobs: echo "Push failed (attempt $attempts). Retrying in ${delay} seconds..." sleep ${delay} done + + mobile: + name: Build Mobile Apps + if: startsWith(github.ref, 'refs/tags/v') + uses: ./.github/workflows/flutter-build.yml + secrets: inherit + + release: + name: Create GitHub Release + if: startsWith(github.ref, 'refs/tags/v') + needs: [merge, mobile] + runs-on: ubuntu-latest + timeout-minutes: 10 + + permissions: + contents: write + + steps: + - name: Download Android APK artifact + uses: actions/download-artifact@v4.3.0 + with: + name: app-release-apk + path: ${{ runner.temp }}/mobile-artifacts + + - name: Download iOS build artifact + uses: actions/download-artifact@v4.3.0 + with: + name: ios-build-unsigned + path: ${{ runner.temp }}/ios-build + + - name: Prepare release assets + run: | + mkdir -p ${{ runner.temp }}/release-assets + + # Copy debug APK if it exists + if [ -f "${{ runner.temp }}/mobile-artifacts/app-debug.apk" ]; then + cp "${{ runner.temp }}/mobile-artifacts/app-debug.apk" "${{ runner.temp }}/release-assets/sure-${{ github.ref_name }}-debug.apk" + echo "✓ Debug APK prepared" + fi + + # Copy release APK if it exists + if [ -f "${{ runner.temp }}/mobile-artifacts/app-release.apk" ]; then + cp "${{ runner.temp }}/mobile-artifacts/app-release.apk" "${{ runner.temp }}/release-assets/sure-${{ github.ref_name }}.apk" + echo "✓ Release APK prepared" + fi + + # Create iOS app archive (zip the .app bundle) + if [ -d "${{ runner.temp }}/ios-build/Runner.app" ]; then + cd "${{ runner.temp }}/ios-build" + zip -r "${{ runner.temp }}/release-assets/sure-${{ github.ref_name }}-ios-unsigned.zip" Runner.app + echo "✓ iOS build archive prepared" + fi + + # Copy iOS build info + if [ -f "${{ runner.temp }}/ios-build/ios-build-info.txt" ]; then + cp "${{ runner.temp }}/ios-build/ios-build-info.txt" "${{ runner.temp }}/release-assets/" + fi + + echo "Release assets:" + ls -la "${{ runner.temp }}/release-assets/" + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ github.ref_name }} + name: ${{ github.ref_name }} + draft: false + prerelease: ${{ contains(github.ref_name, 'alpha') || contains(github.ref_name, 'beta') || contains(github.ref_name, 'rc') }} + generate_release_notes: true + files: | + ${{ runner.temp }}/release-assets/* + body: | + ## Mobile Debug Builds + + This release includes debug builds of the mobile applications: + + - **Android APK**: Debug build for testing on Android devices + - **iOS Build**: Unsigned iOS build (requires code signing for installation) + + > **Note**: These are debug builds intended for testing purposes. For production use, please build from source with proper signing credentials. + + bump-alpha-version: + name: Bump Alpha Version + if: startsWith(github.ref, 'refs/tags/v') && contains(github.ref_name, 'alpha') + needs: [merge] + runs-on: ubuntu-latest + timeout-minutes: 10 + + permissions: + contents: write + + steps: + - name: Check out main branch + uses: actions/checkout@v4.2.0 + with: + ref: main + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Bump alpha version + run: | + VERSION_FILE="config/initializers/version.rb" + + # Ensure version file exists + if [ ! -f "$VERSION_FILE" ]; then + echo "ERROR: Version file not found: $VERSION_FILE" + exit 1 + fi + + # Extract current version + CURRENT_VERSION=$(grep -oP '"\K[0-9]+\.[0-9]+\.[0-9]+-alpha\.[0-9]+' "$VERSION_FILE") + if [ -z "$CURRENT_VERSION" ]; then + echo "ERROR: Could not extract version from $VERSION_FILE" + exit 1 + fi + echo "Current version: $CURRENT_VERSION" + + # Extract the alpha number and increment it + ALPHA_NUM=$(echo "$CURRENT_VERSION" | grep -oP 'alpha\.\K[0-9]+') + if [ -z "$ALPHA_NUM" ]; then + echo "ERROR: Could not extract alpha number from $CURRENT_VERSION" + exit 1 + fi + NEW_ALPHA_NUM=$((ALPHA_NUM + 1)) + + # Create new version string + BASE_VERSION=$(echo "$CURRENT_VERSION" | grep -oP '^[0-9]+\.[0-9]+\.[0-9]+') + if [ -z "$BASE_VERSION" ]; then + echo "ERROR: Could not extract base version from $CURRENT_VERSION" + exit 1 + fi + NEW_VERSION="${BASE_VERSION}-alpha.${NEW_ALPHA_NUM}" + echo "New version: $NEW_VERSION" + + - name: Commit and push version bump + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + git add config/initializers/version.rb + git commit -m "Bump version to next alpha after ${{ github.ref_name }} release" + + # Push with retry logic + attempts=0 + until git push origin main; do + attempts=$((attempts + 1)) + if [[ $attempts -ge 4 ]]; then + echo "ERROR: Failed to push after 4 attempts." >&2 + exit 1 + fi + delay=$((2 ** attempts)) + echo "Push failed (attempt $attempts). Retrying in ${delay} seconds..." + sleep ${delay} + git pull --rebase origin main + done