diff --git a/.github/workflows/csv-coverage-pr-artifacts.yml b/.github/workflows/csv-coverage-pr-artifacts.yml index 2f818713a1b..8e2df456260 100644 --- a/.github/workflows/csv-coverage-pr-artifacts.yml +++ b/.github/workflows/csv-coverage-pr-artifacts.yml @@ -99,10 +99,16 @@ jobs: path: pr/ - name: Save comment ID (if it exists) run: | - mkdir -p comment # Find the latest comment starting with COMMENT_PREFIX COMMENT_PREFIX=":warning: The head of this PR and the base branch were compared for differences in the framework coverage reports." - gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate | jq --arg prefix "${COMMENT_PREFIX}" '[.[] | select(.body|startswith($prefix)) | .id] | max' > comment/ID + COMMENT_ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR_NUMBER}/comments" --paginate | jq --arg prefix "${COMMENT_PREFIX}" 'map(select(.body|startswith($prefix)) | .id) | max // empty') + if [[ -z ${COMMENT_ID} ]] + then + echo "Comment not found. Not uploading 'comment/ID' artifact." + else + mkdir -p comment + echo ${COMMENT_ID} > comment/ID + fi env: GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} @@ -111,3 +117,4 @@ jobs: with: name: comment path: comment/ + if-no-files-found: ignore diff --git a/misc/scripts/library-coverage/comment-pr.py b/misc/scripts/library-coverage/comment-pr.py index 9a35d230a35..51c837be9e8 100644 --- a/misc/scripts/library-coverage/comment-pr.py +++ b/misc/scripts/library-coverage/comment-pr.py @@ -56,14 +56,13 @@ def comment_pr(repo, run_id): if os.path.isdir("pr"): shutil.rmtree("pr") - utils.download_artifact(repo, "comment", "comment", run_id) - try: + utils.download_artifact(repo, "comment", "comment", run_id) with open("comment/ID") as file: raw_comment_id = int(file.read()) except Exception as e: - # If there is no existing comment, comment/ID will contain just a - # newline (due to jq & gh behaviour). This will cause `int(file.read())` + # If there is no existing comment, the `comment/ID` artifact + # will not exist. This will cause `utils.download_artifact` # to fail, so we catch that and set `raw_comment_id` to `None`. print("Could not retrieve an existing comment ID. \n", e) raw_comment_id = None