Skip to content

Update version from AppFlowy-IO/AppFlowy-Premium/main #30

Update version from AppFlowy-IO/AppFlowy-Premium/main

Update version from AppFlowy-IO/AppFlowy-Premium/main #30

name: Update Version from AppFlowy Premium
run-name: Update version from ${{ github.event.inputs.repo }}/${{ github.event.inputs.branch }}
on:
workflow_dispatch:
inputs:
repo:
description: "Source repository for version"
required: true
default: "AppFlowy-IO/AppFlowy-Premium"
type: string
branch:
description: "Source branch for version"
required: true
default: "main"
type: string
create_pr:
description: "Create a pull request with the changes"
required: false
default: true
type: boolean
jobs:
update-version:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Builder Repository
uses: actions/checkout@v4
with:
token: ${{ secrets.BUILDER_GITHUB_TOKEN }}
- name: Fetch pubspec.yaml from AppFlowy Premium
id: fetch_version
run: |
set -euo pipefail
echo "πŸ“₯ Fetching pubspec.yaml from ${{ inputs.repo }}/${{ inputs.branch }}"
# Fetch the pubspec.yaml file from the source repository
HTTP_CODE=$(curl -s -w "%{http_code}" -o pubspec.yaml \
-H "Authorization: token ${{ secrets.PRIVATE_REPO_TOKEN }}" \
-H "Accept: application/vnd.github.v3.raw" \
"https://api.github.com/repos/${{ inputs.repo }}/contents/frontend/appflowy_flutter/pubspec.yaml?ref=${{ inputs.branch }}")
if [ "$HTTP_CODE" != "200" ]; then
echo "❌ Failed to fetch pubspec.yaml (HTTP $HTTP_CODE)"
exit 1
fi
if [ ! -f pubspec.yaml ] || [ ! -s pubspec.yaml ]; then
echo "❌ pubspec.yaml is missing or empty"
exit 1
fi
# Extract version from pubspec.yaml
# Format: version: X.Y.Z+build_number
VERSION=$(grep -E '^version:' pubspec.yaml | sed -E 's/^version:[[:space:]]*([0-9]+\.[0-9]+\.[0-9]+).*/\1/')
if [ -z "$VERSION" ]; then
echo "❌ Failed to extract version from pubspec.yaml"
cat pubspec.yaml
exit 1
fi
# Validate version format (X.Y.Z)
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "❌ Invalid version format: $VERSION (expected X.Y.Z)"
exit 1
fi
echo "πŸ“¦ Extracted version: $VERSION"
# Parse version components (X.Y.Z)
MAJOR=$(echo $VERSION | cut -d. -f1)
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
# Validate version components are numbers
if ! [[ "$MAJOR" =~ ^[0-9]+$ ]] || ! [[ "$MINOR" =~ ^[0-9]+$ ]] || ! [[ "$PATCH" =~ ^[0-9]+$ ]]; then
echo "❌ Invalid version components: major=$MAJOR, minor=$MINOR, patch=$PATCH"
exit 1
fi
echo "πŸ”’ Version components: major=$MAJOR, minor=$MINOR, patch=$PATCH"
# Calculate Android build number: 29[minor][patch]01
# Format: 29 + (minor padded to 2 digits) + (patch padded to 2 digits) + 01
ANDROID_BUILD_NUMBER=$(printf "29%02d%02d01" $MINOR $PATCH)
echo "πŸ“± Android build number: $ANDROID_BUILD_NUMBER"
# Save outputs
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "android_build_number=$ANDROID_BUILD_NUMBER" >> $GITHUB_OUTPUT
# Clean up
rm pubspec.yaml
- name: Update Workflow Files
id: update_files
run: |
set -euo pipefail
VERSION="${{ steps.fetch_version.outputs.version }}"
ANDROID_BUILD_NUMBER="${{ steps.fetch_version.outputs.android_build_number }}"
echo "πŸ”„ Updating workflow files with version $VERSION and Android build number $ANDROID_BUILD_NUMBER"
# Create a list of files to update
FILES=(
".github/workflows/android.yaml"
".github/workflows/ios.yaml"
".github/workflows/macos.yaml"
".github/workflows/windows.yaml"
".github/workflows/linux.yaml"
".github/workflows/release.yml"
)
# Find current version from android.yaml using awk
CURRENT_VERSION=$(awk '/build_name:/{flag=1; next} flag && /default:/{print $2; exit}' .github/workflows/android.yaml | tr -d '"')
if [ -z "$CURRENT_VERSION" ]; then
echo "❌ Error: Could not extract current version from android.yaml"
exit 1
fi
# Validate current version format
if ! echo "$CURRENT_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "⚠️ Warning: Current version has unexpected format: $CURRENT_VERSION"
fi
echo "πŸ“‹ Current version: $CURRENT_VERSION"
echo "πŸ“‹ New version: $VERSION"
# Check if versions are the same
if [ "$CURRENT_VERSION" == "$VERSION" ]; then
echo "ℹ️ Version is already $VERSION, no update needed"
else
# Update version in all workflow files
for file in "${FILES[@]}"; do
if [ -f "$file" ]; then
echo " Updating $file..."
# Use sed with literal string replacement
sed -i "s/default: \"$CURRENT_VERSION\"/default: \"$VERSION\"/g" "$file"
fi
done
# Update hardcoded values in release.yml
if [ -f ".github/workflows/release.yml" ]; then
echo " Updating hardcoded values in release.yml..."
# Update run-name fallback value
sed -i "s/\${{ github.event.inputs.version || '$CURRENT_VERSION' }}/\${{ github.event.inputs.version || '$VERSION' }}/g" .github/workflows/release.yml
# Update scheduled trigger VERSION
sed -i "s/VERSION=\"$CURRENT_VERSION\"/VERSION=\"$VERSION\"/g" .github/workflows/release.yml
fi
fi
# Update Android build number specifically in android.yaml
echo "πŸ“± Updating Android build number in android.yaml..."
CURRENT_ANDROID_BUILD=$(awk '/build_number:/{flag=1; next} flag && /default:/{print $2; exit}' .github/workflows/android.yaml | tr -d '"')
if [ -z "$CURRENT_ANDROID_BUILD" ]; then
echo "❌ Error: Could not extract current Android build number"
exit 1
fi
echo " Current Android build number: $CURRENT_ANDROID_BUILD"
echo " New Android build number: $ANDROID_BUILD_NUMBER"
if [ "$CURRENT_ANDROID_BUILD" == "$ANDROID_BUILD_NUMBER" ]; then
echo "ℹ️ Android build number is already $ANDROID_BUILD_NUMBER, no update needed"
else
sed -i "s/default: \"$CURRENT_ANDROID_BUILD\"/default: \"$ANDROID_BUILD_NUMBER\"/" .github/workflows/android.yaml
fi
echo "βœ… All files updated successfully"
- name: Check for Changes
id: check_changes
run: |
if git diff --quiet; then
echo "ℹ️ No changes detected"
echo "has_changes=false" >> $GITHUB_OUTPUT
else
echo "βœ… Changes detected"
echo "has_changes=true" >> $GITHUB_OUTPUT
echo ""
echo "πŸ“ Changed files:"
git diff --name-only
fi
- name: Show Diff
if: steps.check_changes.outputs.has_changes == 'true'
run: |
echo "πŸ“Š Diff of changes:"
git diff
- name: Create Pull Request
if: steps.check_changes.outputs.has_changes == 'true' && inputs.create_pr == true
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.BUILDER_GITHUB_TOKEN }}
commit-message: |
chore: update version to ${{ steps.fetch_version.outputs.version }}
- Update all workflow files to version ${{ steps.fetch_version.outputs.version }}
- Update Android build number to ${{ steps.fetch_version.outputs.android_build_number }}
Source: ${{ inputs.repo }}@${{ inputs.branch }}
branch: update-version-${{ steps.fetch_version.outputs.version }}
delete-branch: true
title: "Update version to ${{ steps.fetch_version.outputs.version }}"
body: |
## Version Update
This PR updates the version across all workflow files.
- **New Version:** `${{ steps.fetch_version.outputs.version }}`
- **Android Build Number:** `${{ steps.fetch_version.outputs.android_build_number }}`
- **Source Repository:** `${{ inputs.repo }}`
- **Source Branch:** `${{ inputs.branch }}`
### Changed Files
- `.github/workflows/android.yaml`
- `.github/workflows/ios.yaml`
- `.github/workflows/macos.yaml`
- `.github/workflows/windows.yaml`
- `.github/workflows/linux.yaml`
- `.github/workflows/release.yml`
### Android Build Number Calculation
The Android build number follows the pattern: `29[minor][patch]01`
- For version `${{ steps.fetch_version.outputs.version }}`: `${{ steps.fetch_version.outputs.android_build_number }}`
- name: Commit Changes Directly
if: steps.check_changes.outputs.has_changes == 'true' && inputs.create_pr == false
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .github/workflows/*.yaml .github/workflows/*.yml
git commit -m "chore: update version to ${{ steps.fetch_version.outputs.version }}
- Update all workflow files to version ${{ steps.fetch_version.outputs.version }}
- Update Android build number to ${{ steps.fetch_version.outputs.android_build_number }}
Source: ${{ inputs.repo }}@${{ inputs.branch }}"
git push
- name: Summary
if: always()
run: |
echo "## πŸ“Š Version Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ steps.fetch_version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Android Build Number:** ${{ steps.fetch_version.outputs.android_build_number }}" >> $GITHUB_STEP_SUMMARY
echo "- **Source:** ${{ inputs.repo }}@${{ inputs.branch }}" >> $GITHUB_STEP_SUMMARY
echo "- **Changes Detected:** ${{ steps.check_changes.outputs.has_changes }}" >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.create_pr }}" == "true" ]; then
echo "- **Action:** Pull request created" >> $GITHUB_STEP_SUMMARY
else
echo "- **Action:** Changes committed directly" >> $GITHUB_STEP_SUMMARY
fi