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

feat: generate typescript and publish on merge #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

matthiasmatt
Copy link
Contributor

@matthiasmatt matthiasmatt commented Mar 21, 2024

Fix #85 85

Summary by CodeRabbit

  • New Features

    • Enhanced schema generation process and added TypeScript code generation support.
    • Introduced a new recipe for generating TypeScript code based on schemas.
  • Chores

    • Updated build and deployment scripts to streamline development operations.

Copy link
Contributor

coderabbitai bot commented Mar 21, 2024

Walkthrough

This update introduces a workflow for publishing TypeScript code, enhancing the project's automation capabilities. It adds and modifies recipes in the justfile to improve schema generation and TypeScript code generation, streamlining development processes and ensuring consistency in code output. The addition of environment variable loading further simplifies configuration management.

Changes

File Change Summary
.github/workflows/.../publish-ts.yml New workflow for building, generating, and publishing TypeScript code.
justfile - Added environment variable loading.
- Improved schema generation.
- Added TypeScript code generation based on schemas.

🐰✨
In the garden of code, where the bits softly tread,
A new workflow blooms, its petals widespread.
Schemas transform, in TypeScript delight,
With a hop and a skip, our project takes flight.
To the server, we sync, with a gentle embrace,
In this digital meadow, our code finds its place.
🌼🚀

Assessment against linked issues

Objective Addressed Explanation
Create a command for simplified ts-codegen run
Implement CI workflow for TypeScript publishing
Output generated code to designated directory
Manual trigger for publishing TypeScript code
Organize generated code into a common directory

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>.
    • Generate unit-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 21dbc5c and 7402a3d.
Files selected for processing (2)
  • .github/workflows/publish-ts.yml (1 hunks)
  • justfile (2 hunks)
Additional comments: 3
.github/workflows/publish-ts.yml (1)
  • 3-28: The workflow is well-structured and follows best practices for GitHub Actions. However, consider the following points for improvement:
  • Security: Ensure that DEPLOY_KEY is securely stored as a GitHub secret and has the minimal required access rights on the deployment server.
  • Node.js Version: Using a specific version of Node.js ("14") is good for consistency. However, verify if this version aligns with the project's current Node.js version requirements to avoid potential compatibility issues.
  • rsync Usage: The rsync command uses -avz flags for verbose, archive mode, and compression. Ensure that verbose mode (-v) does not leak sensitive information in the logs. Additionally, consider specifying the exact directories or files to sync to avoid unintentional overwrites.
justfile (2)
  • 4-4: Adding set dotenv-load is a good practice for managing environment variables. Ensure that the .env file is properly secured and not checked into version control to prevent accidental exposure of sensitive information.
  • 121-137: The gen-ts recipe introduces a new process for generating TypeScript code. While the approach is generally sound, consider the following points:
  • Schema Directory Handling: The script assumes the presence of a schema directory. Ensure that this directory is created or checked for existence before proceeding with the TypeScript generation to avoid potential errors.
  • Error Handling: Similar to the gen-schema recipe, ensure proper error handling and exit codes for each step of the process to maintain robustness in automated environments.

Comment on lines +94 to +118
initial_dir=$PWD
for dir in contracts/*; do
dir_name=$(basename $dir)
echo "Generating schema for $dir_name..."

# Change to the contract directory
if cd $dir; then
# Check if 'cargo schema' can be run successfully
if cargo schema; then
# Move back to the initial directory
cd $initial_dir
# Create target schema directory if it doesn't exist
mkdir -p schema/$dir_name
# Move the generated schema to the target directory
if ! mv $dir/schema schema/$dir_name; then
echo "Failed to move schema directory for $dir_name."
fi
else
cd $initial_dir
fi
else
echo "Failed to change directory to $dir."
fi
done
Copy link
Contributor

Choose a reason for hiding this comment

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

The gen-schema recipe has been enhanced to handle directory changes and schema generation more robustly. Consider the following improvements:

  • Error Handling: Ensure that the script exits with a non-zero status code when encountering errors to prevent silent failures in CI/CD pipelines.
  • Directory Navigation: Use pushd and popd instead of cd for changing directories. This approach is more reliable and readable, especially in scripts with multiple directory changes.
- if cd $dir; then
+ if pushd $dir > /dev/null; then
- cd $initial_dir
+ popd > /dev/null

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
initial_dir=$PWD
for dir in contracts/*; do
dir_name=$(basename $dir)
echo "Generating schema for $dir_name..."
# Change to the contract directory
if cd $dir; then
# Check if 'cargo schema' can be run successfully
if cargo schema; then
# Move back to the initial directory
cd $initial_dir
# Create target schema directory if it doesn't exist
mkdir -p schema/$dir_name
# Move the generated schema to the target directory
if ! mv $dir/schema schema/$dir_name; then
echo "Failed to move schema directory for $dir_name."
fi
else
cd $initial_dir
fi
else
echo "Failed to change directory to $dir."
fi
done
#!/usr/bin/env bash
initial_dir=$PWD
for dir in contracts/*; do
dir_name=$(basename $dir)
echo "Generating schema for $dir_name..."
# Change to the contract directory
if pushd $dir > /dev/null; then
# Check if 'cargo schema' can be run successfully
if cargo schema; then
# Move back to the initial directory
popd > /dev/null
# Create target schema directory if it doesn't exist
mkdir -p schema/$dir_name
# Move the generated schema to the target directory
if ! mv $dir/schema schema/$dir_name; then
echo "Failed to move schema directory for $dir_name."
fi
else
popd > /dev/null
fi
else
echo "Failed to change directory to $dir."
fi
done

Copy link

codecov bot commented Mar 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.72%. Comparing base (902b788) to head (a9a2bff).
Report is 21 commits behind head on main.

Additional details and impacted files

see 41 files with indirect coverage changes

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 7402a3d and a9a2bff.
Files selected for processing (1)
  • justfile (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • justfile

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.

feat(scripts): Flexible TypeScript code generation command for smart contract types
1 participant