Forráskód Böngészése

ci(refactor): compute before/after references in parent workflow

Thales Macedo Garitezi 2 éve
szülő
commit
4151fe5045

+ 2 - 0
.github/workflows/_pr_entrypoint.yaml

@@ -154,6 +154,8 @@ jobs:
     with:
       runner: ${{ needs.sanity-checks.outputs.runner }}
       builder: ${{ needs.sanity-checks.outputs.builder }}
+      before_ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }}
+      after_ref: ${{ github.sha }}
 
   run_test_cases:
     needs:

+ 2 - 0
.github/workflows/_push-entrypoint.yaml

@@ -166,6 +166,8 @@ jobs:
     with:
       runner: ${{ needs.sanity-checks.outputs.runner }}
       builder: ${{ needs.sanity-checks.outputs.builder }}
+      before_ref: ${{ github.event.before }}
+      after_ref: ${{ github.sha }}
 
   run_test_cases:
     if: needs.prepare.outputs.release != 'true'

+ 10 - 12
.github/workflows/run_emqx_app_tests.yaml

@@ -16,6 +16,12 @@ on:
       builder:
         required: true
         type: string
+      before_ref:
+        required: true
+        type: string
+      after_ref:
+        required: true
+        type: string
 
 env:
   IS_CI: "yes"
@@ -34,20 +40,12 @@ jobs:
       with:
         fetch-depth: 0
     - name: run
+      env:
+        BEFORE_REF: ${{ inputs.before_ref }}
+        AFTER_REF: ${{ inputs.after_ref }}
       run: |
         git config --global --add safe.directory "$GITHUB_WORKSPACE"
-        echo "git diff base: $GITHUB_BASE_REF"
-        if [[ "$GITHUB_BASE_REF" =~ [0-9a-f]{8,40} ]]; then
-          # base is a commit sha1
-          compare_base="$GITHUB_BASE_REF"
-        else
-          repo="${GITHUB_REPOSITORY}"
-          git remote -v
-          remote="$(git remote -v | grep -E "github\.com(:|/)$repo((\.git)|(\s))" | grep fetch | awk '{print $1}')"
-          git fetch "$remote" "$GITHUB_BASE_REF"
-          compare_base="$remote/$GITHUB_BASE_REF"
-        fi
-        changed_files="$(git diff --name-only ${compare_base} HEAD apps/emqx)"
+        changed_files="$(git diff --name-only ${BEFORE_REF} ${AFTER_REF} apps/emqx)"
         if [ "$changed_files" = '' ]; then
           echo "nothing changed in apps/emqx, ignored."
           exit 0