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

refactor: dynamic version and refactor builds #46

Merged
merged 4 commits into from
Aug 12, 2024
Merged

Conversation

helder-moreira
Copy link
Contributor

@helder-moreira helder-moreira commented Aug 2, 2024

This PR makes a few changes:

  • Removes references to Hugo in version command.
  • Adds version and commit hash variables for printing in version command, and dynamically sets them at build time.
  • Simplifies builds by using pure Go and remove CGO bindings which are not necessary.
  • Uses normal GoReleaser instead of cross one because CGO isn't required anymore.
  • Reduces binary size.
  • Fixes config tests.

Summary by CodeRabbit

  • New Features

    • Enhanced workflow capabilities with updated GitHub Actions configuration for GoReleaser.
    • Dynamic version reporting in the version command, displaying application version and commit hash.
    • Introduced default constants for gRPC and WebSocket endpoints, improving configuration management.
    • Streamlined build process and improved binary naming in the Dockerfile.
    • Improved test setup organization for a consistent environment in test execution.
  • Chores

    • Updated entries in the .gitignore file to maintain a clean repository.
  • Refactor

    • Restructured Makefile for a more efficient build and installation process.

@helder-moreira helder-moreira added the type: enhancement New feature or request label Aug 2, 2024
@helder-moreira helder-moreira self-assigned this Aug 2, 2024
@helder-moreira helder-moreira requested a review from a team as a code owner August 2, 2024 10:34
Copy link
Contributor

coderabbitai bot commented Aug 2, 2024

Walkthrough

This update enhances the GoReleaser workflow for the pricefeeder project by upgrading dependencies, refining build configurations, and improving version reporting. Key changes include a revamped .goreleaser.yml for better environment handling, adjustments in the Dockerfile for clearer builds, and a more dynamic version command in the codebase. Additionally, new constants for gRPC and WebSocket endpoints were introduced, streamlining configuration management and enhancing overall project maintainability.

Changes

Files Change Summary
.github/.../goreleaser.yml Updated workflow permissions and actions. Added GoReleaser step with new parameters.
.gitignore Added entries for dist and pricefeeder to improve file management.
.goreleaser.yml Major updates to build settings, including architecture-specific configurations and removal of pre-build hooks. Version upgraded to 2, emphasizing reduced dependencies.
Dockerfile Changed build command to make build, renamed binary to pricefeeder, and added essential build tools.
Makefile Streamlined build targets and integrated versioning into the build process. Removed release-related targets.
cmd/version.go Introduced dynamic versioning with Version and CommitHash variables, enhancing command output clarity.
config/config.go Added default constants for gRPC and WebSocket endpoints, improving configuration flexibility.
config/config_test.go Added initialization function to set prefixes for tests, improving setup consistency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Makefile
    participant Dockerfile
    participant GoReleaser

    User->>Makefile: Invoke build
    Makefile->>Dockerfile: Trigger build process
    Dockerfile->>GoReleaser: Build application
    GoReleaser-->>Dockerfile: Return built binary
    Dockerfile-->>User: Provide pricefeeder binary
Loading

Poem

🐇 In code we hop, in builds we play,
With tweaks and turns, we pave the way.
From feeder to pricefeeder, we leap with glee,
A streamlined path, as clear as can be!
So let’s rejoice, in version's embrace,
Our project shines, in this happy space! 🌟


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 as 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.

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

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

Outside diff range, codebase verification and nitpick comments (1)
Makefile (1)

1-6: Potential Issue: Missing Git Tags

The git describe --tags --abbrev=0 command failed because no tags were found in the repository. This will cause the VERSION variable to be empty, which may impact the build process if it relies on this version number.

  • Ensure that tags are created in the repository to provide a valid version number.
#!/bin/bash
# Verify if there are any tags in the repository.
git tag
Analysis chain

LGTM! Verify the correctness of the shell commands.

The new variables are well-defined and enhance the build process. Ensure that the shell commands return the expected values.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correctness of the shell commands used in the Makefile.

# Test: Check the output of the shell commands. Expect: Proper version and commit hash.
echo "VERSION: $(git describe --tags --abbrev=0)"
echo "COMMIT: $(git rev-parse HEAD)"

Length of output: 240

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between caec1f8 and dca9e3c.

