Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: logs step will work when failure is there #36314

Closed
wants to merge 3 commits into from

Conversation

sagar-qa007
Copy link
Contributor

@sagar-qa007 sagar-qa007 commented Sep 13, 2024

Description

This step should only work when failure is there.

Fixes #Issue Number
or
Fixes Issue URL

Warning

If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.

Automation

/ok-to-test tags="@tag.ImportExport"

🔍 Cypress test results

Warning

Tests have not run on the HEAD 4a4df8f yet


Fri, 13 Sep 2024 11:05:20 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a script to automate the extraction of tags from JavaScript test files and generate a CSV report for easier analysis.
  • Bug Fixes

    • Adjusted conditions for commenting on pull requests based on CI test outcomes to improve developer notifications.
  • Chores

    • Refined workflow logic to execute log file trimming only on workflow failures, optimizing storage management.

Copy link
Contributor

coderabbitai bot commented Sep 13, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the conditional logic for commenting on pull requests based on CI test results. The logic for when comments are added has been inverted, affecting how developers are notified about CI outcomes. Additionally, a new script has been introduced to automate the extraction of tags from JavaScript test files, enhancing metadata reporting capabilities.

Changes

File Path Change Summary
.github/workflows/build-client-server-count.yml, .github/workflows/ci-test-limited-with-count.yml The conditional logic for adding comments on PRs based on CI test results has been inverted. The log trimming step now executes only on failure instead of always.
app/client/generate_csv.sh A new script has been added to automate the extraction of tags from JavaScript test files and generate a CSV report.

Possibly related PRs

Suggested labels

Bug, ok-to-test

Poem

In the land of code where logic flows,
Comments dance with CI's highs and lows.
A script now sings, extracting tags with grace,
While trimming logs finds its rightful place.
With every change, our tools refine,
Together we build, our efforts align! 🌟

Tip

OpenAI O1 model for chat
  • We have deployed OpenAI's latest O1 model for chat.
  • OpenAI claims that this model has superior reasoning capabilities than their GPT-4o model.
  • Please share any feedback with us in the discussions post.

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (1)
app/client/generate_csv.sh (1)

14-22: The file processing loop is well-structured, but there's room for improvement. 🔍

  1. Consider simplifying the awk command by using a single regular expression to extract the tags. This will make the code more concise and easier to understand.

  2. Make the grep command case-insensitive by adding the -i flag. This will ensure that tags with different letter cases are correctly extracted.

Here's an example of how you can modify the code:

-    tags=$(awk -v RS='[{}]' '/tags:/ {gsub(/[["\]]/, ""); print $0}' "$file" | grep -Eo '@tag\.[A-Za-z0-9_-]+')
+    tags=$(awk -v RS='[{}]' '/tags:/ {gsub(/[["]]/, ""); print $2}' "$file" | grep -Eio '@tag\.[a-z0-9_-]+')

These changes will make the script more robust and maintainable.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f5b29b4 and 4a4df8f.

Files ignored due to path filters (5)
  • app/client/cypress/scripts/.yarn/cache/ansi-regex-npm-4.1.1-af0a582bb9-b1a6ee44cb.zip is excluded by !**/.yarn/**
  • app/client/cypress/scripts/.yarn/cache/prompt-sync-npm-4.2.0-1ce4e10166-b14dfb7d25.zip is excluded by !**/.yarn/**
  • app/client/cypress/scripts/.yarn/cache/strip-ansi-npm-5.2.0-275214c316-bdb5f76ade.zip is excluded by !**/.yarn/**
  • app/client/cypress/scripts/.yarn/install-state.gz is excluded by !**/.yarn/**
  • app/client/output.csv is excluded by !**/*.csv
Files selected for processing (3)
  • .github/workflows/build-client-server-count.yml (4 hunks)
  • .github/workflows/ci-test-limited-with-count.yml (1 hunks)
  • app/client/generate_csv.sh (1 hunks)
Additional comments not posted (6)
app/client/generate_csv.sh (3)

1-7: Great job setting up the script header and defining the variables! 👍

The shebang line correctly specifies the bash interpreter, and the variables for the folder, postfix, and output CSV file are clearly defined. This makes the script more readable and maintainable.


8-9: Excellent work initializing the CSV file with headers! 🌟

