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(build): revert to working build + cherry-picks #1715

Merged
merged 3 commits into from
Dec 17, 2023
Merged

Conversation

Unique-Divine
Copy link
Member

@Unique-Divine Unique-Divine commented Dec 17, 2023

Purpose

The builds and docker image workflows have been broken a while. I think we
should combine the RocksDB changes into Helder's PR (#1713) and merge the
changes in from a working state to make it easier to upgrade versions more
smoothly.

Cherry-picked Commits

The build was working perfectly in 8959862.
This PR works up from there, where I cherry-picked each commit from the main
branch in order, evaluated whether the commit was safe with:

go clean -cache -modcache -testcache && go mod tidy && rm -rf temp && make build

If this passed, I kept the commit, and if it did not, I skipped it. Only two commits from our current main (d3297de) are missing:

Here is the full list of cherry-picked commits with working builds:


Summary by CodeRabbit

  • New Features

    • Introduced a new Bash library for enhanced logging and error handling.
    • Added new justfile recipes for streamlined development tasks such as installation, building, and release management.
  • Bug Fixes

    • Fixed build issues and inconsistencies across platforms.
  • Documentation

    • Updated the CHANGELOG with the latest fixes and removed dependency updates.
  • Refactor

    • Simplified the release preparation scripts for both Darwin and Linux platforms.
    • Updated build configurations and environment variables in goreleaser configurations.
  • Chores

    • Modified CI workflow to run on updated ubuntu-latest environment.
    • Updated Cosmos-SDK and dependency versions in build scripts.

@Unique-Divine Unique-Divine requested a review from a team as a code owner December 17, 2023 16:51
Copy link
Contributor

coderabbitai bot commented Dec 17, 2023

Walkthrough

The project underwent a series of updates affecting build configurations, environment variables, and scripts for release preparation. It includes simplifications and enhancements in the build process, removal of outdated dependencies, and introduction of new utility scripts and makefile targets. The changes aim to streamline the development and deployment process, refine the build environment, and improve the handling of cross-platform releases.

Changes

Files Change Summary
.github/workflows/goreleaser.yml Updated the runner environment from ubuntu-latest-m to ubuntu-latest.
.goreleaser.yml
CHANGELOG.md
Modified build configurations, removed environment variables, and added platform-specific overrides.
Semantic changes including fix additions and dependency update removal.
contrib/bashlib.sh Introduced a Bash library script with color variables, logging functions, error handling, and input validation utilities.
contrib/make/build.mk
contrib/make/release.mk
Added new variables capturing git branch, commit, and Cosmos-SDK version; updated Tendermint and RocksDB versions.
Removed a line from the docker run command in the release-snapshot target.
contrib/scripts/release_pre_darwin.sh
contrib/scripts/release_pre_linux.sh
Changed library installation process from using flock to direct wget downloads; modified installation directories.
Streamlined the logic, download, and installation processes for libraries.
justfile Added recipes for installation, building, protobuf code generation, linting, formatting, and release management; introduced task aliases.

"In the burrow of code, we hop and tweak, 🐇
Push and pull, in the git warren, we seek.
A build refined, a script entwined,
Release the bytes, let the versions peak! 🚀"

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 X ?


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • You can reply to a review comment made by CodeRabbit.
  • You can tag CodeRabbit on specific lines of code or files in the PR by tagging @coderabbitai in a comment.
  • You can tag @coderabbitai in a PR comment and ask one-off questions about the PR and the codebase. Use quoted replies to pass the context for follow-up questions.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

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.

Review Status

Actionable comments generated: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d3297de and 82d8f5c.
Files ignored due to filter (2)
  • go.mod
  • go.sum
Files selected for processing (9)
  • .github/workflows/goreleaser.yml (1 hunks)
  • .goreleaser.yml (3 hunks)
  • CHANGELOG.md (2 hunks)
  • contrib/bashlib.sh (1 hunks)
  • contrib/make/build.mk (2 hunks)
  • contrib/make/release.mk (1 hunks)
  • contrib/scripts/release_pre_darwin.sh (1 hunks)
  • contrib/scripts/release_pre_linux.sh (1 hunks)
  • justfile (1 hunks)
