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: |Github Action| Deploy Backend add DEBUG_MODE for logging && BA… #554

Merged
merged 1 commit into from
Jan 11, 2025

Conversation

dreamhunter2333
Copy link
Owner

@dreamhunter2333 dreamhunter2333 commented Jan 11, 2025

User description

…CKEND_USE_MAIL_WASM_PARSER to enable mail-parser-wasm-worker


PR Type

enhancement, documentation


Description

  • Add DEBUG_MODE and BACKEND_USE_MAIL_WASM_PARSER to backend deployment.

  • Enable mail parsing using mail-parser-wasm-worker.

  • Update GitHub Actions workflow for conditional deployment steps.

  • Document new configuration options in the project documentation.


Changes walkthrough 📝

Relevant files
Enhancement
common.ts
Enable WASM mail parsing and clean up logs                             

worker/src/common.ts

  • Enable mail parsing using mail-parser-wasm-worker.
  • Remove redundant console log statement.
  • +0/-1     
    mail-parser-wasm-worker.patch
    Add patch for `mail-parser-wasm-worker`                                   

    .github/config/mail-parser-wasm-worker.patch

    • Add patch file to enable mail-parser-wasm-worker.
    +42/-0   
    backend_deploy.yaml
    Update backend deployment workflow with new options           

    .github/workflows/backend_deploy.yaml

  • Add DEBUG_MODE and BACKEND_USE_MAIL_WASM_PARSER environment variables.
  • Conditionally apply mail-parser-wasm-worker patch.
  • Update deployment steps based on debug mode.
  • +20/-6   
    Documentation
    CHANGELOG.md
    Update changelog with new deployment options                         

    CHANGELOG.md

  • Document new DEBUG_MODE and BACKEND_USE_MAIL_WASM_PARSER options.
  • +1/-0     
    telegram.md
    Document WASM mail parser configuration for Telegram         

    vitepress-docs/docs/zh/guide/feature/telegram.md

    • Add reference to WASM mail parser configuration.
    +2/-0     
    github-action.md
    Add documentation for new GitHub Action options                   

    vitepress-docs/docs/zh/guide/github-action.md

    • Document DEBUG_MODE and BACKEND_USE_MAIL_WASM_PARSER options.
    +2/-0     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    …CKEND_USE_MAIL_WASM_PARSER to enable mail-parser-wasm-worker
    @dreamhunter2333 dreamhunter2333 changed the title feat: |Github Action| Deploy Backend add DEBUG_MODE for logging && BA… feat: |Github Action| add DEBUG_MODE && BACKEND_USE_MAIL_WASM_PARSER Jan 11, 2025
    @github-actions github-actions bot changed the title feat: |Github Action| add DEBUG_MODE && BACKEND_USE_MAIL_WASM_PARSER feat: |Github Action| Deploy Backend add DEBUG_MODE for logging && BA… Jan 11, 2025
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Possible Issue

    The triggerAnotherWorker function no longer logs when another worker is disabled or the worker list is empty. This might make debugging more difficult.

    export async function triggerAnotherWorker(
        c: Context<HonoCustomType>,
        rpcEmailMessage: RPCEmailMessage,
        parsedText: string | undefined | null
    ): Promise<void> {
        if (!parsedText) {
            return;
        }
    
        const anotherWorkerList: AnotherWorker[] = getAnotherWorkerList(c);
        if (!getBooleanValue(c.env.ENABLE_ANOTHER_WORKER) || anotherWorkerList.length === 0) {
            return;
        }
    
        const parsedTextLowercase: string = parsedText.toLowerCase();
    Conditional Deployment Logic

    The new conditional deployment logic based on DEBUG_MODE and BACKEND_USE_MAIL_WASM_PARSER should be thoroughly tested to ensure it works as expected and does not introduce any deployment issues.

    name: Deploy Backend
    
    on:
      workflow_run:
        workflows: [Upstream Sync]
        types: [completed]
      push:
        tags:
          - "*"
      workflow_dispatch:
    
    jobs:
      deploy:
        runs-on: ubuntu-latest
        permissions:
          contents: write
        steps:
          - name: Checkout
            uses: actions/checkout@v4
    
          - name: Install Node.js
            uses: actions/setup-node@v4
            with:
              node-version: 18
    
          - uses: pnpm/action-setup@v3
            name: Install pnpm
            id: pnpm-install
            with:
              version: 8
              run_install: false
    
          - name: Deploy Backend for ${{ github.ref_name }}
            run: |
              export debug_mode=${{ secrets.DEBUG_MODE }}
              export use_mail_wasm_parser=${{ secrets.BACKEND_USE_MAIL_WASM_PARSER }}
              cd worker/
              echo '${{ secrets.BACKEND_TOML }}' > wrangler.toml
              pnpm install --no-frozen-lockfile
    
              if [ -n "$use_mail_wasm_parser" ]; then
                echo "Using mail-parser-wasm-worker"
                pnpm add mail-parser-wasm-worker
                git apply ../.github/config/mail-parser-wasm-worker.patch
                echo "Applied mail-parser-wasm-worker patch"
              fi
    
              if [ -n "$debug_mode" ]; then
                pnpm run deploy
              else
                output=$(pnpm run deploy 2>&1)
                if [ $? -ne 0 ]; then
                    code=$?
                    echo "Command failed with exit code $code"
                    exit $code
                fi
              fi
              echo "Deployed for tag ${{ github.ref_name }}"
            env:
              CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Avoid unnecessary installations of mail-parser-wasm-worker by checking if it is already installed

    Ensure that the pnpm add mail-parser-wasm-worker command is only run if the package
    is not already installed to avoid unnecessary installations.

    .github/workflows/backend_deploy.yaml [41-45]

     if [ -n "$use_mail_wasm_parser" ]; then
         echo "Using mail-parser-wasm-worker"
    -    pnpm add mail-parser-wasm-worker
    +    if ! pnpm list mail-parser-wasm-worker > /dev/null 2>&1; then
    +        pnpm add mail-parser-wasm-worker
    +    fi
         git apply ../.github/config/mail-parser-wasm-worker.patch
         echo "Applied mail-parser-wasm-worker patch"
     fi
    Suggestion importance[1-10]: 8

    Why: This suggestion optimizes the deployment process by preventing redundant installations, which can save time and resources. It is a practical improvement for efficiency.

    8
    Add a log statement to indicate when the function exits early due to parsedText being undefined or null

    Add a log statement to indicate when the function exits early due to parsedText
    being undefined or null.

    worker/src/common.ts [426-428]

     if (!parsedText) {
    +    console.log('parsedText is undefined or null, exiting function');
         return;
     }
    Suggestion importance[1-10]: 7

    Why: Adding a log statement improves traceability and debugging, helping developers understand why the function exited early. However, it is not critical for functionality.

    7
    Add log statements to indicate whether DEBUG_MODE is enabled or not for better traceability

    Add a log statement to indicate whether the DEBUG_MODE is enabled or not for better
    traceability.

    .github/workflows/backend_deploy.yaml [48-56]

     if [ -n "$debug_mode" ]; then
    +    echo "DEBUG_MODE is enabled"
         pnpm run deploy
     else
    +    echo "DEBUG_MODE is not enabled"
         output=$(pnpm run deploy 2>&1)
         if [ $? -ne 0 ]; then
             code=$?
             echo "Command failed with exit code $code"
             exit $code
         fi
     fi
    Suggestion importance[1-10]: 7

    Why: Adding log statements for DEBUG_MODE enhances traceability and helps in understanding the deployment process. It is useful for debugging but not essential for functionality.

    7

    @dreamhunter2333 dreamhunter2333 merged commit b604f56 into main Jan 11, 2025
    1 check passed
    @dreamhunter2333 dreamhunter2333 deleted the feature/dev branch January 11, 2025 10:04
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant