blob: ea6b786c74fbe10f21fe0409cbb8efbf8f3a5462 [file] [log] [blame] [edit]
name: Sync Engine Version
on:
workflow_dispatch:
jobs:
sync-engine:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
with:
repository: flutteractionsbot/flutter
token: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }}
ref: master
- name: Configure git
env:
GH_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }}
run: |
git config user.name "flutteractionsbot"
git config user.email "<flutter-actions-bot@google.com>"
git remote add upstream https://github.com/flutter/flutter.git
git fetch upstream ${{ github.ref_name }}
BRANCH_NAME="update-engine-$(date +%s)"
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
git checkout -b "$BRANCH_NAME" upstream/${{ github.ref_name }}
- name: Generate and Capture Hash
id: generate-hash
run: |
# Capture the OLD hash (handle case where file doesn't exist)
if [ -f bin/internal/engine.version ]; then
OLD_HASH=$(< bin/internal/engine.version)
else
OLD_HASH="None (New File)"
fi
echo "OLD_HASH=$OLD_HASH" >> $GITHUB_ENV
chmod +x bin/internal/last_engine_commit.sh
NEW_HASH=$(./bin/internal/last_engine_commit.sh)
echo "$NEW_HASH" > bin/internal/engine.version
echo "ENGINE_HASH=$NEW_HASH" >> $GITHUB_ENV
- name: Check for Changes
id: git-check
run: |
# -N (intent-to-add) treats untracked files as existing but empty
# -f adds even if it's in the .gitignore (which it usually is)
git add -N -f bin/internal/engine.version
if git diff --cached --exit-code bin/internal/engine.version; then
echo "changed=false" >> $GITHUB_OUTPUT
# Nice big No-Op Summary
echo "## ✅ Engine version already up to date" >> $GITHUB_STEP_SUMMARY
echo "The engine is already at hash \`${{ env.ENGINE_HASH }}\`. No PR was created." >> $GITHUB_STEP_SUMMARY
else
echo "changed=true" >> $GITHUB_OUTPUT
fi
- name: Create PR if Changed
if: steps.git-check.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.FLUTTERACTIONSBOT_CP_TOKEN }}
run: |
git commit -m "Update engine.version to ${{ env.ENGINE_HASH }}"
git push origin "$BRANCH_NAME"
# Capture the PR URL
PR_URL=$(gh pr create \
--title "[${{ github.ref_name }}] Sync engine.version to ${{ env.ENGINE_HASH }}" \
--body "Updates the engine.version file from \`${{ env.OLD_HASH }}\` to \`${{ env.ENGINE_HASH }}\`." \
--repo flutter/flutter \
--base ${{ github.ref_name }} \
--head flutteractionsbot:$BRANCH_NAME)
# Nice big PR Success Summary
echo "## 🚀 PR Created Successfully" >> $GITHUB_STEP_SUMMARY
echo "Updated engine version from \`${{ env.OLD_HASH }}\` to \`${{ env.ENGINE_HASH }}\`." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "🔗 **View Pull Request:** $PR_URL" >> $GITHUB_STEP_SUMMARY