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

Add Trigger.dev and jobs #846

Merged
merged 15 commits into from
Mar 11, 2025
Merged

Add Trigger.dev and jobs #846

merged 15 commits into from
Mar 11, 2025

Conversation

FunamaYukina
Copy link
Member

@FunamaYukina FunamaYukina commented Mar 11, 2025

Issue

Trigger.dev as a job worker.
Concrete job images are added to frontend/apps/app/src/trigger/jobs.ts.
https://github.com/liam-hq/liam/pull/846/files#diff-f59dcca9048641d0588315ab628cc432c0f9b951059a5318eacd7166e3692bd3

I think the starting point of the job is the webhook in/app/api/webhook/github/route.ts, but I have not added any code there. I am thinking that the code will probably be as follows

    // start review job
    await savePullRequestTask.trigger({
      prNumber: pullRequest.number,
      repositoryId: repo,
      title: pullRequest.title,
    })

Why is this change needed?

What would you like reviewers to focus on?

Testing Verification

What was done

🤖 Generated by PR Agent at ad3119b

  • Introduced a task-based workflow for pull request processing using Trigger.dev, including tasks like savePullRequestTask, generateReviewTask, saveReviewTask, and postCommentTask.
  • Added a configuration file for Trigger.dev to manage tasks, including project ID, runtime, log level, and retry policies.
  • Updated dependencies to include @trigger.dev/sdk, dotenv, and other supporting libraries.
  • Added a new environment variable TRIGGER_PROJECT_ID for Trigger.dev project configuration.
  • Updated package license documentation with new entries and adjustments, including approvals for new dependencies.

Detailed Changes

Relevant files
Enhancement
jobs.ts
Added task-based workflow for pull request processing.     

frontend/apps/app/src/trigger/jobs.ts

  • Introduced four new tasks: savePullRequestTask, generateReviewTask,
    saveReviewTask, and postCommentTask.
  • Each task logs its execution and triggers subsequent tasks with
    specific payloads.
  • Added functionality for handling pull request reviews, including
    generating and saving reviews.
  • Tasks are interconnected to form a workflow for processing pull
    requests.
  • +75/-0   
    Configuration changes
    trigger.config.ts
    Added Trigger.dev configuration file for task management.

    frontend/apps/app/trigger.config.ts

  • Added a configuration file for Trigger.dev using defineConfig.
  • Configured project ID, runtime, log level, and task retry policies.
  • Included a directory for task definitions.
  • +26/-0   
    package.json
    Updated package.json with Trigger.dev dependencies and scripts.

    frontend/apps/app/package.json

  • Added @trigger.dev/sdk and dotenv to dependencies.
  • Introduced a new script trigger:dev for Trigger.dev development.
  • +3/-0     
    .env.development
    Added environment variable for Trigger.dev project configuration.

    frontend/apps/app/.env.development

  • Added a new environment variable TRIGGER_PROJECT_ID for Trigger.dev.
  • Documented the variable for development purposes.
  • +3/-0     
    Dependencies
    pnpm-lock.yaml
    Updated dependencies for Trigger.dev integration.               

    pnpm-lock.yaml

  • Updated dependencies to include @trigger.dev/sdk and related packages.
  • Added new dependencies such as dotenv and other supporting libraries.
  • Adjusted lockfile to reflect the new packages and their versions.
  • +865/-9 
    dependency_decisions.yml
    Approved new dependency for Trigger.dev integration.         

    config/dependency_decisions.yml

  • Approved the use of @electric-sql/client with an Apache-2.0 license.
  • Documented the approval decision with metadata.
  • +6/-0     
    Documentation
    packages-license.md
    Updated package license documentation with new entries and
    adjustments.

    docs/packages-license.md

  • Updated license counts for various packages, including MIT, Apache
    2.0, and New BSD.
  • Added new package entries with their respective licenses, such as
    @electric-sql/client, @google-cloud/precise-date, and others.
  • Downgraded or updated versions for some packages, e.g.,
    @opentelemetry/api-logs and zod.
  • Included additional metadata for newly added packages, specifying
    license types and approval statuses.
  • +687/-22

    Additional Notes


    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    changeset-bot bot commented Mar 11, 2025

    ⚠️ No Changeset found

    Latest commit: 89e715e

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    Copy link

    vercel bot commented Mar 11, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    liam-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2025 10:40am
    liam-erd-sample ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 11, 2025 10:40am
    3 Skipped Deployments
    Name Status Preview Comments Updated (UTC)
    test-liam-docs ⬜️ Ignored (Inspect) Mar 11, 2025 10:40am
    test-liam-erd-sample ⬜️ Ignored (Inspect) Mar 11, 2025 10:40am
    test-liam-erd-web ⬜️ Ignored (Inspect) Mar 11, 2025 10:40am

    Copy link

    liam-migration bot commented Mar 11, 2025

    Your pull request is detected by Liam Migration. 8 files are changed.

    Comment on lines +113 to +118
    - - :approve
    - "@electric-sql/client"
    - :who: OSPO @masutaka
    :why: The license is Apache-2.0.
    :versions: []
    :when: 2025-03-11 06:08:23.596952 Z
    Copy link
    Member Author

    Choose a reason for hiding this comment

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

    Comment on lines +2 to +4
    import * as dotenv from 'dotenv'

    dotenv.config()
    Copy link
    Member Author

    Choose a reason for hiding this comment

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

    Without dotenv, the environment variable seemed to be undefind.🙏
    (When running pnpm trigger:dev )

    Copy link
    Member

    Choose a reason for hiding this comment

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

    In my local shell environment, process.env.TRIGGER_PROJECT_ID is still undefined. 🤔

    Do you use any shell tool or plugin? Maybe VSCode?

    Anyway, I verified that by setting up some workarounds, I can use the dev and deploy commands from my environment.

    Copy link
    Member

    Choose a reason for hiding this comment

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

    Sorry, I understood. Linking .env.develop to .env solves.

    # example
    ln -s .env.development .env
    

    Copy link
    Member Author

    Choose a reason for hiding this comment

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

    Yes, I'm using .env!

    Copy link
    Contributor

    qodo-merge-pro-for-open-source bot commented Mar 11, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Fix hardcoded schema changes

    The schemaChanges parameter is hardcoded as a string literal 'schemaChanges'
    instead of using actual schema changes data. This will cause all PR reviews to
    use the same placeholder value regardless of the actual changes.

    frontend/apps/app/src/trigger/jobs.ts [3-18]

     export const savePullRequestTask = task({
       id: 'save-pull-request',
       run: async (payload: {
         prNumber: number
         repositoryId: string
         title: string
       }) => {
         logger.log('Executing PR save task:', { payload })
    +    // Get actual schema changes based on the PR
    +    const schemaChanges = await getSchemaChanges(payload.repositoryId, payload.prNumber)
         await generateReviewTask.trigger({
           prNumber: payload.prNumber,
           repositoryId: payload.repositoryId,
    -      schemaChanges: 'schemaChanges',
    +      schemaChanges,
         })
         return { success: true }
       },
     })
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: The suggestion correctly identifies a significant issue where schema changes are hardcoded as a string literal, which would cause all PR reviews to use the same placeholder value. Implementing actual schema change detection would significantly improve the functionality of the review system.

    Medium
    Validate required environment variable

    Using a hardcoded fallback value 'project-id' for triggerProjectId could lead to
    unexpected behavior in production if the environment variable is missing.
    Consider throwing an error if the environment variable is not set.

    frontend/apps/app/trigger.config.ts [5]

    -const triggerProjectId = process.env.TRIGGER_PROJECT_ID || 'project-id'
    +const triggerProjectId = process.env.TRIGGER_PROJECT_ID
    +if (!triggerProjectId) {
    +  throw new Error('TRIGGER_PROJECT_ID environment variable is required')
    +}
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies a potential issue with using a hardcoded fallback value for a critical configuration parameter. Failing fast with a clear error message when a required environment variable is missing is a better practice for configuration management.

    Medium
    • Update

    @hoshinotsuyoshi
    Copy link
    Member

    Let me check! 👀

    Copy link
    Member

    @MH4GF MH4GF left a comment

    Choose a reason for hiding this comment

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

    Thanks!
    Please check package.json 🙏🏻

    @@ -41,6 +43,7 @@
    "lint:biome": "biome check .",
    "postinstall": "cp ../../packages/db-structure/node_modules/@ruby/prism/src/prism.wasm prism.wasm",
    "start": "next start",
    "trigger:dev": "pnpm dlx trigger.dev@latest dev",
    Copy link
    Member

    Choose a reason for hiding this comment

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

    Can you fix it so that pnpm dev can start the dev server at once?

    Suggested change
    "trigger:dev": "pnpm dlx trigger.dev@latest dev",
    "dev:trigger": "pnpm dlx trigger.dev@latest dev",

    @@ -41,6 +43,7 @@
    "lint:biome": "biome check .",
    "postinstall": "cp ../../packages/db-structure/node_modules/@ruby/prism/src/prism.wasm prism.wasm",
    "start": "next start",
    "trigger:dev": "pnpm dlx trigger.dev@latest dev",
    Copy link
    Member

    Choose a reason for hiding this comment

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

    I would like to add to devDependencies, and fix to the following:

    Suggested change
    "trigger:dev": "pnpm dlx trigger.dev@latest dev",
    "trigger:dev": "trigger.dev dev",

    Copy link
    Member Author

    Choose a reason for hiding this comment

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

    Thanks for letting me know!
    I added trigger.dev to devDependencies. (21b1d8b)

    But Dependency Review test faild because trigger.dev depends on [email protected]
    So, I added resolutions to package.json because trigger.dev depends on [email protected].
    Is that OK?🙏

    21b1d8b ... add resolutions
    89e715e ... change packageManager

    Copy link
    Member

    Choose a reason for hiding this comment

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

    Oh, I see! I think resolutions is correct approach .

    Copy link
    Member Author

    Choose a reason for hiding this comment

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

    Thank you for confirming!😄

    Copy link
    Member

    @hoshinotsuyoshi hoshinotsuyoshi left a comment

    Choose a reason for hiding this comment

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

    👍
    Confirmed:

    • $ pnpm trigger:dev in the frontend/apps/app directory.
    • $ pnpm dlx trigger.dev@latest deploy in the frontend/apps/app directory.

    Copy link
    Contributor

    github-actions bot commented Mar 11, 2025

    Dependency Review

    The following issues were found:

    • ❌ 1 vulnerable package(s)
    • ✅ 0 package(s) with incompatible licenses
    • ✅ 0 package(s) with invalid SPDX license definitions
    • ⚠️ 1 package(s) with unknown licenses.
    • ⚠️ 8 packages with OpenSSF Scorecard issues.

    View full job summary

    Copy link
    Contributor

    qodo-merge-pro-for-open-source bot commented Mar 11, 2025

    CI Feedback 🧐

    (Feedback updated until commit 51dffe0)

    A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

    Action: Deploy (app, VERCEL_PROJECT_ID_ERD_WEB)

    Failed stage: [❌]

    Failure summary:

    The action failed because it was canceled during the Vercel deployment process. The log shows:

    1. The build process was progressing normally with package installation, CSS module type generation,
    and Vercel deployment
    2. The deployment was in the "Queued" state at line 974
    3. At line 975, the
    operation was explicitly canceled with the error message "##[error]The operation was canceled"

    This suggests the action was terminated either due to a timeout, manual cancellation, or another
    process interrupting the workflow.

    Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    179:  Lockfile is up to date, resolution step is skipped
    180:  Progress: resolved 1, reused 0, downloaded 0, added 0
    181:  Packages: +1587
    182:  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    183:  Progress: resolved 1587, reused 1139, downloaded 0, added 0
    184:  Progress: resolved 1587, reused 1570, downloaded 0, added 451
    185:  Progress: resolved 1587, reused 1570, downloaded 0, added 1181
    186:  Progress: resolved 1587, reused 1570, downloaded 0, added 1587, done
    187:  WARN  Failed to create bin at /home/runner/work/liam/liam/frontend/apps/erd-sample/node_modules/.bin/liam. ENOENT: no such file or directory, open '/home/runner/work/liam/liam/frontend/packages/cli/dist-cli/bin/cli.js'
    ...
    
    192:  + @turbo/gen 2.1.2
    193:  + syncpack 13.0.0
    194:  + turbo 2.1.2
    195:  frontend/apps/docs postinstall$ fumadocs-mdx
    196:  frontend/apps/docs postinstall: [MDX] types generated
    197:  frontend/apps/docs postinstall: Done
    198:  frontend/apps/app postinstall$ cp ../../packages/db-structure/node_modules/@ruby/prism/src/prism.wasm prism.wasm
    199:  frontend/apps/app postinstall: Done
    200:  WARN  Failed to create bin at /home/runner/work/liam/liam/frontend/apps/erd-sample/node_modules/.bin/liam. ENOENT: no such file or directory, open '/home/runner/work/liam/liam/frontend/apps/erd-sample/node_modules/@liam-hq/cli/dist-cli/bin/cli.js'
    ...
    
    295:  > tcm src
    296:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDContent/ERDContent.module.css.d.ts
    297:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/styles/variables.css.d.ts
    298:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ERDRenderer.module.css.d.ts
    299:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/Toolbar/DesktopToolbar.module.css.d.ts
    300:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/TableDetailDrawer/TableDetailDrawer.module.css.d.ts
    301:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/RelationshipEdgeParticleMarker/RelationshipEdgeParticleMarker.module.css.d.ts
    302:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/LeftPane/LeftPane.module.css.d.ts
    303:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ErrorDisplay/ParseErrorDisplay.module.css.d.ts
    304:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ErrorDisplay/NetworkErrorDisplay.module.css.d.ts
    305:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ErrorDisplay/ErrorDisplay.module.css.d.ts
    ...
    
    400:  . build:vite:  * [new branch]        avoid-semicolon-logic-test -> origin/avoid-semicolon-logic-test
    401:  . build:vite:  * [new branch]        before-promptfoo-experiment -> origin/before-promptfoo-experiment
    402:  . build:vite:  * [new branch]        changeset-invest1        -> origin/changeset-invest1
    403:  . build:vite:  * [new branch]        changeset-invest3        -> origin/changeset-invest3
    404:  . build:vite:  * [new branch]        changeset-release/changeset-invest1 -> origin/changeset-release/changeset-invest1
    405:  . build:vite:  * [new branch]        changeset-release/main   -> origin/changeset-release/main
    406:  . build:vite:  * [new branch]        check-github-action      -> origin/check-github-action
    407:  . build:vite:  * [new branch]        cli-schema-json-for-local -> origin/cli-schema-json-for-local
    408:  . build:vite:  * [new branch]        console-error-1-draft    -> origin/console-error-1-draft
    ...
    
    411:  . build:vite:  * [new branch]        delete-docs-vercel-deploy-erd-yml -> origin/delete-docs-vercel-deploy-erd-yml
    412:  . build:vite:  * [new branch]        devin/1738820244-add-init-command-tests -> origin/devin/1738820244-add-init-command-tests
    413:  . build:vite:  * [new branch]        devin/1738828298-add-multiline-comment-support -> origin/devin/1738828298-add-multiline-comment-support
    414:  . build:vite:  * [new branch]        devin/1739501885-improve-navigation-test-waits -> origin/devin/1739501885-improve-navigation-test-waits
    415:  . build:vite:  * [new branch]        devin/1740113652-update-changeset-docs -> origin/devin/1740113652-update-changeset-docs
    416:  . build:vite:  * [new branch]        devin/1741661851-optimize-github-config-validation -> origin/devin/1741661851-optimize-github-config-validation
    417:  . build:vite:  * [new branch]        devin/1741663537-github-env-validation-at-boot -> origin/devin/1741663537-github-env-validation-at-boot
    418:  . build:vite:  * [new branch]        enhance-the-highlighting-of-related-table-nodes-when-hovering-usememo-1 -> origin/enhance-the-highlighting-of-related-table-nodes-when-hovering-usememo-1
    419:  . build:vite:  * [new branch]        error-message-erd-network-error -> origin/error-message-erd-network-error
    ...
    
    452:  . build:vite:  * [new branch]        primary-key-icon-2       -> origin/primary-key-icon-2
    453:  . build:vite:  * [new branch]        promptfoo-go-1           -> origin/promptfoo-go-1
    454:  . build:vite:  * [new branch]        reduce-set-node-calling-chance-3 -> origin/reduce-set-node-calling-chance-3
    455:  . build:vite:  * [new branch]        refactor-active-highlight -> origin/refactor-active-highlight
    456:  . build:vite:  * [new branch]        refactor-to-testcases    -> origin/refactor-to-testcases
    457:  . build:vite:  * [new branch]        refactor_edge_cardinality_by_using_custom_mark -> origin/refactor_edge_cardinality_by_using_custom_mark
    458:  . build:vite:  * [new branch]        refactor_hidden_node_handle -> origin/refactor_hidden_node_handle
    459:  . build:vite:  * [new branch]        release-debug-branch     -> origin/release-debug-branch
    460:  . build:vite:  * [new branch]        revert-435-error-message-erd -> origin/revert-435-error-message-erd
    ...
    
    688:  ├ ƒ /app                                 325 B           204 kB
    689:  ├ ƒ /app/confirm                         325 B           204 kB
    690:  ├ ○ /app/login                           325 B           204 kB
    691:  ├ ƒ /app/projects                        663 B           270 kB
    692:  ├ ƒ /app/projects/new                    663 B           270 kB
    693:  ├ ○ /erd                                 326 B           204 kB
    694:  ├ ○ /erd/galaxy                          325 B           204 kB
    695:  ├ ƒ /erd/p/[...slug]                     516 kB          782 kB
    696:  └ ○ /error                               478 B           204 kB
    ...
    
    796:  > tcm src
    797:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/styles/globals.css.d.ts
    798:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ERDRenderer.module.css.d.ts
    799:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/styles/variables.css.d.ts
    800:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDContent/ERDContent.module.css.d.ts
    801:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/Toolbar/DesktopToolbar.module.css.d.ts
    802:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/TableDetailDrawer/TableDetailDrawer.module.css.d.ts
    803:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/RelationshipEdgeParticleMarker/RelationshipEdgeParticleMarker.module.css.d.ts
    804:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ErrorDisplay/ParseErrorDisplay.module.css.d.ts
    805:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ErrorDisplay/NetworkErrorDisplay.module.css.d.ts
    806:  Wrote /home/runner/work/liam/liam/frontend/packages/erd-core/src/features/erd/components/ERDRenderer/ErrorDisplay/ErrorDisplay.module.css.d.ts
    ...
    
    929:  ├ ƒ /app                                 325 B           204 kB
    930:  ├ ƒ /app/confirm                         325 B           204 kB
    931:  ├ ○ /app/login                           325 B           204 kB
    932:  ├ ƒ /app/projects                        663 B           270 kB
    933:  ├ ƒ /app/projects/new                    663 B           270 kB
    934:  ├ ○ /erd                                 326 B           204 kB
    935:  ├ ○ /erd/galaxy                          325 B           204 kB
    936:  ├ ƒ /erd/p/[...slug]                     516 kB          782 kB
    937:  └ ○ /error                               478 B           204 kB
    ...
    
    967:  Uploading [--------------------] (0.0B/19.1MB)
    968:  Uploading [=====---------------] (4.8MB/19.1MB)
    969:  Uploading [==========----------] (9.6MB/19.1MB)
    970:  Uploading [===============-----] (14.3MB/19.1MB)
    971:  Uploading [====================] (19.1MB/19.1MB)
    972:  Inspect: https://vercel.com/route-06-core/liam-app/Z5a5G5A94RFVPYsprE5dWpRX18n5 [6s]
    973:  Preview: https://liam-plzte9nai-route-06-core.vercel.app [6s]
    974:  Queued
    975:  ##[error]The operation was canceled.
    

    Copy link
    Member

    @MH4GF MH4GF left a comment

    Choose a reason for hiding this comment

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

    LGTM 👍🏻

    @FunamaYukina FunamaYukina added this pull request to the merge queue Mar 11, 2025
    Merged via the queue into main with commit 48d2c7a Mar 11, 2025
    19 checks passed
    @FunamaYukina FunamaYukina deleted the add-job-worker branch March 11, 2025 12:18
    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.

    3 participants