|
| 1 | +name: Flutter Upgrade Check |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + - cron: "0 0 * * 1" |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +jobs: |
| 9 | + check-flutter-upgrade: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout repository |
| 14 | + uses: actions/checkout@v5 |
| 15 | + |
| 16 | + - name: Read Flutter version from pubspec.yaml |
| 17 | + id: read-version |
| 18 | + run: | |
| 19 | + FLUTTER_VERSION=$(yq '.environment.flutter' pubspec.yaml) |
| 20 | + echo "Current Flutter version: $FLUTTER_VERSION" |
| 21 | + echo "flutter_version=$FLUTTER_VERSION" >> $GITHUB_ENV |
| 22 | +
|
| 23 | + - name: Get latest stable Flutter version |
| 24 | + id: check-latest |
| 25 | + run: | |
| 26 | + LATEST_VERSION=$(curl -s https://storage.googleapis.com/flutter_infra_release/releases/releases_linux.json | jq -r '.releases[] | select(.channel == "stable") | .version' | head -n 1) |
| 27 | + echo "Latest stable Flutter version: $LATEST_VERSION" |
| 28 | + echo "latest_flutter_version=$LATEST_VERSION" >> $GITHUB_ENV |
| 29 | +
|
| 30 | + - name: Compare versions and update pubspec.yaml if needed |
| 31 | + id: update-version |
| 32 | + run: | |
| 33 | + if [ "$flutter_version" != "$latest_flutter_version" ]; then |
| 34 | + echo "Updating Flutter version in pubspec.yaml..." |
| 35 | + sed -i "s/flutter:\s*'${flutter_version}'/flutter: '${latest_flutter_version}'/" pubspec.yaml |
| 36 | + git --no-pager diff |
| 37 | + echo "update_needed=true" >> $GITHUB_ENV |
| 38 | + else |
| 39 | + echo "Flutter is up to date." |
| 40 | + echo "update_needed=false" >> $GITHUB_ENV |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Commit and create PR if update is needed |
| 44 | + if: env.update_needed == 'true' |
| 45 | + env: |
| 46 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + run: | |
| 48 | + git config --global user.name "dependabot[bot]" |
| 49 | + git config --global user.email "49699333+dependabot[bot]@users.noreply.github.com" |
| 50 | +
|
| 51 | + BRANCH_NAME="flutter-upgrade-${{ env.latest_flutter_version }}" |
| 52 | + git checkout -b $BRANCH_NAME |
| 53 | + git add pubspec.yaml |
| 54 | + git commit -m "chore: Upgrade Flutter to ${{ env.latest_flutter_version }}" |
| 55 | + git push origin -f $BRANCH_NAME |
| 56 | +
|
| 57 | + PR_URL=$(gh pr create --title "chore(deps): upgrade Flutter to ${{ env.latest_flutter_version }}" \ |
| 58 | + --body "This PR updates Flutter version in pubspec.yaml to the latest stable release." \ |
| 59 | + --base development \ |
| 60 | + --head $BRANCH_NAME) |
0 commit comments