diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c584f5f427..b99dee3edc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,9 +27,9 @@ jobs: boards-aarch: ${{ steps.set-matrix.outputs.boards-aarch }} steps: - name: Dump GitHub context + run: echo "$GITHUB_CONTEXT" env: GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v3 with: submodules: false @@ -135,20 +135,26 @@ jobs: GITHUB_TOKEN: ${{ github.token }} EXCLUDE_COMMIT: ${{ github.event.after }} run: python3 -u ci_changes_per_commit.py + - name: Deepen and convert depth to sha + id: deepen-and-convert-depth-to-sha + run: | + DEEPEN=$((DEPTH - $(git rev-list HEAD --count))) && if((DEEPEN > 0)); then git fetch --no-tags --recurse-submodules=no --deepen=$DEEPEN; fi + echo "commit=$(git rev-list $GITHUB_SHA --skip=$((DEPTH + 1)) --max-count=1)" >> $GITHUB_OUTPUT + env: + DEPTH: ${{ steps.get-last-commit-with-checks.outputs.commit_depth || github.event.pull_request.commits }} - name: Get changes id: get-changes if: github.event_name == 'pull_request' - uses: tj-actions/changed-files@v34 - with: - json: true - sha: ${{ steps.get-last-commit-with-checks.outputs.commit && github.event.after }} - base_sha: ${{ steps.get-last-commit-with-checks.outputs.commit }} + run: echo $(git diff $BASE_SHA...$HEAD_SHA --name-only) | echo "changed_files=[\"$(sed "s/ /\", \"/g")\"]" >> $GITHUB_OUTPUT + env: + BASE_SHA: ${{ steps.deepen-and-convert-depth-to-sha.outputs.commit }} + HEAD_SHA: ${{ github.event.after }} - name: Set matrix id: set-matrix working-directory: tools env: - CHANGED_FILES: ${{ steps.get-changes.outputs.all_changed_and_modified_files }} - LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.checkruns }} + CHANGED_FILES: ${{ steps.get-changes.outputs.changed_files }} + LAST_FAILED_JOBS: ${{ steps.get-last-commit-with-checks.outputs.check_runs }} run: python3 -u ci_set_matrix.py diff --git a/tools/ci_changes_per_commit.py b/tools/ci_changes_per_commit.py index e40ee8ae47..b2256c6d45 100644 --- a/tools/ci_changes_per_commit.py +++ b/tools/ci_changes_per_commit.py @@ -18,7 +18,7 @@ query ($owner: String!, $name: String!, $pullNumber: Int!, $commitsPerPage: Int! } nodes { commit { - checkSuites(first: 3) { + checkSuites(first: 100) { nodes { conclusion workflowRun { @@ -141,26 +141,29 @@ def set_output(name, value): print(f"Would set GitHub actions output {name} to '{value}'") -def get_commit_and_check_suite(query_commits): - commits = query_commits.fetch()["data"]["repository"]["pullRequest"]["commits"] +def get_commit_depth_and_check_suite(query_commits): + while True: + commits = query_commits.fetch()["data"]["repository"]["pullRequest"]["commits"] - if commits["totalCount"] > 0: - for commit in reversed(commits["nodes"]): - commit = commit["commit"] - commit_sha = commit["oid"] - if commit_sha == os.environ["EXCLUDE_COMMIT"]: - continue - check_suites = commit["checkSuites"] - if check_suites["totalCount"] > 0: - for check_suite in check_suites["nodes"]: - if check_suite["workflowRun"]["workflow"]["name"] == "Build CI": - return [ - commit_sha, - check_suite["id"] if check_suite["conclusion"] != "SUCCESS" else None, - ] - else: - if query_commits.paginate(commits["pageInfo"], "beforeCommit"): - return get_commit_and_check_suite(query_commits) + if commits["totalCount"] > 0: + nodes = commits["nodes"] + nodes.reverse() + if nodes[0]["commit"]["oid"] == os.environ["EXCLUDE_COMMIT"]: + nodes.pop(0) + for index, commit in enumerate(nodes): + commit = commit["commit"] + commit_sha = commit["oid"] + check_suites = commit["checkSuites"] + if check_suites["totalCount"] > 0: + for check_suite in check_suites["nodes"]: + if check_suite["workflowRun"]["workflow"]["name"] == "Build CI": + return [ + {"sha": commit_sha, "depth": index + 1}, + check_suite["id"] if check_suite["conclusion"] != "SUCCESS" else None, + ] + else: + if not query_commits.paginate(commits["pageInfo"], "beforeCommit"): + break return [None, None] @@ -201,19 +204,24 @@ def get_bad_check_runs(query_check_runs): return bad_runs_by_matrix +def set_commit(commit): + set_output("commit_sha", commit["sha"]) + set_output("commit_depth", commit["depth"]) + + def main(): query_commits = Query(QUERY_COMMITS, query_variables_commits, headers) query_commits.variables["owner"], query_commits.variables["name"] = os.environ["REPO"].split( "/" ) - commit, check_suite = get_commit_and_check_suite(query_commits) + commit, check_suite = get_commit_depth_and_check_suite(query_commits) if check_suite is None: if commit is None: print("Abort: No check suite found") else: - set_output("commit", commit) + set_commit(commit) quit() query_check_runs = Query(QUERY_CHECK_RUNS, query_variables_check_runs, headers) @@ -225,7 +233,7 @@ def main(): print("Abort: No check runs found") quit() - set_output("commit", commit) + set_commit(commit) set_output("check_runs", json.dumps(check_runs))