Using the echo command to write the headers to the CSV file is a straightforward and effective approach. The headers are well-defined and cover the necessary information for each test file.


41-48: Great work appending the data to the CSV file and completing the script! 🎉

The script correctly appends the extracted data to the CSV file using the echo command and increments the row number for each processed file. The completion message at the end of the script provides useful information about the generated CSV file.

.github/workflows/ci-test-limited-with-count.yml (1)

365-365: Great job optimizing the workflow! 👍

The change in the step condition from if: always() to if: failure() is a smart move. It ensures that the log files are trimmed only when there is a failure in the previous steps, rather than always executing regardless of the outcome.

This optimization will help conserve resources and improve the efficiency of the workflow.

.github/workflows/build-client-server-count.yml (2)

454-454: Inversion of logic detected. Please verify the intended behavior.

Similar to the previous comment, the condition for adding a comment on the PR with new CI failures has been changed from checking if env.ci_test_failed is 'true' to checking if it is not 'true'. This inverts the logic, causing a comment to be added when there are no CI test failures.

Please refer to the previous comment for the suggested fix.


468-468: Inversion of logic detected. Please verify the intended behavior.

Similar to the previous comment, the condition for adding a comment when the ci-test-limited-existing-docker-image job is successful has been changed from checking if env.ci_test_failed is not 'true' to checking if it is 'true'. This inverts the logic, causing a comment to be added only when there are CI test failures.

Please refer to the previous comment for the suggested fix.

Comment on lines +23 to +39
# Remove brackets and split tags into an array
IFS=',' read -r -a tagArray <<< "$(echo "$tags" | tr '\n' ',' | sed 's/,$//')"

# Initialize empty tag variables for up to 9 tags
tags1=""; tags2=""; tags3=""; tags4=""; tags5=""
tags6=""; tags7=""; tags8=""; tags9=""

