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

chore: Various maintenance #16326

Merged
merged 10 commits into from
Oct 11, 2024
Merged

chore: Various maintenance #16326

merged 10 commits into from
Oct 11, 2024

Conversation

AndesKrrrrrrrrrrr
Copy link
Member

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr commented Oct 8, 2024

  • create release script
  • set --load to export Docker layer (started failing for me)
  • simpler helm-diff.sh usage (doesn't require arguments)

Summary by CodeRabbit

  • New Features

    • Enhanced the release automation script to support multiple repositories with improved logging and command execution.
    • Updated Docker image building to prioritize podman and included a new --load option.
    • Added user feedback for branch counts and installation checks during changelog generation.
    • Implemented a self-calling mechanism in the Helm diff script for automatic branch retrieval.
  • Bug Fixes

    • Improved error handling for AWS credentials and clarified error messages.
  • Documentation

    • Enhanced user feedback and logging for various scripts to improve usability and debugging.

Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.75%. Comparing base (a26489b) to head (faae939).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16326   +/-   ##
=======================================
  Coverage   36.75%   36.75%           
=======================================
  Files        6804     6804           
  Lines      140903   140903           
  Branches    40137    40137           
=======================================
  Hits        51785    51785           
  Misses      89118    89118           
Flag Coverage Δ
judicial-system-backend 55.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a26489b...faae939. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 8, 2024

Datadog Report

All test runs 951f81a 🔗

32 Total Test Services: 0 Failed, 32 Passed
⬆️ Test Sessions change in coverage: 1 increased (+0.19%), 107 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-web 0 0 0 2 0 9.5s 1 no change Link
api 0 0 0 4 0 3.12s 1 no change Link
api-domains-auth-admin 0 0 0 18 0 14.78s 1 no change Link
api-domains-mortgage-certificate 0 0 0 5 0 20.43s 1 no change Link
application-api-files 0 0 0 12 0 5.63s 1 no change Link
application-core 0 0 0 92 0 18.46s 1 no change Link
application-system-api 0 0 0 120 2 3m 22.84s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 28.69s 1 no change Link
application-templates-accident-notification 0 0 0 148 0 21.07s 1 no change Link
application-templates-driving-license 0 0 0 13 0 18.31s 1 no change Link

@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr marked this pull request as ready for review October 10, 2024 13:49
@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr requested a review from a team as a code owner October 10, 2024 13:49
@AndesKrrrrrrrrrrr AndesKrrrrrrrrrrr added the automerge Merge this PR as soon as all checks pass label Oct 10, 2024
Copy link
Contributor

coderabbitai bot commented Oct 10, 2024

Walkthrough

The pull request introduces several modifications across multiple scripts. The infra/scripts/helm-diff.sh script now includes a self-calling mechanism for automatic retrieval of release branches and uses dynamically generated temporary filenames. The scripts/_run-aws-eks-commands.js file enhances Docker command execution with new options and improved error handling. The generate-changelog.sh script adds user feedback and modifies control flow regarding the installation of a copy tool. Additionally, the mkrelease.sh script automates the release process across multiple repositories, incorporating various logging and command execution features.

Changes

File Change Summary
infra/scripts/helm-diff.sh Added self-calling mechanism for release branches, replaced hardcoded filenames with mktemp for temporary files, and adjusted cleanup commands.
scripts/_run-aws-eks-commands.js Added --load option for Docker builds, enhanced command construction with new environment variables, improved error handling, and refined command comparison logic.
scripts/generate-changelog.sh Added verification for generate-changelog tool installation, improved error messages for copy tools, and included branch count feedback during execution.
scripts/mkrelease.sh New script to automate the release process, including environment variable setup, logging functions, and management of pre-release branches and deployments.

Possibly related PRs

  • chore(scripts): Stricter shell script checking #16242: The changes in infra/scripts/helm-diff.sh regarding the handling of GitHub API calls and the modifications in this PR for stricter shell script checking may relate to improving the robustness and correctness of shell scripts.
  • chore(ci): Update configure-aws-credentials version to v4 #16258: The updates to the push.yml workflow, which involve AWS credential management, could be indirectly related to the changes in helm-diff.sh if the script interacts with AWS services as part of its functionality.
  • fix: pre-release #16308: The modifications in the push.yml workflow to enhance control flow and conditions for executing jobs may relate to the overall robustness of the CI/CD process, which could include the execution of the helm-diff.sh script as part of the deployment pipeline.

Suggested labels

high priority

Suggested reviewers

  • svanaeinars

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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: 10

🧹 Outside diff range and nitpick comments (8)
scripts/generate-changelog.sh (4)

5-7: Excellent addition for tool verification.

The added verification step improves the script's robustness by ensuring 'generate-changelog' is installed. The echo statement enhances user feedback, which is great for usability.

Consider adding error handling for the case where 'generate-changelog' is not installed. For example:

if ! npx generate-changelog &>/dev/null; then
  echo "Error: 'generate-changelog' is not installed. Please install it and try again."
  exit 1
fi

22-23: Improved error handling and script robustness.

The expanded error message and the use of "tee" as a fallback option enhance the script's usability and robustness. This change allows the script to continue execution even when no clipboard tool is available.

For clarity, consider adding a comment explaining the fallback behavior:

# Fallback to 'tee' if no clipboard tool is available
# This will print the changelog to stdout instead of copying to clipboard
selected_tool="tee"

30-32: Great addition of progress feedback.

The introduction of a counter and real-time feedback on the number of branches found significantly improves the user experience. The use of 'echo -ne' with '\r' for dynamic updates is an efficient approach for terminal output.

For consistency with bash naming conventions, consider using uppercase for the constant maximum number of branches:

MAX_BRANCHES=2
n=0
while IFS= read -r line && [ "$n" -lt "$MAX_BRANCHES" ]; do
  echo -ne "Found $((++n)) branches\r"
  branches+=("$line")
done < <(git for-each-ref --sort=-committerdate refs/heads/release/ --format='%(refname:short)')

This change also ensures that we only process the required number of branches, improving efficiency.


35-36: Improved user feedback and traceability.

The addition of the total branch count provides a clear summary to the user, and including this information in the changelog generation command improves traceability. These changes enhance the overall user experience and maintainability of the script.

Consider adding a check to ensure that at least two branches were found before generating the changelog:

if [ "${#branches[@]}" -lt 2 ]; then
  echo "Error: Not enough release branches found. At least two are required."
  exit 1
fi

echo "Found ${#branches[@]} branches in total"
npx generate-changelog -t "${branches[1]}".."${branches[0]}" -a -f - | "$selected_tool"

This addition would improve error handling and prevent potential issues if not enough branches are available.

infra/scripts/helm-diff.sh (1)

3-12: Excellent enhancement for usability!

The self-calling mechanism is a great addition that improves the script's ease of use. It automatically fetches the latest two release branches when no arguments are provided, which is very convenient.

A small suggestion for improvement:
Consider adding a git fetch command before git branch -r to ensure the list of remote branches is up-to-date. This would prevent potential issues if the local copy of remote branches is outdated.

You could add the following line just before line 5:

git fetch --all --quiet

This ensures that the list of remote branches is current before selecting the latest releases.

scripts/mkrelease.sh (2)

28-35: Use consistent function definitions for color outputs.

For better readability and consistency, it's recommended to define color functions before using them and to group related code together.

Consider moving the color function definitions directly after the color variables:

 COLOR_GRAY="\e[90m"

+red() { echo "${COLOR_RED}${*}${COLOR_RESET}"; }
+blue() { echo "${COLOR_BLUE}${*}${COLOR_RESET}"; }
+gray() { echo "${COLOR_GRAY}${*}${COLOR_RESET}"; }

-echo -e "$(gray "$(echo -e "Environment debug:\n###\n$(set | grep '^RELEASE_')\n###")")\n"

37-37: Avoid unnecessary nested echo commands.

The echo command is nested unnecessarily, which might impact readability.

Simplify the command by removing the redundant echo -e:

-echo -e "$(gray "$(echo -e "Environment debug:\n###\n$(set | grep '^RELEASE_')\n###")")\n"
+gray "Environment debug:\n###\n$(set | grep '^RELEASE_')\n###\n"
scripts/_run-aws-eks-commands.js (1)

Line range hint 17-22: Inconsistent error handling when container runtime is not found

When neither podman nor docker is available, the code logs an error message but still returns 'docker' as the containerer. This could lead to failures later since docker is not installed on the system.

Apply this diff to exit the process after logging the error:

   } else if (commandExistsSync('docker')) {
     return 'docker'
   }
   console.error('Please install podman or docker')
-  return 'docker'
+  process.exit(1)
 })()

This change ensures that the script halts execution when no valid container runtime is found, preventing unexpected errors downstream.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between df4b50b and 4dc4c2a.

📒 Files selected for processing (4)
  • infra/scripts/helm-diff.sh (2 hunks)
  • scripts/_run-aws-eks-commands.js (1 hunks)
  • scripts/generate-changelog.sh (2 hunks)
  • scripts/mkrelease.sh (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
scripts/_run-aws-eks-commands.js (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
scripts/generate-changelog.sh (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
scripts/mkrelease.sh (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
🔇 Additional comments (2)
infra/scripts/helm-diff.sh (1)

Line range hint 1-40: Overall, excellent improvements to the script!

The changes made to helm-diff.sh significantly enhance its functionality and ease of use. The addition of the self-calling mechanism with automatic retrieval of release branches aligns perfectly with the PR objective of simplifying the script's usage. The switch to dynamic temporary files improves the script's robustness and security.

These modifications make the script more user-friendly and less error-prone, which should lead to a smoother workflow for your team.

To further polish the script, consider implementing the suggestions provided in the previous comments:

  1. Add a git fetch before retrieving release branches to ensure up-to-date information.
  2. Implement a cleanup mechanism for the temporary files using a trap.

These minor adjustments will make the script even more robust and maintainable.

scripts/mkrelease.sh (1)

146-163: GITHUB_TOKEN is not set: Authentication issues confirmed.

The GITHUB_TOKEN environment variable is not set, which could lead to authentication failures when dispatching events.

  • File: scripts/mkrelease.sh
  • Function: dispatch-event

[issues_found]

🔗 Analysis chain

Handle GitHub token absence gracefully.

In the dispatch-event function, the Authorization header includes ${GITHUB_TOKEN}. If GITHUB_TOKEN is unset, it could lead to authentication issues.

Ensure that the GITHUB_TOKEN is set before making the API call, or adjust the script to handle its absence.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if GITHUB_TOKEN is set

# Test: Check if GITHUB_TOKEN is set
if [ -z "${GITHUB_TOKEN}" ]; then
  echo "GITHUB_TOKEN is not set. Please export GITHUB_TOKEN before running this script."
else
  echo "GITHUB_TOKEN is set."
fi

Length of output: 184

infra/scripts/helm-diff.sh Show resolved Hide resolved
scripts/mkrelease.sh Outdated Show resolved Hide resolved
scripts/mkrelease.sh Show resolved Hide resolved
scripts/mkrelease.sh Outdated Show resolved Hide resolved
scripts/mkrelease.sh Outdated Show resolved Hide resolved
scripts/mkrelease.sh Outdated Show resolved Hide resolved
scripts/mkrelease.sh Outdated Show resolved Hide resolved
scripts/mkrelease.sh Show resolved Hide resolved
scripts/mkrelease.sh Show resolved Hide resolved
scripts/_run-aws-eks-commands.js Show resolved Hide resolved
Copy link
Member

@robertaandersen robertaandersen left a comment

Choose a reason for hiding this comment

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

LGMT (see comments)

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: 0

🧹 Outside diff range and nitpick comments (2)
scripts/mkrelease.sh (2)

39-66: Well-implemented run() function with comprehensive error handling.

The run() function is well-designed, handling both dry runs and actual command execution. It effectively captures command output and exit codes, providing robust error handling. Consider either removing or uncommenting the debug lines (54-56) based on your debugging needs.

If the debug lines are no longer needed, consider removing them to improve code cleanliness:

-  # echo -e "$(gray "$(echo -e "[CMD] Command: ${CMD[1]}")")"
-  # for arg in "${CMD[@]}"; do
-  #   echo -e "$(gray "$(echo -e "[CMD] -> Argument: '${arg}'")")"
-  # done

103-123: Consider adding comments to clarify the rename-branch() function logic.

The rename-branch() function handles both local and remote branch renaming effectively. However, the logic is somewhat complex and could benefit from additional inline comments explaining each step of the process. This would improve maintainability and make it easier for other developers to understand the function's workflow.

Consider adding comments to explain the logic, especially for the conditional checks:

 rename-branch() {
   local OLD_BRANCH="${1}" NEW_BRANCH="${2}"
+  # Handle local branch renaming
   ## Local
   # Don't rename if already renamed
   if ! git branch --list | grep -q "^${NEW_BRANCH}$" &&
     ! git branch --list | grep -q "^${OLD_BRANCH}\$"; then
     run git branch -m "${OLD_BRANCH}" "${NEW_BRANCH}"
   fi
   run git fetch origin
+  # Handle remote branch renaming
   ## Remote
   if ! git branch -r | grep -q "origin/${NEW_BRANCH}"; then
     # Don't push new branch if it already exists
     run git push origin "${NEW_BRANCH}"
   fi
   run git branch -u "origin/${NEW_BRANCH}" "${NEW_BRANCH}"
   run git remote set-head origin -a
   run git fetch origin
+  # Clean up old remote branch if it exists
   if git branch -r | grep -q "origin/${OLD_BRANCH}"; then
     run git push origin --delete "${OLD_BRANCH}"
   fi
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4dc4c2a and 8060dd8.

📒 Files selected for processing (2)
  • scripts/_run-aws-eks-commands.js (1 hunks)
  • scripts/mkrelease.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • scripts/_run-aws-eks-commands.js
🧰 Additional context used
📓 Path-based instructions (1)
scripts/mkrelease.sh (1)

Pattern scripts/**/*: "Confirm that the code adheres to the following:

  • Script efficiency, readability, and maintainability.
  • Usage of environmental variables and configuration files for flexibility.
  • Integration with NX workspace utilities and commands."
📓 Learnings (1)
scripts/mkrelease.sh (2)
Learnt from: AndesKrrrrrrrrrrr
PR: island-is/island.is#16326
File: scripts/mkrelease.sh:149-150
Timestamp: 2024-10-11T14:02:50.332Z
Learning: In the `scripts/` directory, `jq` is already a required dependency, so it's acceptable to use `jq` in scripts.
Learnt from: AndesKrrrrrrrrrrr
PR: island-is/island.is#16326
File: scripts/mkrelease.sh:53-54
Timestamp: 2024-10-11T14:00:37.118Z
Learning: In scripts with `set -e`, when capturing the exit code of a command that may fail, it's necessary to use `|| true` to prevent the script from exiting immediately.
🔇 Additional comments (6)
scripts/mkrelease.sh (6)

3-3: Good use of error handling.

The set -euo pipefail command is a best practice in bash scripting. It ensures that the script exits immediately if any command fails, treats unset variables as an error, and prevents errors in a pipeline from being masked.


12-15: Improved portability by avoiding realpath.

Good decision to avoid using realpath for path resolution. This improves the script's portability, especially for macOS systems where realpath might not be available by default.


28-35: Effective use of color definitions for output formatting.

The color definitions and associated functions (red(), blue(), gray()) are well-implemented. This approach enhances the readability of the script's output and makes it easier to distinguish between different types of messages.


153-172: Effective implementation of dispatch-event() function.

The dispatch-event() function is well-implemented, using jq for URI encoding as per the project's requirements. The use of an array for the curl command improves readability and maintainability. The function effectively dispatches GitHub Actions workflow events.


183-218: Well-structured and comprehensive main execution flow.

The main execution flow is logically organized, covering pre-release, staging, and production deployments. It effectively utilizes the helper functions defined earlier, making the process clear and maintainable. The inclusion of monitoring steps and user prompts ensures proper oversight during the release process.


219-219: ⚠️ Potential issue

Fix typo in the final message.

There's a minor typo in the final celebratory message.

Apply this diff to correct the spelling:

-echo -e "\n>\n> 🚀 Realease complete! 🚀\n>\n"
+echo -e "\n>\n> 🚀 Release complete! 🚀\n>\n"

Likely invalid or redundant comment.

@kodiakhq kodiakhq bot merged commit 404dbdc into main Oct 11, 2024
27 checks passed
@kodiakhq kodiakhq bot deleted the chore/release-maintenance branch October 11, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants