Jelajahi Sumber

Fix CI when targeting non-master branches (#6293)

Albert Johnston 4 tahun lalu
induk
melakukan
d7bdd0b0b3

+ 4 - 1
.github/workflows/build.yml

@@ -41,6 +41,7 @@ jobs:
         if: github.event_name == 'pull_request'
         if: github.event_name == 'pull_request'
         run: |
         run: |
           echo "BRANCH_NAME=$GITHUB_HEAD_REF" >> $GITHUB_ENV
           echo "BRANCH_NAME=$GITHUB_HEAD_REF" >> $GITHUB_ENV
+          echo "TARGET_BRANCH_NAME=$(echo ${GITHUB_BASE_REF##*/})" >> $GITHUB_ENV
           echo "COMMIT_MESSAGE<<EOF" >> $GITHUB_ENV
           echo "COMMIT_MESSAGE<<EOF" >> $GITHUB_ENV
           echo "$(git log --format=%B -n 1 HEAD^2)" >> $GITHUB_ENV
           echo "$(git log --format=%B -n 1 HEAD^2)" >> $GITHUB_ENV
           echo "EOF" >> $GITHUB_ENV
           echo "EOF" >> $GITHUB_ENV
@@ -70,7 +71,7 @@ jobs:
           COMMIT_MESSAGE="${COMMIT_MESSAGE//$'\r'/'%0D'}"
           COMMIT_MESSAGE="${COMMIT_MESSAGE//$'\r'/'%0D'}"
           echo "::set-output name=commit_message::$COMMIT_MESSAGE"
           echo "::set-output name=commit_message::$COMMIT_MESSAGE"
           echo "::set-output name=branch_name::$BRANCH_NAME"
           echo "::set-output name=branch_name::$BRANCH_NAME"
-          echo "::set-output name=branch_name::$BRANCH_NAME"
+          echo "::set-output name=target_branch_name::$TARGET_BRANCH_NAME"
           echo "::set-output name=previous_commit::$PREVIOUS_COMMIT"
           echo "::set-output name=previous_commit::$PREVIOUS_COMMIT"
       - id: verify_out
       - id: verify_out
         name: Write verify job matrix
         name: Write verify job matrix
@@ -85,6 +86,7 @@ jobs:
     outputs:
     outputs:
       commit_message: ${{ steps.event_out.outputs.commit_message }}
       commit_message: ${{ steps.event_out.outputs.commit_message }}
       branch_name: ${{ steps.event_out.outputs.branch_name }}
       branch_name: ${{ steps.event_out.outputs.branch_name }}
+      target_branch_name: ${{ steps.event_out.outputs.target_branch_name }}
       previous_commit: ${{ steps.event_out.outputs.previous_commit }}
       previous_commit: ${{ steps.event_out.outputs.previous_commit }}
       verify_matrix: ${{ steps.verify_out.outputs.verify_matrix }}
       verify_matrix: ${{ steps.verify_out.outputs.verify_matrix }}
   verify:
   verify:
@@ -102,6 +104,7 @@ jobs:
       TESTDIR: ${{ matrix.TESTDIR }}
       TESTDIR: ${{ matrix.TESTDIR }}
       COMMIT_MESSAGE: ${{ needs.setup.outputs.commit_message }}
       COMMIT_MESSAGE: ${{ needs.setup.outputs.commit_message }}
       BRANCH_NAME: ${{ needs.setup.outputs.branch_name }}
       BRANCH_NAME: ${{ needs.setup.outputs.branch_name }}
+      TARGET_BRANCH_NAME: ${{ needs.setup.outputs.target_branch_name }}
       PREVIOUS_COMMIT: ${{ needs.setup.outputs.previous_commit }}
       PREVIOUS_COMMIT: ${{ needs.setup.outputs.previous_commit }}
       PR_NUMBER: ${{ github.event.pull_request.number }}
       PR_NUMBER: ${{ github.event.pull_request.number }}
     steps:
     steps:

+ 4 - 3
toolset/github_actions/github_actions_diff.py

@@ -60,15 +60,16 @@ curr_branch = ""
 is_PR = (os.getenv("PR_NUMBER") != "")
 is_PR = (os.getenv("PR_NUMBER") != "")
 previous_commit = os.getenv("PREVIOUS_COMMIT")
 previous_commit = os.getenv("PREVIOUS_COMMIT")
 
 
+diff_target = os.getenv("TARGET_BRANCH_NAME") if is_PR else previous_commit
+
 if is_PR:
 if is_PR:
     curr_branch = "HEAD"
     curr_branch = "HEAD"
     # Also fetch master to compare against
     # Also fetch master to compare against
-    subprocess.check_output(['bash', '-c', 'git fetch origin master:master'])
+    subprocess.check_output(['bash', '-c', 'git fetch origin {0}:{0}'
+                            .format(diff_target)])
 else:
 else:
     curr_branch = os.getenv("GITHUB_SHA")
     curr_branch = os.getenv("GITHUB_SHA")
 
 
-diff_target = "master" if is_PR else previous_commit
-
 # https://stackoverflow.com/questions/25071579/list-all-files-changed-in-a-pull-request-in-git-github
 # https://stackoverflow.com/questions/25071579/list-all-files-changed-in-a-pull-request-in-git-github
 changes = clean_output(
 changes = clean_output(
     subprocess.check_output([
     subprocess.check_output([