# Assign tags to respective variables
if [ ${#tagArray[@]} -gt 0 ]; then tags1="${tagArray[0]}"; fi
if [ ${#tagArray[@]} -gt 1 ]; then tags2="${tagArray[1]}"; fi
if [ ${#tagArray[@]} -gt 2 ]; then tags3="${tagArray[2]}"; fi
if [ ${#tagArray[@]} -gt 3 ]; then tags4="${tagArray[3]}"; fi
if [ ${#tagArray[@]} -gt 4 ]; then tags5="${tagArray[4]}"; fi
if [ ${#tagArray[@]} -gt 5 ]; then tags6="${tagArray[5]}"; fi
if [ ${#tagArray[@]} -gt 6 ]; then tags7="${tagArray[6]}"; fi
if [ ${#tagArray[@]} -gt 7 ]; then tags8="${tagArray[7]}"; fi
if [ ${#tagArray[@]} -gt 8 ]; then tags9="${tagArray[8]}"; fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tag assignment logic works, but let's make it more efficient and readable. 📝

  1. Replace the multiple if statements with a loop to assign tags to variables dynamically. This will reduce code duplication and make the script more maintainable.

  2. Use an array to store the tag variables instead of individual variables. This will simplify the initialization and make the code more concise.

Here's an example of how you can refactor the code:

-    # Initialize empty tag variables for up to 9 tags
-    tags1=""; tags2=""; tags3=""; tags4=""; tags5=""
-    tags6=""; tags7=""; tags8=""; tags9=""
-
-    # Assign tags to respective variables
-    if [ ${#tagArray[@]} -gt 0 ]; then tags1="${tagArray[0]}"; fi
-    if [ ${#tagArray[@]} -gt 1 ]; then tags2="${tagArray[1]}"; fi
-    if [ ${#tagArray[@]} -gt 2 ]; then tags3="${tagArray[2]}"; fi
-    if [ ${#tagArray[@]} -gt 3 ]; then tags4="${tagArray[3]}"; fi
-    if [ ${#tagArray[@]} -gt 4 ]; then tags5="${tagArray[4]}"; fi
-    if [ ${#tagArray[@]} -gt 5 ]; then tags6="${tagArray[5]}"; fi
-    if [ ${#tagArray[@]} -gt 6 ]; then tags7="${tagArray[6]}"; fi
-    if [ ${#tagArray[@]} -gt 7 ]; then tags8="${tagArray[7]}"; fi
-    if [ ${#tagArray[@]} -gt 8 ]; then tags9="${tagArray[8]}"; fi
+    # Initialize an array to store tag variables
+    tagVars=("" "" "" "" "" "" "" "" "")
+
+    # Assign tags to respective variables using a loop
+    for i in "${!tagArray[@]}"; do
+        if [ $i -lt 9 ]; then
+            tagVars[$i]="${tagArray[$i]}"
+        fi
+    done

These changes will make the script more efficient and easier to understand.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Remove brackets and split tags into an array
IFS=',' read -r -a tagArray <<< "$(echo "$tags" | tr '\n' ',' | sed 's/,$//')"
# Initialize empty tag variables for up to 9 tags
tags1=""; tags2=""; tags3=""; tags4=""; tags5=""
tags6=""; tags7=""; tags8=""; tags9=""
# Assign tags to respective variables
if [ ${#tagArray[@]} -gt 0 ]; then tags1="${tagArray[0]}"; fi
if [ ${#tagArray[@]} -gt 1 ]; then tags2="${tagArray[1]}"; fi
if [ ${#tagArray[@]} -gt 2 ]; then tags3="${tagArray[2]}"; fi
if [ ${#tagArray[@]} -gt 3 ]; then tags4="${tagArray[3]}"; fi
if [ ${#tagArray[@]} -gt 4 ]; then tags5="${tagArray[4]}"; fi
if [ ${#tagArray[@]} -gt 5 ]; then tags6="${tagArray[5]}"; fi
if [ ${#tagArray[@]} -gt 6 ]; then tags7="${tagArray[6]}"; fi
if [ ${#tagArray[@]} -gt 7 ]; then tags8="${tagArray[7]}"; fi
if [ ${#tagArray[@]} -gt 8 ]; then tags9="${tagArray[8]}"; fi
# Remove brackets and split tags into an array
IFS=',' read -r -a tagArray <<< "$(echo "$tags" | tr '\n' ',' | sed 's/,$//')"
# Initialize an array to store tag variables
tagVars=("" "" "" "" "" "" "" "" "")
# Assign tags to respective variables using a loop
for i in "${!tagArray[@]}"; do
if [ $i -lt 9 ]; then
tagVars[$i]="${tagArray[$i]}"
fi
done

@@ -292,7 +292,7 @@ jobs:
fi

- name: Add a comment on the PR with new CI failures
if: env.ci_test_failed == 'true' && needs.file-check.outputs.pr != '0'
if: env.ci_test_failed != 'true' && needs.file-check.outputs.pr != '0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inversion of logic detected. Please verify the intended behavior.

The condition for adding a comment on the PR with new CI failures has been changed from checking if env.ci_test_failed is 'true' to checking if it is not 'true'. This inverts the logic, causing a comment to be added when there are no CI test failures.

If the intention is to add a comment only when there are new CI failures, please revert the condition as follows:

-if: env.ci_test_failed != 'true' && needs.file-check.outputs.pr != '0'
+if: env.ci_test_failed == 'true' && needs.file-check.outputs.pr != '0'
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if: env.ci_test_failed != 'true' && needs.file-check.outputs.pr != '0'
if: env.ci_test_failed == 'true' && needs.file-check.outputs.pr != '0'

@@ -306,7 +306,7 @@
```

- name: Add a comment on the PR when ci-test-limited is successful
if: env.ci_test_failed != 'true' && needs.file-check.outputs.pr != '0'
if: env.ci_test_failed == 'true' && needs.file-check.outputs.pr != '0'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inversion of logic detected. Please verify the intended behavior.

The condition for adding a comment when the ci-test-limited job is successful has been changed from checking if env.ci_test_failed is not 'true' to checking if it is 'true'. This inverts the logic, causing a comment to be added only when there are CI test failures.

If the intention is to add a comment when the ci-test-limited job succeeds, please revert the condition as follows:

-if: env.ci_test_failed == 'true' && needs.file-check.outputs.pr != '0'  
+if: env.ci_test_failed != 'true' && needs.file-check.outputs.pr != '0'
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if: env.ci_test_failed == 'true' && needs.file-check.outputs.pr != '0'
if: env.ci_test_failed != 'true' && needs.file-check.outputs.pr != '0'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant