-
Notifications
You must be signed in to change notification settings - Fork 124
Add workflow to automatically update iOS and Android dependencies. #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
e61fc2f
Add placeholder workflow for updating dependencies.
jonsimantov 916ddf0
Add placeholder job to placeholder workflow.
jonsimantov 7c7d516
Fix format.
jonsimantov 54a6b94
Fix format again
jonsimantov 32ee75d
Check out the repo and create a branch.
jonsimantov f1ac55c
Update iOS and Android dependencies, and (don't yet) push.
jonsimantov e3314ec
Set up Python prereqs.
jonsimantov 5de7981
Install prereqs
jonsimantov 92f1746
Install additional prereq
jonsimantov d3f428a
Add script for creating PR.
jonsimantov 08a6323
Create PR and trigger tests on it.
jonsimantov 311152a
Fix format
jonsimantov fc3eafd
Fix quotes.
jonsimantov 8d914e2
Streamline workflow and fix conditionals.
jonsimantov 63c06c5
Clean up logging, and actually commit this time.
jonsimantov b371054
Add timestamp to branch name.
jonsimantov 7f0a0c9
Set commit email and CLA=yes.
jonsimantov 30bf314
Remove 'base' from req flags
jonsimantov af96f69
Capture pull request number that was created.
jonsimantov 2aa5ba9
Allow integration tests triggered by firebase-workflow-trigger.
jonsimantov 9b79d38
Remove unneeded check.
jonsimantov 45b5da6
Remove cla: yes label; this will be fixed via a different method.
jonsimantov e59a583
Merge remote-tracking branch 'origin/main' into feature/auto-update-d…
jonsimantov 91b865a
Fix lint workflow issue.
jonsimantov e23a2d2
Change commit to use bot address.
jonsimantov d1ca3e1
Change timestamps to Pacific time.
jonsimantov e89998c
Undo time zone change.
jonsimantov ec4be1c
Fix email address.
jonsimantov 9ad3edb
Change commit name to firebase-workflow-trigger-bot
jonsimantov a15dbcf
Make sure to use original ref of workflow for scripts.
jonsimantov 9ac08d1
Use the sha instead of the ref.
jonsimantov cc9a914
Factor out commit title and body.
jonsimantov aaca011
Add logging to update script.
jonsimantov 068be4e
Update log file
jonsimantov 841efd6
Add verbose log of versions that were changed.
jonsimantov 1c1dcef
Fix bash error.
jonsimantov 783f6af
Fix log message.
jonsimantov 54cfa04
Fix logfile.
jonsimantov 8819c7b
Clean up the output a bit.
jonsimantov 7cd44f0
Fix spacing.
jonsimantov fb9c3d3
Change output format
jonsimantov e832511
Fix git comment.
jonsimantov d29db61
Fix commit log.
jonsimantov add6b3b
Restore Android dependencies file.
jonsimantov e116bb7
Fix formatting and other issues.
jonsimantov c3cb955
Add workflow name to comment.
jonsimantov 2d1960c
Change "Android and iOS" PR title to just "mobile"
jonsimantov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,137 @@ | ||
name: Update Android and iOS dependencies (placeholder) | ||
name: Update Android and iOS dependencies | ||
on: | ||
workflow_dispatch: | ||
inputs: | ||
updateAndroid: | ||
description: 'update Android dependencies?' | ||
default: 1 | ||
updateiOS: | ||
description: 'update iOS dependencies?' | ||
default: 1 | ||
triggerTests: | ||
description: 'trigger tests on PR?' | ||
default: 1 | ||
baseBranch: | ||
description: 'create the new branch from this base' | ||
default: 'main' | ||
|
||
env: | ||
branchPrefix: "workflow/auto-update-deps-" | ||
triggerTestsLabel: "tests-requested: quick" | ||
|
||
jobs: | ||
update_dependencies: | ||
name: update-dependencies | ||
name: update-deps | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Placeholder step | ||
- name: Get token for firebase-workflow-trigger | ||
uses: tibdex/github-app-token@v1 | ||
id: generate-token | ||
with: | ||
app_id: ${{ secrets.WORKFLOW_TRIGGER_APP_ID }} | ||
private_key: ${{ secrets.WORKFLOW_TRIGGER_APP_PRIVATE_KEY }} | ||
|
||
- name: Setup python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.7 | ||
|
||
- name: Check out base branch | ||
uses: actions/[email protected] | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.inputs.baseBranch }} | ||
|
||
- name: Install prerequisites | ||
run: | | ||
python scripts/gha/install_prereqs_desktop.py | ||
python -m pip install requests | ||
- name: Name new branch | ||
run: | | ||
date_str=$(date "+%Y%m%d-%H%M%S") | ||
echo "NEW_BRANCH=${{env.branchPrefix}}${{github.run_number}}-${date_str}" >> $GITHUB_ENV | ||
- name: Create new branch | ||
run: | | ||
true | ||
git remote update | ||
git checkout -b "${NEW_BRANCH}" | ||
echo "UPDATE_LOGFILE=update_log.txt" >> $GITHUB_ENV | ||
- name: Run update script | ||
run: | | ||
if [[ ${{ github.event.inputs.updateiOS }} -eq 1 ]]; then | ||
if [[ ${{ github.event.inputs.updateAndroid }} -eq 1 ]]; then | ||
# Update both | ||
echo "Updating all dependencies" | ||
python scripts/update_android_ios_dependencies.py --logfile=${UPDATE_LOGFILE} | ||
echo "CHOSEN_DEPS=mobile" >> $GITHUB_ENV | ||
else | ||
# Update iOS only | ||
echo "Updating iOS dependencies only" | ||
python scripts/update_android_ios_dependencies.py --skip_android --logfile=${UPDATE_LOGFILE} | ||
echo "CHOSEN_DEPS=iOS" >> $GITHUB_ENV | ||
fi | ||
# iOS: Update Firestore external version to match Firestore Cocoapod version. | ||
firestore_version=$(grep "pod 'Firebase/Firestore'" ios_pod/Podfile | sed "s/.*'\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)'.*/\1/") | ||
sed -i~ "s/^set(version [^)]*)/set(version CocoaPods-${firestore_version})/i" cmake/external/firestore.cmake | ||
elif [[ ${{ github.event.inputs.updateAndroid }} -eq 1 ]]; then | ||
# Update Android only | ||
echo "Updating Android dependencies only" | ||
python scripts/update_android_ios_dependencies.py --skip_ios --logfile=${UPDATE_LOGFILE} | ||
echo "CHOSEN_DEPS=Android" >> $GITHUB_ENV | ||
else | ||
echo "::error ::Neither Android nor iOS selected. Exiting." | ||
exit 1 | ||
fi | ||
jonsimantov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- name: Push branch if there are changes | ||
id: push-branch | ||
run: | | ||
if ! git update-index --refresh; then | ||
# Do a bit of post-processing on the update log to split it by platform. | ||
UPDATE_LOGFILE_PROCESSED=update_log_processed.txt | ||
if grep -q ^Android: "${UPDATE_LOGFILE}"; then | ||
echo "### Android" >> "${UPDATE_LOGFILE_PROCESSED}" | ||
echo "" >> "${UPDATE_LOGFILE_PROCESSED}" | ||
sed 's/^Android: /- /' ${UPDATE_LOGFILE} >> ${UPDATE_LOGFILE_PROCESSED} | ||
echo "" >> "${UPDATE_LOGFILE_PROCESSED}" | ||
fi | ||
if grep -q ^iOS: "${UPDATE_LOGFILE}"; then | ||
echo "### iOS" >> "${UPDATE_LOGFILE_PROCESSED}" | ||
echo "" >> "${UPDATE_LOGFILE_PROCESSED}" | ||
sed 's/^iOS: /- /' ${UPDATE_LOGFILE} >> ${UPDATE_LOGFILE_PROCESSED} | ||
echo "" >> "${UPDATE_LOGFILE_PROCESSED}" | ||
fi | ||
date_str=$(date "+%a %b %d %Y") | ||
commit_title="Update ${CHOSEN_DEPS} dependencies - ${date_str}" | ||
commit_body="$(cat ${UPDATE_LOGFILE_PROCESSED}) | ||
> Created by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID)." | ||
git config user.email "[email protected]" | ||
git config user.name "firebase-workflow-trigger-bot" | ||
git config core.commentChar "%" # so we can use # in git commit messages | ||
git commit -a -m "${commit_title} | ||
${commit_body}" | ||
echo "::set-output name=branch_pushed::1" | ||
# Show changes in git log | ||
git diff | ||
# Push branch | ||
git push --set-upstream origin "${NEW_BRANCH}" | ||
# Create pull request | ||
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}") | ||
echo "::set-output name=created_pr_number::${pr_number}" | ||
else | ||
echo "::warning ::No changes detected, won't create pull request." | ||
echo "::set-output name=branch_pushed::0" | ||
fi | ||
- name: Set test trigger label. | ||
uses: actions-ecosystem/action-add-labels@v1 | ||
if: ${{ github.event.inputs.triggerTests == 1 && steps.push-branch.outputs.branch_pushed == 1 }} | ||
with: | ||
github_token: ${{ steps.generate-token.outputs.token }} | ||
number: ${{ steps.push-branch.outputs.created_pr_number }} | ||
labels: "${{ env.triggerTestsLabel }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright 2021 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A utility to create pull requests. | ||
USAGE: | ||
python scripts/gha/create_pull_request.py \ | ||
--token ${{github.token}} \ | ||
--head pr_branch \ | ||
--base main \ | ||
--title 'Title of the pull request' \ | ||
[--body 'Body text for the pull request'] | ||
Creates the pull request, and outputs the new PR number to stdout. | ||
""" | ||
|
||
import datetime | ||
import shutil | ||
|
||
from absl import app | ||
from absl import flags | ||
from absl import logging | ||
|
||
import github | ||
|
||
FLAGS = flags.FLAGS | ||
jonsimantov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_DEFAULT_MESSAGE = "Creating pull request." | ||
|
||
flags.DEFINE_string( | ||
"token", None, | ||
"github.token: A token to authenticate on your repository.") | ||
|
||
flags.DEFINE_string( | ||
"head", None, | ||
"Head branch name.") | ||
|
||
flags.DEFINE_string( | ||
"base", "main", | ||
"Base branch name.") | ||
|
||
flags.DEFINE_string( | ||
"title", None, | ||
"Title for the pull request.") | ||
|
||
flags.DEFINE_string( | ||
"body", "", | ||
"Body text for the pull request.") | ||
|
||
def main(argv): | ||
if len(argv) > 1: | ||
raise app.UsageError("Too many command-line arguments.") | ||
if github.create_pull_request(FLAGS.token, FLAGS.head, FLAGS.base, FLAGS.title, FLAGS.body, True): | ||
# Find the most recent pull_request with the given base and head, that's ours. | ||
pull_requests = github.list_pull_requests(FLAGS.token, "open", FLAGS.head, FLAGS.base) | ||
print(pull_requests[0]['number']) | ||
else: | ||
exit(1) | ||
|
||
|
||
if __name__ == "__main__": | ||
flags.mark_flag_as_required("token") | ||
flags.mark_flag_as_required("head") | ||
flags.mark_flag_as_required("title") | ||
app.run(main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.