Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Make Builds Environment-Aware #169

Merged
merged 3 commits into from
Sep 4, 2024
Merged

Conversation

elg0nz
Copy link
Contributor

@elg0nz elg0nz commented Aug 31, 2024

• GitHub Actions: Added EXTENSION_ENV to manage builds for dev, staging, and production.
• Manifests: Renamed dev manifest to “[Development] Mocksi Lite” and updated production manifest for branding and security.
• Vite Config: Enhanced to pick the right manifest based on EXTENSION_ENV.

Summary by CodeRabbit

  • New Features

    • Introduced a new staging manifest for the Chrome extension, enhancing its configuration and permissions.
    • Added a mechanism to select the appropriate manifest based on the environment, improving deployment flexibility.
  • Improvements

    • Updated content security policies and external connectivity settings for better integration and security.
    • Enhanced the build process with a new environment variable to improve configurability.
  • Branding Changes

    • Renamed the development version of the application to "[Development] Mocksi Lite" for clarity.

• GitHub Actions: Added EXTENSION_ENV to manage builds for dev, staging, and production.
• Manifests: Renamed dev manifest to “[Development] Mocksi Lite” and updated production manifest for branding and security.
• Vite Config: Enhanced to pick the right manifest based on EXTENSION_ENV.
@elg0nz elg0nz requested review from fitzk and jonathankap August 31, 2024 04:42
Copy link

linear bot commented Aug 31, 2024

Copy link

coderabbitai bot commented Aug 31, 2024

Walkthrough

Walkthrough

The changes involve updates to the GitHub Actions workflow, JSON manifest files, and Vite configuration for the mocksi-lite-next application. A new environment variable EXTENSION_ENV is introduced to enhance the build process. The manifest files are modified to reflect new naming conventions and updated security policies. Additionally, a new staging manifest is created, and the Vite configuration is adjusted to dynamically select the appropriate manifest based on the environment.

Changes

Files Change Summary
.github/workflows/ci.yml Added a step to set the EXTENSION_ENV variable based on the current branch name to enhance build process configurability.
apps/mocksi-lite-next/manifest.dev.json Changed the name property from "Mocksi Lite: Next (DEV)" to "[Development] Mocksi Lite."
apps/mocksi-lite-next/manifest.json Updated name from "Mocksi Lite: Next" to "Mocksi Lite," modified matches under externally_connectable from https://nest-auth-ts-merge.onrender.com/* to https://app.mocksi.com/*, and changed extension_pages sources.
apps/mocksi-lite-next/manifest.staging.json Introduced a new manifest file for staging with version 3 specifications, including permissions, content security policy, and action settings for the Chrome extension.
apps/mocksi-lite-next/vite.config.ts Implemented logic to select the appropriate manifest based on the EXTENSION_ENV variable, enhancing configurability for different deployment scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant GitHub Actions
    participant Build System

    Developer->>GitHub Actions: Push code to branch
    GitHub Actions->>GitHub Actions: Set EXTENSION_ENV based on branch
    GitHub Actions->>Build System: Start build process with EXTENSION_ENV
    Build System->>Build System: Create build artifacts
    Build System-->>GitHub Actions: Return build artifacts
Loading

🐰 "Oh, what a change in the air,
With new names and builds to share!
A staging path now leads the way,
For Mocksi Lite, come what may!
Hops of joy, let’s celebrate,
A brighter future, oh so great!" 🐇✨

Tip

We have updated our review workflow to use the Anthropic's Claude family of models. Please share any feedback in the discussion post on our Discord.


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.

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

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

Outside diff range, codebase verification and nitpick comments (1)
apps/mocksi-lite-next/manifest.json (1)

28-28: Inconsistent product name across environments.

The product name change to "Mocksi Lite" is not consistently applied across all environments. The old name "Mocksi Lite: Next" still appears in apps/mocksi-lite-next/manifest.staging.json. Please update the staging manifest to ensure consistency across all configurations and avoid potential confusion.

  • apps/mocksi-lite-next/manifest.staging.json: Update the name to "Mocksi Lite".
Analysis chain

Simplified product name in manifest.json.

The change from "Mocksi Lite: Next" to "Mocksi Lite" simplifies the product's identity, potentially reflecting a branding decision. Ensure that this change is consistently reflected across all user-facing interfaces and marketing materials.

Run the following script to verify the consistency of the product name across user interfaces and marketing materials:

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of the product name across user interfaces and marketing materials.

# Test: Search for occurrences of the old and new product names.
rg "Mocksi Lite: Next" || echo "Old name not found."
rg "Mocksi Lite" || echo "New name not found."

Length of output: 594

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 29f4a63 and 1d726b3.

Files selected for processing (5)
  • .github/workflows/ci.yml (1 hunks)
  • apps/mocksi-lite-next/manifest.dev.json (1 hunks)
  • apps/mocksi-lite-next/manifest.json (1 hunks)
  • apps/mocksi-lite-next/manifest.staging.json (1 hunks)
  • apps/mocksi-lite-next/vite.config.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • apps/mocksi-lite-next/manifest.dev.json
