|
1 |
| -name: Update Android and iOS dependencies (placeholder) |
| 1 | +name: Update Android and iOS dependencies |
2 | 2 | on:
|
3 | 3 | workflow_dispatch:
|
4 | 4 | inputs:
|
| 5 | + updateAndroid: |
| 6 | + description: 'update Android dependencies?' |
| 7 | + default: 1 |
| 8 | + updateiOS: |
| 9 | + description: 'update iOS dependencies?' |
| 10 | + default: 1 |
| 11 | + triggerTests: |
| 12 | + description: 'trigger tests on PR?' |
| 13 | + default: 1 |
| 14 | + baseBranch: |
| 15 | + description: 'create the new branch from this base' |
| 16 | + default: 'main' |
| 17 | + |
| 18 | +env: |
| 19 | + branchPrefix: "workflow/auto-update-deps-" |
| 20 | + triggerTestsLabel: "tests-requested: quick" |
5 | 21 |
|
6 | 22 | jobs:
|
7 | 23 | update_dependencies:
|
8 |
| - name: update-dependencies |
| 24 | + name: update-deps |
9 | 25 | runs-on: ubuntu-latest
|
10 | 26 | steps:
|
11 |
| - - name: Placeholder step |
| 27 | + - name: Get token for firebase-workflow-trigger |
| 28 | + uses: tibdex/github-app-token@v1 |
| 29 | + id: generate-token |
| 30 | + with: |
| 31 | + app_id: ${{ secrets.WORKFLOW_TRIGGER_APP_ID }} |
| 32 | + private_key: ${{ secrets.WORKFLOW_TRIGGER_APP_PRIVATE_KEY }} |
| 33 | + |
| 34 | + - name: Setup python |
| 35 | + uses: actions/setup-python@v2 |
| 36 | + with: |
| 37 | + python-version: 3.7 |
| 38 | + |
| 39 | + - name: Check out base branch |
| 40 | + |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + ref: ${{ github.event.inputs.baseBranch }} |
| 44 | + |
| 45 | + - name: Install prerequisites |
| 46 | + run: | |
| 47 | + python scripts/gha/install_prereqs_desktop.py |
| 48 | + python -m pip install requests |
| 49 | +
|
| 50 | + - name: Name new branch |
| 51 | + run: | |
| 52 | + date_str=$(date "+%Y%m%d-%H%M%S") |
| 53 | + echo "NEW_BRANCH=${{env.branchPrefix}}${{github.run_number}}-${date_str}" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + - name: Create new branch |
12 | 56 | run: |
|
13 |
| - true |
| 57 | + git remote update |
| 58 | + git checkout -b "${NEW_BRANCH}" |
| 59 | + echo "UPDATE_LOGFILE=update_log.txt" >> $GITHUB_ENV |
| 60 | +
|
| 61 | + - name: Run update script |
| 62 | + run: | |
| 63 | + if [[ ${{ github.event.inputs.updateiOS }} -eq 1 ]]; then |
| 64 | + if [[ ${{ github.event.inputs.updateAndroid }} -eq 1 ]]; then |
| 65 | + # Update both |
| 66 | + echo "Updating all dependencies" |
| 67 | + python scripts/update_android_ios_dependencies.py --logfile=${UPDATE_LOGFILE} |
| 68 | + echo "CHOSEN_DEPS=mobile" >> $GITHUB_ENV |
| 69 | + else |
| 70 | + # Update iOS only |
| 71 | + echo "Updating iOS dependencies only" |
| 72 | + python scripts/update_android_ios_dependencies.py --skip_android --logfile=${UPDATE_LOGFILE} |
| 73 | + echo "CHOSEN_DEPS=iOS" >> $GITHUB_ENV |
| 74 | + fi |
| 75 | + # iOS: Update Firestore external version to match Firestore Cocoapod version. |
| 76 | + firestore_version=$(grep "pod 'Firebase/Firestore'" ios_pod/Podfile | sed "s/.*'\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)'.*/\1/") |
| 77 | + sed -i~ "s/^set(version [^)]*)/set(version CocoaPods-${firestore_version})/i" cmake/external/firestore.cmake |
| 78 | + elif [[ ${{ github.event.inputs.updateAndroid }} -eq 1 ]]; then |
| 79 | + # Update Android only |
| 80 | + echo "Updating Android dependencies only" |
| 81 | + python scripts/update_android_ios_dependencies.py --skip_ios --logfile=${UPDATE_LOGFILE} |
| 82 | + echo "CHOSEN_DEPS=Android" >> $GITHUB_ENV |
| 83 | + else |
| 84 | + echo "::error ::Neither Android nor iOS selected. Exiting." |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +
|
| 88 | + - name: Push branch if there are changes |
| 89 | + id: push-branch |
| 90 | + run: | |
| 91 | + if ! git update-index --refresh; then |
| 92 | + # Do a bit of post-processing on the update log to split it by platform. |
| 93 | + UPDATE_LOGFILE_PROCESSED=update_log_processed.txt |
| 94 | + if grep -q ^Android: "${UPDATE_LOGFILE}"; then |
| 95 | + echo "### Android" >> "${UPDATE_LOGFILE_PROCESSED}" |
| 96 | + echo "" >> "${UPDATE_LOGFILE_PROCESSED}" |
| 97 | + sed 's/^Android: /- /' ${UPDATE_LOGFILE} >> ${UPDATE_LOGFILE_PROCESSED} |
| 98 | + echo "" >> "${UPDATE_LOGFILE_PROCESSED}" |
| 99 | + fi |
| 100 | + if grep -q ^iOS: "${UPDATE_LOGFILE}"; then |
| 101 | + echo "### iOS" >> "${UPDATE_LOGFILE_PROCESSED}" |
| 102 | + echo "" >> "${UPDATE_LOGFILE_PROCESSED}" |
| 103 | + sed 's/^iOS: /- /' ${UPDATE_LOGFILE} >> ${UPDATE_LOGFILE_PROCESSED} |
| 104 | + echo "" >> "${UPDATE_LOGFILE_PROCESSED}" |
| 105 | + fi |
| 106 | +
|
| 107 | + date_str=$(date "+%a %b %d %Y") |
| 108 | + commit_title="Update ${CHOSEN_DEPS} dependencies - ${date_str}" |
| 109 | + commit_body="$(cat ${UPDATE_LOGFILE_PROCESSED}) |
| 110 | +
|
| 111 | + > Created by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)." |
| 112 | + git config user.email "[email protected]" |
| 113 | + git config user.name "firebase-workflow-trigger-bot" |
| 114 | + git config core.commentChar "%" # so we can use # in git commit messages |
| 115 | + git commit -a -m "${commit_title} |
| 116 | +
|
| 117 | + ${commit_body}" |
| 118 | + echo "::set-output name=branch_pushed::1" |
| 119 | + # Show changes in git log |
| 120 | + git diff |
| 121 | + # Push branch |
| 122 | + git push --set-upstream origin "${NEW_BRANCH}" |
| 123 | + # Create pull request |
| 124 | + pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --head "${NEW_BRANCH}" --base "${{ github.event.inputs.baseBranch }}" --title "${commit_title}" --body "${commit_body}") |
| 125 | + echo "::set-output name=created_pr_number::${pr_number}" |
| 126 | + else |
| 127 | + echo "::warning ::No changes detected, won't create pull request." |
| 128 | + echo "::set-output name=branch_pushed::0" |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Set test trigger label. |
| 132 | + uses: actions-ecosystem/action-add-labels@v1 |
| 133 | + if: ${{ github.event.inputs.triggerTests == 1 && steps.push-branch.outputs.branch_pushed == 1 }} |
| 134 | + with: |
| 135 | + github_token: ${{ steps.generate-token.outputs.token }} |
| 136 | + number: ${{ steps.push-branch.outputs.created_pr_number }} |
| 137 | + labels: "${{ env.triggerTestsLabel }}" |
0 commit comments