From 12ea72338cd044b791995f63b91a15a312b03def Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:20:39 -0700 Subject: [PATCH 01/27] Add workflow for automatically updating feature branches weekly. --- .github/workflows/update-feature-braches.yml | 89 ++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/update-feature-braches.yml diff --git a/.github/workflows/update-feature-braches.yml b/.github/workflows/update-feature-braches.yml new file mode 100644 index 0000000000..9d06467bee --- /dev/null +++ b/.github/workflows/update-feature-braches.yml @@ -0,0 +1,89 @@ +name: Update Android and iOS dependencies +on: + workflow_dispatch: + inputs: + +env: + branchPattern: "feature_branch/*" + mainBranch: "main" + triggerTestsLabel: "tests-requested: quick" + +jobs: + list_feature_branches: + name: list-feature-branches + runs-on: ubuntu-20 + outputs: + branch_list: ${{ steps.get-branches.outputs.branch-list }} + + - name: Check out repo + uses: actions/checkout@v3 + + - name: Get list of feature branches. + id: get-branches + run: | + branch_list=$(git branch --list '${{ env.branchPattern }}' | sed 's/ /,/') + echo ${branch_list} >> $GITHUB_OUTPUT + + create_merge_prs: + name: create-merge-pr-${{ matrix.branch_name }} + needs: [ list_feature_branches ] + runs-on: ubuntu-20 + strategy: + fail-fast: false + matrix: + branch_name: [ ${{ needs.list_feature_branches.branch_list }} ] + steps: + - 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@v4 + with: + python-version: 3.7 + + - uses: actions/checkout@v3 + with: + ref: ${{ matrix.branch_name }} + fetch-depth: 0 + submodules: false + + - name: Install prerequisites + run: | + python scripts/gha/install_prereqs_desktop.py + python -m pip install requests + + - name: Create merge PR + id: create-pr + run: | + # Attempt a merge, then check if any files changed. + git merge --no-commit --no-ff ${{ env.mainBranch }} || true + if git diff --quiet ${{ matrix.branch_name }}; then + # No merge necessary. + echo "::warning ::No merge needed for ${{ matrix.branch_name }}, won't create pull request." + echo "created_pr_number=0" >> $GITHUB_OUTPUT + exit 0 + fi + + # Undo the actual merge. Let the PR creation handle it. + git merge --abort + + date_str=$(date "+%b %d, %Y") + pr_title="Weekly merge of ${{ env.mainBranch }} into ${{ matrix.branch_name }} - ${date_str}" + pr_body="Automatic weekly merge of ${{ env.mainBranch }} into ${{ matrix.branch_name }}. + + > Created on ${date_str} by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID). + " + pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --head "${{ matrix.branch_name }}" --base "${{ env.mainBranch }}" --title "${pr_title}" --body "${pr_body}") + echo "created_pr_number=${pr_number}" >> $GITHUB_OUTPUT + + - name: Set test trigger label. + uses: actions-ecosystem/action-add-labels@v1 + if: ${{ steps.push-branch.outputs.created_pr_number }} + with: + github_token: ${{ steps.generate-token.outputs.token }} + number: ${{ steps.push-branch.outputs.created_pr_number }} + labels: "${{ env.triggerTestsLabel }}" From b8a73c80ab33401275a5a63f029e75d7494c75bd Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:39:48 -0700 Subject: [PATCH 02/27] Corrected filename, and added inputs. --- .github/workflows/update-feature-braches.yml | 89 -------------- .github/workflows/update-feature-branches.yml | 114 ++++++++++++++++++ 2 files changed, 114 insertions(+), 89 deletions(-) delete mode 100644 .github/workflows/update-feature-braches.yml create mode 100644 .github/workflows/update-feature-branches.yml diff --git a/.github/workflows/update-feature-braches.yml b/.github/workflows/update-feature-braches.yml deleted file mode 100644 index 9d06467bee..0000000000 --- a/.github/workflows/update-feature-braches.yml +++ /dev/null @@ -1,89 +0,0 @@ -name: Update Android and iOS dependencies -on: - workflow_dispatch: - inputs: - -env: - branchPattern: "feature_branch/*" - mainBranch: "main" - triggerTestsLabel: "tests-requested: quick" - -jobs: - list_feature_branches: - name: list-feature-branches - runs-on: ubuntu-20 - outputs: - branch_list: ${{ steps.get-branches.outputs.branch-list }} - - - name: Check out repo - uses: actions/checkout@v3 - - - name: Get list of feature branches. - id: get-branches - run: | - branch_list=$(git branch --list '${{ env.branchPattern }}' | sed 's/ /,/') - echo ${branch_list} >> $GITHUB_OUTPUT - - create_merge_prs: - name: create-merge-pr-${{ matrix.branch_name }} - needs: [ list_feature_branches ] - runs-on: ubuntu-20 - strategy: - fail-fast: false - matrix: - branch_name: [ ${{ needs.list_feature_branches.branch_list }} ] - steps: - - 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@v4 - with: - python-version: 3.7 - - - uses: actions/checkout@v3 - with: - ref: ${{ matrix.branch_name }} - fetch-depth: 0 - submodules: false - - - name: Install prerequisites - run: | - python scripts/gha/install_prereqs_desktop.py - python -m pip install requests - - - name: Create merge PR - id: create-pr - run: | - # Attempt a merge, then check if any files changed. - git merge --no-commit --no-ff ${{ env.mainBranch }} || true - if git diff --quiet ${{ matrix.branch_name }}; then - # No merge necessary. - echo "::warning ::No merge needed for ${{ matrix.branch_name }}, won't create pull request." - echo "created_pr_number=0" >> $GITHUB_OUTPUT - exit 0 - fi - - # Undo the actual merge. Let the PR creation handle it. - git merge --abort - - date_str=$(date "+%b %d, %Y") - pr_title="Weekly merge of ${{ env.mainBranch }} into ${{ matrix.branch_name }} - ${date_str}" - pr_body="Automatic weekly merge of ${{ env.mainBranch }} into ${{ matrix.branch_name }}. - - > Created on ${date_str} by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID). - " - pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --head "${{ matrix.branch_name }}" --base "${{ env.mainBranch }}" --title "${pr_title}" --body "${pr_body}") - echo "created_pr_number=${pr_number}" >> $GITHUB_OUTPUT - - - name: Set test trigger label. - uses: actions-ecosystem/action-add-labels@v1 - if: ${{ steps.push-branch.outputs.created_pr_number }} - with: - github_token: ${{ steps.generate-token.outputs.token }} - number: ${{ steps.push-branch.outputs.created_pr_number }} - labels: "${{ env.triggerTestsLabel }}" diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml new file mode 100644 index 0000000000..544c29cf8a --- /dev/null +++ b/.github/workflows/update-feature-branches.yml @@ -0,0 +1,114 @@ +name: Update Android and iOS dependencies +on: + workflow_dispatch: + inputs: + branch_patterns: + description: 'Space-separated list of feature branch patterns' + default: 'feature_branch/*' + required: true + main_branch_: + description: 'Main branch to merge' + default: 'main' + required: true + schedule: + - cron: "0 16 * * 1" # Mondays, 4pm UTC = 9am PST / 10am PDT + +env: + defaultBranchPattern: "feature_branch/*" + defaultMainBranch: "main" + triggerTestsLabel: "tests-requested: quick" + +jobs: + list_feature_branches: + name: list-feature-branches + runs-on: ubuntu-20.04 + outputs: + branch_list: ${{ steps.get-branches.outputs.branch-list }} + + - name: Check out repo (if needed) + if: ${{ github.event.inputs.branch_list == '' }} + uses: actions/checkout@v3 + + - name: Get list of feature branches + id: get-branches + run: | + branch_pattern='${{ env.defaultBranchPattern }}' + if [[ -n ${{ github.event.inputs.branch_patterns }} ]; then + branch_pattern='${{ github.event.inputs.branch_patterns }}' + fi + branch_list=$(git branch --list "${branch_pattern}" | sed 's/ /,/g') + if [[ -n "${branch_list}" ]]; then + # add quotes around each entry + branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g)'"' + fi + echo "::warning ::Branch list: [${branch_list}]" + echo "[${branch_list}]" >> $GITHUB_OUTPUT + + create_merge_prs: + name: create-merge-pr-${{ matrix.branch_name }} + needs: [ list_feature_branches ] + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + branch_name: ${{ fromJson(needs.list_feature_branches.branch_list) }} + steps: + - 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@v4 + with: + python-version: 3.7 + + - uses: actions/checkout@v3 + with: + ref: ${{ matrix.branch_name }} + fetch-depth: 0 + submodules: false + + - name: Install prerequisites + run: | + python scripts/gha/install_prereqs_desktop.py + python -m pip install requests + + - name: Create merge PR + id: create-pr + run: | + main_branch='${{ env.defaultMainBranch }}' + if [[ -n ${{ github.event.inputs.main_branch }} ]; then + main_branch='${{ github.event.inputs.main_branch }}' + fi + # Attempt a merge, then check if any files changed. + git merge --no-commit --no-ff "${main_branch}" || true + if git diff --quiet ${{ matrix.branch_name }}; then + # No merge necessary. + echo "::warning ::No merge needed for ${{ matrix.branch_name }}, won't create pull request." + echo "created_pr_number=0" >> $GITHUB_OUTPUT + exit 0 + fi + + # Undo the actual merge. Let the PR creation handle it. + git merge --abort + + date_str=$(date "+%b %d, %Y") + + pr_title="Automatic merge of ${main_branch} into ${{ matrix.branch_name }} - ${date_str}" + pr_body="Automatic merge of ${main_branch} into ${{ matrix.branch_name }}. + + > Created on ${date_str} by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID). + " + pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --head "${{ matrix.branch_name }}" --base "${main_branch}" --title "${pr_title}" --body "${pr_body}") + echo "created_pr_number=${pr_number}" >> $GITHUB_OUTPUT + + - name: Set test trigger label. + uses: actions-ecosystem/action-add-labels@v1 + if: ${{ steps.push-branch.outputs.created_pr_number }} + with: + github_token: ${{ steps.generate-token.outputs.token }} + number: ${{ steps.push-branch.outputs.created_pr_number }} + labels: "${{ env.triggerTestsLabel }}" From af49149b0a409cd7a03ff920da9408df139f806d Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:40:34 -0700 Subject: [PATCH 03/27] Remove trailing spaces. --- .github/workflows/update-feature-branches.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 544c29cf8a..83b78a1e80 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-20.04 outputs: branch_list: ${{ steps.get-branches.outputs.branch-list }} - + - name: Check out repo (if needed) if: ${{ github.event.inputs.branch_list == '' }} uses: actions/checkout@v3 @@ -89,14 +89,14 @@ jobs: # No merge necessary. echo "::warning ::No merge needed for ${{ matrix.branch_name }}, won't create pull request." echo "created_pr_number=0" >> $GITHUB_OUTPUT - exit 0 + exit 0 fi # Undo the actual merge. Let the PR creation handle it. git merge --abort - + date_str=$(date "+%b %d, %Y") - + pr_title="Automatic merge of ${main_branch} into ${{ matrix.branch_name }} - ${date_str}" pr_body="Automatic merge of ${main_branch} into ${{ matrix.branch_name }}. From 2e2137adedb472e5b598a9bac7da2c34d6f592b3 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:42:36 -0700 Subject: [PATCH 04/27] Fix workflow. --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 83b78a1e80..1820829dae 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-20.04 outputs: branch_list: ${{ steps.get-branches.outputs.branch-list }} - + steps: - name: Check out repo (if needed) if: ${{ github.event.inputs.branch_list == '' }} uses: actions/checkout@v3 From d2a8f3531197c6947edaf105f8ecba45d86dd990 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:45:14 -0700 Subject: [PATCH 05/27] Fix workflow name. --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 1820829dae..8541ede815 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -1,4 +1,4 @@ -name: Update Android and iOS dependencies +name: Update Feature Branches on: workflow_dispatch: inputs: From 98faefbce5891a7b9da1a541194207de0215b121 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:46:11 -0700 Subject: [PATCH 06/27] Fix syntax. --- .github/workflows/update-feature-branches.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 8541ede815..05ffbe04e5 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -33,7 +33,7 @@ jobs: id: get-branches run: | branch_pattern='${{ env.defaultBranchPattern }}' - if [[ -n ${{ github.event.inputs.branch_patterns }} ]; then + if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then branch_pattern='${{ github.event.inputs.branch_patterns }}' fi branch_list=$(git branch --list "${branch_pattern}" | sed 's/ /,/g') @@ -80,7 +80,7 @@ jobs: id: create-pr run: | main_branch='${{ env.defaultMainBranch }}' - if [[ -n ${{ github.event.inputs.main_branch }} ]; then + if [[ -n ${{ github.event.inputs.main_branch }} ]]; then main_branch='${{ github.event.inputs.main_branch }}' fi # Attempt a merge, then check if any files changed. From 41dedd05aac99f510ceb754d57d0dd159edc1cb6 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:47:06 -0700 Subject: [PATCH 07/27] Fix syntax. --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 05ffbe04e5..54576d56f0 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -39,7 +39,7 @@ jobs: branch_list=$(git branch --list "${branch_pattern}" | sed 's/ /,/g') if [[ -n "${branch_list}" ]]; then # add quotes around each entry - branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g)'"' + branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g')'"' fi echo "::warning ::Branch list: [${branch_list}]" echo "[${branch_list}]" >> $GITHUB_OUTPUT From 5bf3fe83d5cf7b109fecaee2165d1cbfc58479cb Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:55:02 -0700 Subject: [PATCH 08/27] List remote branches instead. --- .github/workflows/update-feature-branches.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 54576d56f0..895c0aada6 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -32,17 +32,22 @@ jobs: - name: Get list of feature branches id: get-branches run: | - branch_pattern='${{ env.defaultBranchPattern }}' + branch_pattern='origin/${{ env.defaultBranchPattern }}' if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then - branch_pattern='${{ github.event.inputs.branch_patterns }}' + branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi - branch_list=$(git branch --list "${branch_pattern}" | sed 's/ /,/g') + branch_list=$(git branch --list --remote "${branch_pattern}") + # Remove origin/ from all branches. + branch_list=$(echo "${branch_list}" | sed 's| origin/| |g' | sed 's|^origin/||') + # Change spaces to commas. + branch_list=$(echo "${branch_list}" | sed 's/ /,/g') + if [[ -n "${branch_list}" ]]; then - # add quotes around each entry + # If there's at least one entry, add quotes around each branch name. branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g')'"' fi echo "::warning ::Branch list: [${branch_list}]" - echo "[${branch_list}]" >> $GITHUB_OUTPUT + echo "branch_list=[${branch_list}]" >> $GITHUB_OUTPUT create_merge_prs: name: create-merge-pr-${{ matrix.branch_name }} From 90a3e755f2d4fd66d898781bbfe86eeccaa36391 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:59:24 -0700 Subject: [PATCH 09/27] Clean up script. --- .github/workflows/update-feature-branches.yml | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 895c0aada6..cca9f39dbd 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -32,19 +32,24 @@ jobs: - name: Get list of feature branches id: get-branches run: | - branch_pattern='origin/${{ env.defaultBranchPattern }}' + branch_pattern=origin/'${{ env.defaultBranchPattern }}' if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi + echo "Branch pattern: ${branch_pattern}" branch_list=$(git branch --list --remote "${branch_pattern}") - # Remove origin/ from all branches. - branch_list=$(echo "${branch_list}" | sed 's| origin/| |g' | sed 's|^origin/||') - # Change spaces to commas. - branch_list=$(echo "${branch_list}" | sed 's/ /,/g') - - if [[ -n "${branch_list}" ]]; then - # If there's at least one entry, add quotes around each branch name. + if [[ -n ${branch_list} ]]; then + # If there's at least one entry, process them. + echo "Remote branch list: ${branch_list}" + # Remove origin/ from all branches. + branch_list=$(echo "${branch_list}" | sed 's| origin/| |g' | sed 's|^origin/||') + echo "Local branch list: ${branch_list}" + # Change spaces to commas. + branch_list=$(echo "${branch_list}" | sed 's/ /,/g') + echo "Branch list with commas: ${branch_pattern}" + # Add quotes around each branch name. branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g')'"' + echo "Branch list with quotes: ${branch_pattern}" fi echo "::warning ::Branch list: [${branch_list}]" echo "branch_list=[${branch_list}]" >> $GITHUB_OUTPUT From 601e4cc154ed5753d83e46cae4fba1ef8b3f9438 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 13:59:48 -0700 Subject: [PATCH 10/27] Untab. --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index cca9f39dbd..25c01c34f1 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -47,7 +47,7 @@ jobs: # Change spaces to commas. branch_list=$(echo "${branch_list}" | sed 's/ /,/g') echo "Branch list with commas: ${branch_pattern}" - # Add quotes around each branch name. + # Add quotes around each branch name. branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g')'"' echo "Branch list with quotes: ${branch_pattern}" fi From d63ee2696bb5a5571636c32de8d2b0788102e144 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:00:59 -0700 Subject: [PATCH 11/27] Add branch list for debugging. --- .github/workflows/update-feature-branches.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 25c01c34f1..2c4ab44858 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -36,6 +36,9 @@ jobs: if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi + git remote update + echo "All known branches:" + git branch --list --all echo "Branch pattern: ${branch_pattern}" branch_list=$(git branch --list --remote "${branch_pattern}") if [[ -n ${branch_list} ]]; then From 707b92b20fb6f8e4d549d419598cef3c99a62860 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:03:50 -0700 Subject: [PATCH 12/27] Untab. --- .github/workflows/update-feature-branches.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 2c4ab44858..a10f0c18b4 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -36,9 +36,9 @@ jobs: if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi - git remote update - echo "All known branches:" - git branch --list --all + git remote update + echo "All known branches:" + git branch --list --all echo "Branch pattern: ${branch_pattern}" branch_list=$(git branch --list --remote "${branch_pattern}") if [[ -n ${branch_list} ]]; then From 782873f3bec9d4aa52efbcbc0268316b346030cf Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:05:03 -0700 Subject: [PATCH 13/27] Specify remote branches. --- .github/workflows/update-feature-branches.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index a10f0c18b4..cf50f35f85 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -32,9 +32,9 @@ jobs: - name: Get list of feature branches id: get-branches run: | - branch_pattern=origin/'${{ env.defaultBranchPattern }}' + branch_pattern=remotes/origin/'${{ env.defaultBranchPattern }}' if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then - branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') + branch_pattern=remote/origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | remote/origin/|g') fi git remote update echo "All known branches:" @@ -44,8 +44,8 @@ jobs: if [[ -n ${branch_list} ]]; then # If there's at least one entry, process them. echo "Remote branch list: ${branch_list}" - # Remove origin/ from all branches. - branch_list=$(echo "${branch_list}" | sed 's| origin/| |g' | sed 's|^origin/||') + # Remove remotes/origin/ from all branches. + branch_list=$(echo "${branch_list}" | sed 's| remotes/origin/| |g' | sed 's|^remotes/origin/||') echo "Local branch list: ${branch_list}" # Change spaces to commas. branch_list=$(echo "${branch_list}" | sed 's/ /,/g') From a686cc35539866046233155527f9b429dbccb123 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:05:41 -0700 Subject: [PATCH 14/27] Skip second stage if no first. --- .github/workflows/update-feature-branches.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index cf50f35f85..4ab0daa124 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -61,6 +61,7 @@ jobs: name: create-merge-pr-${{ matrix.branch_name }} needs: [ list_feature_branches ] runs-on: ubuntu-20.04 + if: ${{ needs.list_feature_branches.branch_list != '[]' }} strategy: fail-fast: false matrix: From 997046ac1e2a390efc0cea29a1963452f3ce5c37 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:06:40 -0700 Subject: [PATCH 15/27] Typo --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 4ab0daa124..b4b5021cf0 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -34,7 +34,7 @@ jobs: run: | branch_pattern=remotes/origin/'${{ env.defaultBranchPattern }}' if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then - branch_pattern=remote/origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | remote/origin/|g') + branch_pattern=remotes/origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | remotes/origin/|g') fi git remote update echo "All known branches:" From c7e7f05967d63977f5572a11997a06156f61c0da Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:07:12 -0700 Subject: [PATCH 16/27] Error. --- .github/workflows/update-feature-branches.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index b4b5021cf0..530a741eee 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -61,11 +61,11 @@ jobs: name: create-merge-pr-${{ matrix.branch_name }} needs: [ list_feature_branches ] runs-on: ubuntu-20.04 - if: ${{ needs.list_feature_branches.branch_list != '[]' }} + if: ${{ needs.list_feature_branches.outputs.branch_list != '[]' }} strategy: fail-fast: false matrix: - branch_name: ${{ fromJson(needs.list_feature_branches.branch_list) }} + branch_name: ${{ fromJson(needs.list_feature_branches.outputs.branch_list) }} steps: - name: Get token for firebase-workflow-trigger uses: tibdex/github-app-token@v1 From 1abb4d6b9ab5baad51b853a8c25dad32627b8f4f Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:08:29 -0700 Subject: [PATCH 17/27] List all branches. --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 530a741eee..62222d4b4b 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -40,7 +40,7 @@ jobs: echo "All known branches:" git branch --list --all echo "Branch pattern: ${branch_pattern}" - branch_list=$(git branch --list --remote "${branch_pattern}") + branch_list=$(git branch --list --all "${branch_pattern}") if [[ -n ${branch_list} ]]; then # If there's at least one entry, process them. echo "Remote branch list: ${branch_list}" From 8e54a6a17f5634072c334412fc6afabf328de0d4 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:10:15 -0700 Subject: [PATCH 18/27] Fix logic. --- .github/workflows/update-feature-branches.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 62222d4b4b..7b58b283e4 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -32,9 +32,9 @@ jobs: - name: Get list of feature branches id: get-branches run: | - branch_pattern=remotes/origin/'${{ env.defaultBranchPattern }}' + branch_pattern='origin/${{ env.defaultBranchPattern }}' if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then - branch_pattern=remotes/origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | remotes/origin/|g') + branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi git remote update echo "All known branches:" @@ -44,7 +44,7 @@ jobs: if [[ -n ${branch_list} ]]; then # If there's at least one entry, process them. echo "Remote branch list: ${branch_list}" - # Remove remotes/origin/ from all branches. + # Remove remotes/origin/ from each branch. branch_list=$(echo "${branch_list}" | sed 's| remotes/origin/| |g' | sed 's|^remotes/origin/||') echo "Local branch list: ${branch_list}" # Change spaces to commas. From 55f2ae3699fe5d815b7cec536de7f45bfd49fc7a Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:12:22 -0700 Subject: [PATCH 19/27] Fix spacing. --- .github/workflows/update-feature-branches.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 7b58b283e4..2bb0b836de 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -45,13 +45,13 @@ jobs: # If there's at least one entry, process them. echo "Remote branch list: ${branch_list}" # Remove remotes/origin/ from each branch. - branch_list=$(echo "${branch_list}" | sed 's| remotes/origin/| |g' | sed 's|^remotes/origin/||') + branch_list=$(echo ${branch_list} | sed 's| remotes/origin/| |g' | sed 's|^remotes/origin/||') echo "Local branch list: ${branch_list}" # Change spaces to commas. - branch_list=$(echo "${branch_list}" | sed 's/ /,/g') + branch_list=$(echo ${branch_list} | sed 's/ /,/g') echo "Branch list with commas: ${branch_pattern}" # Add quotes around each branch name. - branch_list='"'$(echo "${branch_list}" | sed 's/,/","/g')'"' + branch_list='"'$(echo ${branch_list} | sed 's/,/","/g')'"' echo "Branch list with quotes: ${branch_pattern}" fi echo "::warning ::Branch list: [${branch_list}]" From 835ec7c533390f4f965b4e0ae3b840b706a179e3 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:12:46 -0700 Subject: [PATCH 20/27] Fix output --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 2bb0b836de..b0632c5b91 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -23,7 +23,7 @@ jobs: name: list-feature-branches runs-on: ubuntu-20.04 outputs: - branch_list: ${{ steps.get-branches.outputs.branch-list }} + branch_list: ${{ steps.get-branches.outputs.branch_list }} steps: - name: Check out repo (if needed) if: ${{ github.event.inputs.branch_list == '' }} From bc31e189187194978b2f1099e7d8066f2e99e483 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:14:31 -0700 Subject: [PATCH 21/27] Fix parameters. --- .github/workflows/update-feature-branches.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index b0632c5b91..3da4a7efe0 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -6,7 +6,7 @@ on: description: 'Space-separated list of feature branch patterns' default: 'feature_branch/*' required: true - main_branch_: + main_branch: description: 'Main branch to merge' default: 'main' required: true @@ -33,7 +33,7 @@ jobs: id: get-branches run: | branch_pattern='origin/${{ env.defaultBranchPattern }}' - if [[ -n ${{ github.event.inputs.branch_patterns }} ]]; then + if [[ -n '${{ github.event.inputs.branch_patterns }}' ]]; then branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi git remote update @@ -94,7 +94,7 @@ jobs: id: create-pr run: | main_branch='${{ env.defaultMainBranch }}' - if [[ -n ${{ github.event.inputs.main_branch }} ]]; then + if [[ -n '${{ github.event.inputs.main_branch }}' ]]; then main_branch='${{ github.event.inputs.main_branch }}' fi # Attempt a merge, then check if any files changed. From 266925b4a325366e2dd6a300e6d278cfa06cf6b1 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:17:54 -0700 Subject: [PATCH 22/27] Fix merge to use origin. --- .github/workflows/update-feature-branches.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 3da4a7efe0..695ea35155 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -93,9 +93,9 @@ jobs: - name: Create merge PR id: create-pr run: | - main_branch='${{ env.defaultMainBranch }}' + main_branch='origin/${{ env.defaultMainBranch }}' if [[ -n '${{ github.event.inputs.main_branch }}' ]]; then - main_branch='${{ github.event.inputs.main_branch }}' + main_branch='origin/${{ github.event.inputs.main_branch }}' fi # Attempt a merge, then check if any files changed. git merge --no-commit --no-ff "${main_branch}" || true From be988c40661cfa44ad05cc40aab2914b9039f2f4 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:19:35 -0700 Subject: [PATCH 23/27] Remove debug echos. --- .github/workflows/update-feature-branches.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 695ea35155..581ece95ab 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -37,22 +37,17 @@ jobs: branch_pattern=origin/$(echo '${{ github.event.inputs.branch_patterns }}' | sed 's| | origin/|g') fi git remote update - echo "All known branches:" - git branch --list --all echo "Branch pattern: ${branch_pattern}" branch_list=$(git branch --list --all "${branch_pattern}") if [[ -n ${branch_list} ]]; then - # If there's at least one entry, process them. + # If there's at least one entry, process the list. echo "Remote branch list: ${branch_list}" # Remove remotes/origin/ from each branch. branch_list=$(echo ${branch_list} | sed 's| remotes/origin/| |g' | sed 's|^remotes/origin/||') - echo "Local branch list: ${branch_list}" # Change spaces to commas. branch_list=$(echo ${branch_list} | sed 's/ /,/g') - echo "Branch list with commas: ${branch_pattern}" # Add quotes around each branch name. branch_list='"'$(echo ${branch_list} | sed 's/,/","/g')'"' - echo "Branch list with quotes: ${branch_pattern}" fi echo "::warning ::Branch list: [${branch_list}]" echo "branch_list=[${branch_list}]" >> $GITHUB_OUTPUT From ebfed91a6640aa1c7a976ec6730ac0422c15a513 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:21:00 -0700 Subject: [PATCH 24/27] Add git config. --- .github/workflows/update-feature-branches.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 581ece95ab..c0ec952df2 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -88,6 +88,10 @@ jobs: - name: Create merge PR id: create-pr run: | + git config user.email "firebase-workflow-trigger-bot@google.com" + git config user.name "firebase-workflow-trigger-bot" + git config core.commentChar "%" # so we can use # in git commit messages + main_branch='origin/${{ env.defaultMainBranch }}' if [[ -n '${{ github.event.inputs.main_branch }}' ]]; then main_branch='origin/${{ github.event.inputs.main_branch }}' From 18b73a6c11182dd1f2b64fffb04efdffcbc09332 Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:23:40 -0700 Subject: [PATCH 25/27] Fix PR creation. --- .github/workflows/update-feature-branches.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index c0ec952df2..96d9472fdf 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -115,7 +115,7 @@ jobs: > Created on ${date_str} by [${{github.workflow}} workflow]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID). " - pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --head "${{ matrix.branch_name }}" --base "${main_branch}" --title "${pr_title}" --body "${pr_body}") + pr_number=$(python scripts/gha/create_pull_request.py --token ${{ steps.generate-token.outputs.token }} --base "${{ matrix.branch_name }}" --head "${main_branch}" --title "${pr_title}" --body "${pr_body}") echo "created_pr_number=${pr_number}" >> $GITHUB_OUTPUT - name: Set test trigger label. From 6fbca6497dd6262461c391ed42af6cbdb1d86aba Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:25:33 -0700 Subject: [PATCH 26/27] Fix PR creation. --- .github/workflows/update-feature-branches.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 96d9472fdf..7685d3d694 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -92,12 +92,12 @@ jobs: git config user.name "firebase-workflow-trigger-bot" git config core.commentChar "%" # so we can use # in git commit messages - main_branch='origin/${{ env.defaultMainBranch }}' + main_branch='${{ env.defaultMainBranch }}' if [[ -n '${{ github.event.inputs.main_branch }}' ]]; then - main_branch='origin/${{ github.event.inputs.main_branch }}' + main_branch='${{ github.event.inputs.main_branch }}' fi # Attempt a merge, then check if any files changed. - git merge --no-commit --no-ff "${main_branch}" || true + git merge --no-commit --no-ff "origin/${main_branch}" || true if git diff --quiet ${{ matrix.branch_name }}; then # No merge necessary. echo "::warning ::No merge needed for ${{ matrix.branch_name }}, won't create pull request." From 62339bef70ccba99f1327e724555daf34ccb095a Mon Sep 17 00:00:00 2001 From: Jon Simantov Date: Thu, 20 Jul 2023 14:29:10 -0700 Subject: [PATCH 27/27] Fix automatic push. --- .github/workflows/update-feature-branches.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update-feature-branches.yml b/.github/workflows/update-feature-branches.yml index 7685d3d694..5e180d2611 100644 --- a/.github/workflows/update-feature-branches.yml +++ b/.github/workflows/update-feature-branches.yml @@ -120,8 +120,8 @@ jobs: - name: Set test trigger label. uses: actions-ecosystem/action-add-labels@v1 - if: ${{ steps.push-branch.outputs.created_pr_number }} + if: ${{ steps.create-pr.outputs.created_pr_number }} with: github_token: ${{ steps.generate-token.outputs.token }} - number: ${{ steps.push-branch.outputs.created_pr_number }} + number: ${{ steps.create-pr.outputs.created_pr_number }} labels: "${{ env.triggerTestsLabel }}"