Files skipped from review due to trivial changes (1)
  • contrib/scripts/release_pre_darwin.sh
Additional comments: 24
.github/workflows/goreleaser.yml (1)
  • 14-14: The change to runs-on: ubuntu-latest may affect the build environment. Verify that all dependencies and build steps are compatible with the updated runner environment.
.goreleaser.yml (5)
  • 9-22: The changes to the darwin build configuration, including the update to the pre-hook script and the environment variable for the compiler, seem to align with the PR's goal of fixing build issues. Ensure that the new CC value is correct and that the release_pre_darwin.sh script is properly configured to handle the build environment.

  • 40-44: The addition of the overrides section for the darwin platform with arm64 architecture is a significant change. Verify that the oa64-clang compiler is available and properly configured in the build environment, and that this change has been tested to ensure it does not introduce any new issues.

  • 46-61: The updates to the linux build configuration, including the new pre-hook script and the updated compiler environment variable, should be verified. Confirm that the release_pre_linux.sh script is correctly handling the build requirements and that the x86_64-linux-gnu-gcc compiler is the intended choice for the linux builds.

  • 79-83: The new overrides section for the linux platform with arm64 architecture introduces a different compiler setting. Verify that the aarch64-linux-gnu-gcc compiler is correctly set up in the build environment and that this change has been thoroughly tested to prevent any build issues.

  • 37-61: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [9-83]

While the hunks do not display removed code, the AI-generated summary mentions the removal of specific environment variables. Please confirm that any removed environment variables are no longer required and that their removal does not affect the build process or other dependencies.

CHANGELOG.md (2)
  • 51-51: Verify that the entry "fix(build): revert to working build + cherry-picks" is correctly categorized under "State Machine Breaking". If it's not related to state machine changes, it should be placed under the appropriate section.

  • 85-86: Confirm that the release links and commit references for version v1.1.0 are accurate and lead to the correct resources.

contrib/make/build.mk (5)
  • 6-9: The addition of BRANCH and COMMIT variables is correctly implemented using shell commands to capture the current git branch and commit hash.

  • 27-32: The SDK_PACK variable is introduced to capture the Cosmos-SDK version, and the TM_VERSION variable is updated to reflect the new source repository cometbft. The ROCKSDB_VERSION is set to a static value. Ensure that these versions are compatible with the rest of the project.

  • 17-35: The use of the new BRANCH and COMMIT variables to dynamically set the VERSION when it is not provided by the user is a good practice, ensuring that the build artifacts are always versioned.

  • 17-35: The linker flags (ldflags) are correctly updated to include the new TM_VERSION and the existing COMMIT variable, which will be reflected in the built binaries.

  • 17-35: The download commands for rocksdblib and wasmvmlib are correctly using the ROCKSDB_VERSION and WASMVM_VERSION variables. The conditional logic for different operating systems and architectures is also correctly implemented.

contrib/make/release.mk (1)
  • 20-25: The removal of the volume mapping from the docker run command in the release-snapshot target may affect the build process if there was a dependency on shared temporary files or directories. Verify that the build process functions correctly without this volume mapping and that no other parts of the build rely on this behavior.
justfile (10)
  • 6-8: The install recipe is clear and straightforward, assuming the make install command is correctly set up in the Makefile.

  • 10-12: The build recipe is also clear, assuming the make build command is correctly set up in the Makefile.

  • 14-14: The alias b for build is a useful shortcut for developers.

  • 16-19: The proto-gen recipe is clear, assuming the make proto-gen command is correctly set up in the Makefile.

  • 21-21: The alias proto for proto-gen is a useful shortcut for developers.

  • 27-35: The lint recipe includes installation of golangci-lint if not present, which is a good practice. However, the installation command should be verified for correctness and safety.

  • 37-39: The fmt recipe uses gofumpt to format the code, which is a standard practice for Go codebases.

  • 41-47: The tidy recipe combines multiple formatting and linting steps, which is a good practice for maintaining code quality.

  • 49-50: The release-test recipe should be verified to ensure that the make release-snapshot command is correctly set up in the Makefile.

Verification successful

The release-test recipe in the justfile is correctly set up. The make release-snapshot command exists and is defined in the contrib/make/release.mk file.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the `make release-snapshot` command is correctly set up in the `Makefile`.
rg --type make "release-snapshot:" Makefile

Length of output: 43



Script:

#!/bin/bash
# Search for any Makefile or .mk files in the repository
fd --type f --extension mk --extension '' 'Makefile' | xargs rg "release-snapshot:"

Length of output: 123

* 52-53: The `release-publish` recipe should be verified to ensure that the `make release` command is correctly set up in the `Makefile`.

CHANGELOG.md Outdated
@@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#1682](https://github.com/NibiruChain/nibiru/pull/1682) - feat!: add upgrade handler for v1.1.0
* [#1706](https://github.com/NibiruChain/nibiru/pull/1706) - fix: `v1.1.0` upgrade handler
* [#1712](https://github.com/NibiruChain/nibiru/pull/1712) - refactor(inflation): turn inflation off by default
* [#xxx](https://github.com/NibiruChain/nibiru/pull/xxx) - fix(build): revert to working build + cherry-picks
Copy link
Contributor

Choose a reason for hiding this comment

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

The PR link placeholder [#xxx] should be replaced with the actual PR number that corresponds to the "fix(build): revert to working build + cherry-picks" entry.

@@ -73,15 +74,13 @@
* [#1710](https://github.com/NibiruChain/nibiru/pull/1710) - refactor(perp): Clean and organize module errors for x/perp
Copy link
Contributor

Choose a reason for hiding this comment

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

The entry under "Non-breaking/Compatible Improvements" for PR [#1710] lacks a description of what the refactor entails. It would be beneficial for users to have a brief summary of the changes made.

Comment on lines 1 to 75
#!/usr/bin/env bash

# —————————————————————————————————————————————————
# COLORS: Terminal colors are set with ANSI escape codes.

export COLOR_GREEN="\033[32m"
export COLOR_CYAN="\033[36m"
export COLOR_RESET="\033[0m"

export COLOR_BLACK="\033[30m"
export COLOR_RED="\033[31m"
export COLOR_YELLOW="\033[33m"
export COLOR_BLUE="\033[34m"
export COLOR_MAGENTA="\033[35m"
export COLOR_WHITE="\033[37m"

# Bright color definitions
export COLOR_BRIGHT_BLACK="\033[90m"
export COLOR_BRIGHT_RED="\033[91m"
export COLOR_BRIGHT_GREEN="\033[92m"
export COLOR_BRIGHT_YELLOW="\033[93m"
export COLOR_BRIGHT_BLUE="\033[94m"
export COLOR_BRIGHT_MAGENTA="\033[95m"
export COLOR_BRIGHT_CYAN="\033[96m"
export COLOR_BRIGHT_WHITE="\033[97m"

# —————————————————————————————————————————————————
# LOGGING

# log_debug: Simple wrapper for `echo` with a DEBUG prefix.
log_debug() {
echo "${COLOR_CYAN}DEBUG${COLOR_RESET}" "$@"
}

# log_error: ERROR messages in red, output to stderr.
log_error() {
echo "❌ ${COLOR_RED}ERROR:${COLOR_RESET}" "$@" >&2
}

log_success() {
echo "${COLOR_GREEN}✅ Success:${COLOR_RESET}" "$@"
}

# —————————————————————————————————————————————————
# OK Suffix: Functions used for error handling or validating inputs.

# which_ok: Check if the given binary is in the $PATH.
# Returns code 0 on success and code 1 if the command fails.
which_ok() {
if which "$1" >/dev/null 2>&1; then
return 0
else
log_error "$1 is not present in \$PATH"
return 1
fi
}

# source_ok (Function): Sources a bash script if it exists.
# Usage: source_ok [bash_script]
source_ok() {
local bash_script="$1"
if test -r "$bash_script"; then
# shellcheck disable=SC1090
source "$bash_script"
fi
}

env_var_ok() {
local env_var="$1"
if [[ -z "$env_var" ]]; then
log_error "expected env var to be set"
return 1 # Return 1 to indicate error (variable is not set)
else
return 0 # Return 0 to indicate success (variable is set)
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 color definitions and logging functions in contrib/bashlib.sh are well-defined and follow standard bash scripting conventions. The use of ANSI escape codes for color output is correct, and the logging functions provide clear visual cues for different log levels. The which_ok, source_ok, and env_var_ok functions provide basic utility checks with appropriate error handling and logging.

However, the source_ok function on lines 58-66 does not handle the case where the file exists but sourcing it fails (e.g., due to syntax errors in the sourced file). It is recommended to check the exit status of the source command and log an error if it fails.

  if test -r "$bash_script"; then 
    # shellcheck disable=SC1090
-   source "$bash_script"
+   if ! source "$bash_script"; then
+     log_error "Failed to source $bash_script"
+     return 1
+   fi
  fi

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.

Suggested change
#!/usr/bin/env bash
# —————————————————————————————————————————————————
# COLORS: Terminal colors are set with ANSI escape codes.
export COLOR_GREEN="\033[32m"
export COLOR_CYAN="\033[36m"
export COLOR_RESET="\033[0m"
export COLOR_BLACK="\033[30m"
export COLOR_RED="\033[31m"
export COLOR_YELLOW="\033[33m"
export COLOR_BLUE="\033[34m"
export COLOR_MAGENTA="\033[35m"
export COLOR_WHITE="\033[37m"
# Bright color definitions
export COLOR_BRIGHT_BLACK="\033[90m"
export COLOR_BRIGHT_RED="\033[91m"
export COLOR_BRIGHT_GREEN="\033[92m"
export COLOR_BRIGHT_YELLOW="\033[93m"
export COLOR_BRIGHT_BLUE="\033[94m"
export COLOR_BRIGHT_MAGENTA="\033[95m"
export COLOR_BRIGHT_CYAN="\033[96m"
export COLOR_BRIGHT_WHITE="\033[97m"
# —————————————————————————————————————————————————
# LOGGING
# log_debug: Simple wrapper for `echo` with a DEBUG prefix.
log_debug() {
echo "${COLOR_CYAN}DEBUG${COLOR_RESET}" "$@"
}
# log_error: ERROR messages in red, output to stderr.
log_error() {
echo "${COLOR_RED}ERROR:${COLOR_RESET}" "$@" >&2
}
log_success() {
echo "${COLOR_GREEN}✅ Success:${COLOR_RESET}" "$@"
}
# —————————————————————————————————————————————————
# OK Suffix: Functions used for error handling or validating inputs.
# which_ok: Check if the given binary is in the $PATH.
# Returns code 0 on success and code 1 if the command fails.
which_ok() {
if which "$1" >/dev/null 2>&1; then
return 0
else
log_error "$1 is not present in \$PATH"
return 1
fi
}
# source_ok (Function): Sources a bash script if it exists.
# Usage: source_ok [bash_script]
source_ok() {
local bash_script="$1"
if test -r "$bash_script"; then
# shellcheck disable=SC1090
source "$bash_script"
fi
}
env_var_ok() {
local env_var="$1"
if [[ -z "$env_var" ]]; then
log_error "expected env var to be set"
return 1 # Return 1 to indicate error (variable is not set)
else
return 0 # Return 0 to indicate success (variable is set)
fi
# source_ok (Function): Sources a bash script if it exists.
# Usage: source_ok [bash_script]
source_ok() {
local bash_script="$1"
if test -r "$bash_script"; then
# shellcheck disable=SC1090
if ! source "$bash_script"; then
log_error "Failed to source $bash_script"
return 1
fi
fi
}

@@ -0,0 +1,76 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding a set -e directive at the beginning of the script to ensure that the script exits immediately if any command exits with a non-zero status. This is a common best practice for bash scripts to prevent unexpected behavior in case of errors. However, if this script is intended to be sourced rather than executed directly, this may not be necessary.

#!/usr/bin/env bash
+ set -e

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.

Suggested change
#!/usr/bin/env bash
#!/usr/bin/env bash
set -e

Comment on lines +14 to +21
wget https://github.com/CosmWasm/wasmvm/releases/download/v${WASMVM_VERSION}/libwasmvm_muslc.x86_64.a -O /usr/lib/x86_64-linux-gnu/libwasmvm_muslc.a
wget https://github.com/CosmWasm/wasmvm/releases/download/v${WASMVM_VERSION}/libwasmvm_muslc.aarch64.a -O /usr/lib/aarch64-linux-gnu/libwasmvm_muslc.a
wget https://github.com/NibiruChain/gorocksdb/releases/download/v8.1.1/include.8.1.1.tar.gz -O /root/include.8.1.1.tar.gz
tar -xvf /root/include.8.1.1.tar.gz -C /usr/include/
wget https://github.com/NibiruChain/gorocksdb/releases/download/v8.1.1/librocksdb_8.1.1_linux_amd64.tar.gz -O /root/librocksdb_8.1.1_linux_amd64.tar.gz
tar -xvf /root/librocksdb_8.1.1_linux_amd64.tar.gz -C /usr/lib/x86_64-linux-gnu/
wget https://github.com/NibiruChain/gorocksdb/releases/download/v8.1.1/librocksdb_8.1.1_linux_arm64.tar.gz -O /root/librocksdb_8.1.1_linux_arm64.tar.gz
tar -xvf /root/librocksdb_8.1.1_linux_arm64.tar.gz -C /usr/lib/aarch64-linux-gnu/
Copy link
Contributor

Choose a reason for hiding this comment

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

The script directly downloads and installs binaries and libraries to system directories. Consider the following points:

  1. Ensure the script is executed with appropriate permissions, as writing to /usr/lib and /usr/include typically requires root access.
  2. To avoid potential versioning issues, consider parameterizing the library versions or deriving them from a source of truth that reflects the project's dependencies.
  3. Check if the files already exist before downloading to prevent unnecessary network usage and file overwrites.
  4. It's a good practice to verify the integrity of the downloaded files (e.g., via checksums) before extracting them to system directories to mitigate the risk of malicious tampering.

Comment on lines +1 to +4
# Displays available recipes by running `just -l`.
setup:
#!/usr/bin/env bash
just -l
Copy link
Contributor

Choose a reason for hiding this comment

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

The setup recipe seems to be misnamed or misused, as it only lists available recipes instead of performing any setup tasks.

Comment on lines +23 to +25
# Build protobuf types (Rust)
proto-rs:
bash proto/buf.gen.rs.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 NOTE
Codebase verification is a beta feature.

The verification script has confirmed that the script proto/buf.gen.rs.sh does not exist or is not executable in the repository. This means that the proto-rs recipe in the justfile may fail to execute as intended since it relies on this script.

  • The script proto/buf.gen.rs.sh referenced in the proto-rs recipe of the justfile is either missing or not marked as executable. This needs to be addressed to ensure the proto-rs recipe functions correctly.
Analysis chain

The proto-rs recipe should ensure that the script proto/buf.gen.rs.sh exists and is executable.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that the script `proto/buf.gen.rs.sh` exists and is executable.
if [[ -x "proto/buf.gen.rs.sh" ]]; then
  echo "The script proto/buf.gen.rs.sh is executable."
else
  echo "The script proto/buf.gen.rs.sh does not exist or is not executable."
fi

Length of output: 175

@Unique-Divine Unique-Divine merged commit 2afd0da into main Dec 17, 2023
13 checks passed
@Unique-Divine Unique-Divine deleted the realu/build-2 branch December 17, 2023 17:14
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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 82d8f5c and c359e0d.
Files selected for processing (2)
  • CHANGELOG.md (2 hunks)
  • contrib/bashlib.sh (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • contrib/bashlib.sh

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