Additional context used
actionlint
.github/workflows/ci.yml

45-45: shellcheck reported issue in this script: SC2086:info:1:55: Double quote to prevent globbing and word splitting

(shellcheck)


46-46: unexpected key "45" for "workflow" section. expected one of "concurrency", "defaults", "env", "jobs", "name", "on", "permissions", "run-name"

(syntax-check)

Additional comments not posted (4)
apps/mocksi-lite-next/manifest.json (2)

18-18: Updated extension_pages to new domain.

The change in the extension_pages field to use https://app.mocksi.ai for both child and frame sources reflects a shift in the backend service or hosting environment. Ensure that this new domain is properly configured and secure.

Run the following script to verify the availability and security settings of the new domain:


22-22: Updated matches for external connectivity.

The update in the matches field to https://app.mocksi.com/* potentially broadens the extension's functionality or alters its integration with other services. Verify that this new URL pattern does not introduce any security or operational issues.

Run the following script to verify the impact of the new URL pattern on the extension's functionality:

apps/mocksi-lite-next/vite.config.ts (1)

7-7: Enhanced manifest selection based on environment.

The introduction of stagingManifest and the implementation of a switch statement to select the appropriate manifest based on the EXTENSION_ENV variable are significant improvements. These changes ensure that the correct settings are applied for each environment, enhancing the application's configurability.

Run the following script to verify that the correct manifest is assigned based on the environment:

Also applies to: 19-33

Verification successful

Manifest selection logic is correctly implemented.

The switch statement in apps/mocksi-lite-next/vite.config.ts correctly assigns the appropriate manifest based on the EXTENSION_ENV variable. This ensures that the correct settings are applied for each environment, enhancing the application's configurability.

  • For "staging", activeManifest is a combination of manifest and stagingManifest.
  • For "production", activeManifest is set to manifest.
  • For other environments, activeManifest combines manifest with devManifest.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the correct manifest is assigned based on the environment.

# Test: Check the assignment of manifests in different environments.
echo "Testing in staging environment:"
export EXTENSION_ENV=staging
node -e "console.log(require('./vite.config.ts').default)"
echo "Testing in production environment:"
export EXTENSION_ENV=production
node -e "console.log(require('./vite.config.ts').default)"

Length of output: 546


Script:

#!/bin/bash
# Search for the switch statement or conditional logic in vite.config.ts that selects the manifest based on EXTENSION_ENV.
ast-grep --lang typescript --pattern $'switch ($_EXTENSION_ENV) { $$$ }'

Length of output: 6955

apps/mocksi-lite-next/manifest.staging.json (1)

1-48: Review of the Entire Manifest File