Files selected for processing (6)
  • .github/workflows/goreleaser.yml (1 hunks)
  • .gitignore (1 hunks)
  • .goreleaser.yml (1 hunks)
  • Dockerfile (1 hunks)
  • Makefile (2 hunks)
  • cmd/version.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments not posted (19)
Dockerfile (3)

3-3: LGTM!

The addition of build tools and Git is necessary for the new build process or dependencies.


12-12: LGTM!

Switching to make build suggests a more structured build process defined in a Makefile, which is beneficial for maintainability and flexibility.


17-19: LGTM!

Renaming the output binary to pricefeeder aligns with the application's context and enhances clarity.

cmd/version.go (3)

13-16: LGTM!

The introduction of global variables Version and CommitHash enhances the flexibility and maintainability of the version reporting feature.


20-21: LGTM!

The updated descriptions align the command's purpose with the updated context of the application.


23-23: LGTM!

The modification improves the informativeness and maintainability of the version reporting feature.

.github/workflows/goreleaser.yml (6)

8-9: LGTM!

The addition of the permissions section enhances the workflow's capability to manage repository contents.


15-16: LGTM!

Updating to the latest version of the action ensures compatibility and access to the latest features and fixes.


20-20: LGTM!

Updating to the latest version of the action ensures compatibility and access to the latest features and fixes.


22-22: LGTM!

Adding this step with updated parameters for the Go version and command arguments enhances the functionality and maintainability of the workflow.


24-24: LGTM!

Specifying a version constraint ensures that the workflow uses a compatible version of GoReleaser.


25-25: LGTM!

Using a more explicit invocation of GoReleaser with the --clean argument ensures a fresh build and enhances clarity.

Makefile (1)

29-31: LGTM!

The .PHONY target and the $(BUILD_TARGETS) rule streamline the build process and ensure version and commit hash information is embedded into the binary.

.goreleaser.yml (6)

1-1: LGTM!

The version update from 1 to 2 indicates a shift in functionality or structure, aligning with the overall improvements.


5-5: LGTM!

Setting CGO_ENABLED to 0 simplifies the build process by eliminating the need for CGO bindings.


17-19: LGTM!

The architecture-specific environment variables enhance clarity and specificity in the build process.


24-26: LGTM!

The updated ldflags section ensures that version and commit hash information is embedded into the binary, improving traceability and debugging.


37-39: LGTM!

The architecture-specific environment variables enhance clarity and specificity in the build process.


44-46: LGTM!

The updated ldflags section ensures that version and commit hash information is embedded into the binary, improving traceability and debugging.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dca9e3c and 5f95f4b.

Files selected for processing (1)
  • config/config_test.go (2 hunks)
Additional comments not posted (3)
config/config_test.go (3)

11-13: LGTM! Initialization function enhances consistency.

The init function ensures that application prefixes are set up before any tests are executed, enhancing the consistency of the test environment.


Line range hint 15-28:
LGTM! Environment setup and config retrieval are correct.

The TestConfig_Get function correctly sets environment variables and tests the configuration retrieval.


30-36: LGTM! Proper testing without EXCHANGE_SYMBOLS_MAP.

The TestConfig_Without_EXCHANGE_SYMBOLS_MAP function correctly tests configuration retrieval without the EXCHANGE_SYMBOLS_MAP environment variable. The removal of the fmt.Println statement is appropriate.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5f95f4b and d9ee664.

Files selected for processing (1)
  • Dockerfile (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • Dockerfile

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d9ee664 and a4a30b9.

Files selected for processing (1)
  • config/config.go (2 hunks)
Additional comments not posted (3)
config/config.go (3)

18-18: LGTM!

The addition of the defaultGrpcEndpoint constant enhances configuration flexibility and robustness.


19-19: LGTM!

The addition of the defaultWebsocketEndpoint constant enhances configuration flexibility and robustness.


95-100: LGTM!

The updates to the Get function ensure that the application has a fallback mechanism for connecting to necessary services, thereby improving robustness and user experience.

@helder-moreira helder-moreira merged commit 8c605e6 into main Aug 12, 2024
1 of 2 checks passed
@helder-moreira helder-moreira deleted the refactor/builds branch August 12, 2024 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
Status: ✅ Completed
Development

Successfully merging this pull request may close these issues.

2 participants