This new staging manifest file appears to be well-structured and aligns with the typical conventions for web extensions. Here are some specific observations and suggestions:

  1. Default Icon (Lines 3-5): The icon file mocksi-icon.png is specified. Ensure this file is included in the project assets.
  2. Background Script (Lines 7-9): The service worker is correctly set to src/pages/background/index.ts. Verify that this file exists and contains appropriate logic for a staging environment.
  3. Content Scripts (Lines 11-16): Scripts are set to run on all URLs, which is typical for browser extensions but ensure this is intended for staging.
  4. Content Security Policy (Lines 17-19): The policy restricts sources as expected. However, ensure that the domains listed (https://nest-auth-ts-merge.onrender.com) are correct for staging environments.
  5. Externally Connectable URLs (Lines 21-23): Matches URLs for external connections. Confirm that this URL is correct and that the server configuration allows these connections.
  6. Icons (Lines 24-26): The larger icon mocksi-logo.png is specified. As with the default icon, ensure this asset is available.
  7. Permissions (Lines 30-41): The permissions listed are extensive and include sensitive capabilities like cookies, downloads, and debugger. Review these permissions to ensure they are necessary for the staging environment.
  8. Web Accessible Resources (Lines 42-47): Lists resources that are web accessible. Verify that all listed resources are intended to be accessible and are present in the project.

Overall, the manifest file sets up the extension for the staging environment with appropriate settings. It is crucial to ensure all resources and URLs are correctly configured and that the security settings are appropriate for the environment.

Comment on lines 43 to 50
# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=${GITHUB_REF#refs/heads///-/}" >> $GITHUB_ENV
45:
- name: Build artifacts
run: pnpm build
env:
EXTENSION_ENV: ${{ env.EXTENSION_ENV }}
Copy link

Choose a reason for hiding this comment

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

Set EXTENSION_ENV based on branch name.

The addition of setting the EXTENSION_ENV variable based on the branch name enhances the build process's configurability. However, there are issues that need to be addressed:

  • Shell Script Issue: Ensure variables are properly quoted to prevent globbing and word splitting.
  • Syntax Error: The unexpected key "45" seems to be a typo or copy-paste error.

Apply these fixes to address the issues:

- echo "EXTENSION_ENV=${GITHUB_REF#refs/heads///-/}" >> $GITHUB_ENV
+ echo "EXTENSION_ENV=\"${GITHUB_REF#refs/heads///-/}\"" >> $GITHUB_ENV

- 45:
+ # Correct this line to remove the unexpected key
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
# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=${GITHUB_REF#refs/heads///-/}" >> $GITHUB_ENV
45:
- name: Build artifacts
run: pnpm build
env:
EXTENSION_ENV: ${{ env.EXTENSION_ENV }}
# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=\"${GITHUB_REF#refs/heads///-/}\"" >> $GITHUB_ENV
# Correct this line to remove the unexpected key
- name: Build artifacts
run: pnpm build
env:
EXTENSION_ENV: ${{ env.EXTENSION_ENV }}
Tools
actionlint

45-45: shellcheck reported issue in this script: SC2086:info:1:55: Double quote to prevent globbing and word splitting

(shellcheck)


46-46: unexpected key "45" for "workflow" section. expected one of "concurrency", "defaults", "env", "jobs", "name", "on", "permissions", "run-name"

(syntax-check)

Copy link
Contributor

@fitzk fitzk left a comment

Choose a reason for hiding this comment

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

everything looks good except the broken build & zip GitHub action is broken, see comment

# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=${GITHUB_REF#refs/heads///-/}" >> $GITHUB_ENV
45:
Copy link
Contributor

Choose a reason for hiding this comment

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

Screenshot 2024-09-03 at 10 16 03 AM Screenshot 2024-09-03 at 10 15 50 AM

@elg0nz take a look at this was this intended? I ran the build and zip action and those were the errors ☝🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, that was a typo :face-palm: correcting it now!

Copy link

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1d726b3 and d95bda4.

Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Additional context used
actionlint
.github/workflows/ci.yml

45-45: shellcheck reported issue in this script: SC2086:info:1:73: Double quote to prevent globbing and word splitting

(shellcheck)

Additional comments not posted (1)
.github/workflows/ci.yml (1)

48-49: LGTM!

Including the EXTENSION_ENV variable in the build step's environment context is necessary for the build process to utilize this variable.

Comment on lines 43 to 45
# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=\"${GITHUB_REF##refs/heads/}\"" | sed 's/\//-/g' >> $GITHUB_ENV
Copy link

Choose a reason for hiding this comment

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

Great enhancement to make the build process environment-aware!

Setting the EXTENSION_ENV variable based on the current branch name is a nice way to make the build process more configurable.

Fix the shellcheck issue.

actionlint has flagged a potential shellcheck issue in this step. To prevent globbing and word splitting, double quote the variable.

Apply this fix to address the shellcheck issue:

- run: echo "EXTENSION_ENV=\"${GITHUB_REF##refs/heads/}\"" | sed 's/\//-/g' >> $GITHUB_ENV
+ run: echo "EXTENSION_ENV=\"${GITHUB_REF##refs/heads/}\"" | sed 's/\//-/g' >> "$GITHUB_ENV"
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
# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=\"${GITHUB_REF##refs/heads/}\"" | sed 's/\//-/g' >> $GITHUB_ENV
# Set EXTENSION_ENV variable to the current branch name
- name: Set EXTENSION_ENV variable
run: echo "EXTENSION_ENV=\"${GITHUB_REF##refs/heads/}\"" | sed 's/\//-/g' >> "$GITHUB_ENV"
Tools
actionlint

45-45: shellcheck reported issue in this script: SC2086:info:1:73: Double quote to prevent globbing and word splitting

(shellcheck)

Copy link

@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)
.github/workflows/ci.yml (1)

43-45: Great enhancement to make the build process environment-aware!

Setting the EXTENSION_ENV variable based on the current branch name is a nice way to make the build process more configurable.

Fix the shellcheck issue.

actionlint has flagged a potential shellcheck issue in this step:

45-45: shellcheck reported issue in this script: SC2086:info:1:69: Double quote to prevent globbing and word splitting

To prevent globbing and word splitting, double quote the variable.

Apply this fix to address the shellcheck issue:

- run: echo "EXTENSION_ENV=${GITHUB_REF##refs/heads/}" | sed 's/\//-/g' >> $GITHUB_ENV
+ run: echo "EXTENSION_ENV=${GITHUB_REF##refs/heads/}" | sed 's/\//-/g' >> "$GITHUB_ENV" 
Tools
actionlint

45-45: shellcheck reported issue in this script: SC2086:info:1:69: Double quote to prevent globbing and word splitting

(shellcheck)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d95bda4 and 66cb678.

Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
Additional context used
actionlint
.github/workflows/ci.yml

45-45: shellcheck reported issue in this script: SC2086:info:1:69: Double quote to prevent globbing and word splitting

(shellcheck)

@elg0nz elg0nz requested a review from fitzk September 3, 2024 20:19
@fitzk
Copy link
Contributor

fitzk commented Sep 3, 2024

lgtm!

@elg0nz elg0nz merged commit c947a60 into main Sep 4, 2024
4 checks passed
@elg0nz elg0nz deleted the MOC-251-add-production-manifest branch September 4, 2024 02:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants