From eb5fc5f62488fbcdd79b256f49ac0e4da6f3b1d4 Mon Sep 17 00:00:00 2001 From: Duy Tran Date: Wed, 10 Dec 2025 17:48:54 +0700 Subject: [PATCH 1/4] feat(): add root url --- src/app.controller.ts | 9 +++++++++ src/app.module.ts | 2 ++ src/main.ts | 1 + 3 files changed, 12 insertions(+) create mode 100644 src/app.controller.ts diff --git a/src/app.controller.ts b/src/app.controller.ts new file mode 100644 index 0000000..6202e57 --- /dev/null +++ b/src/app.controller.ts @@ -0,0 +1,9 @@ +import { Controller, Get } from '@nestjs/common'; + +@Controller() +export class AppController { + @Get() + getHello(): string { + return 'hello'; + } +} diff --git a/src/app.module.ts b/src/app.module.ts index f96d2ed..9a12e8f 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -4,6 +4,7 @@ import { UserModule } from './user/user.module'; import { BookmarkModule } from './bookmark/bookmark.module'; import { PrismaModule } from './prisma/prisma.module'; import { ConfigModule } from '@nestjs/config'; +import { AppController } from './app.controller'; @Module({ imports: [ @@ -11,5 +12,6 @@ import { ConfigModule } from '@nestjs/config'; isGlobal: true }), AuthModule, UserModule, BookmarkModule, PrismaModule], + controllers: [AppController], }) export class AppModule {} diff --git a/src/main.ts b/src/main.ts index a4261f8..3371e6e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,5 +8,6 @@ async function bootstrap() { whitelist: true })); const port = process.env.PORT || 3333; + await app.listen(port); } bootstrap(); From 0f6c3ebb32d4c4c0857e4ac1307b6452a8203341 Mon Sep 17 00:00:00 2001 From: Duy Tran Date: Wed, 10 Dec 2025 18:04:10 +0700 Subject: [PATCH 2/4] feat(): fix action --- .github/workflows/railway-preview.yml | 98 ++------------------------- 1 file changed, 5 insertions(+), 93 deletions(-) diff --git a/.github/workflows/railway-preview.yml b/.github/workflows/railway-preview.yml index dcb21cb..9698bd6 100644 --- a/.github/workflows/railway-preview.yml +++ b/.github/workflows/railway-preview.yml @@ -14,108 +14,20 @@ concurrency: cancel-in-progress: true jobs: - deploy: + deploy-preview: runs-on: ubuntu-latest - if: ${{ github.event.action != 'closed' }} - steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Deploy to Railway Preview - id: deploy + - name: Railway Preview Deploy uses: ayungavis/railway-preview-deploy@v1.0.2 with: railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }} project_id: ${{ secrets.RAILWAY_PROJECT_ID }} - environment_name: 'production' - preview_environment_name: 'pr-${{ github.event.pull_request.number }}-${{ github.sha }}' - branch_name: ${{ github.head_ref }} - reuse_preview_environment: 'true' - - - name: Post deployment info - if: ${{ steps.deploy.outputs.service_domain != '' }} - run: | - echo "🚀 Preview deployed at: ${{ steps.deploy.outputs.service_domain }}" - echo "Preview URL: https://${{ steps.deploy.outputs.service_domain }}" - - - name: Post or update deployment comment - if: ${{ steps.deploy.outputs.service_domain != '' }} - uses: actions/github-script@v7 - with: - script: | - const marker = ''; - - const { data: commits } = await github.rest.pulls.listCommits({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: context.issue.number, - per_page: 1 - }); - - const latestCommit = commits[commits.length - 1]; - const latestCommitSha = latestCommit.sha.substring(0, 7); - const latestCommitAuthor = latestCommit.commit.author.name; - const latestCommitMessage = latestCommit.commit.message.split('\n')[0]; - - const { data: comments } = await github.rest.issues.listComments({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo - }); - - const body = ` - ${marker} - ## 🚀 Railway Preview Deployment - - **Preview URL:** [https://${{ steps.deploy.outputs.service_domain }}](https://${{ steps.deploy.outputs.service_domain }}) - - --- - - **Latest commit:** \`${latestCommitSha}\` - **Author:** ${latestCommitAuthor} - **Message:** ${latestCommitMessage} - - *This preview environment will be automatically cleaned up when the PR is closed or merged.* - `; - - const existingComment = comments.find(comment => - comment.user.type === 'Bot' && comment.body.includes(marker) - ); - - if (existingComment) { - await github.rest.issues.updateComment({ - comment_id: existingComment.id, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }); - console.log(`Updated comment ID: ${existingComment.id}`); - } else { - await github.rest.issues.createComment({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - body: body - }); - console.log('Created a new comment'); - } - - cleanup: - runs-on: ubuntu-latest - if: ${{ github.event.pull_request.merged == true || github.event.action == 'closed' }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Cleanup Railway Preview Environment - uses: ayungavis/railway-preview-deploy@v1.0.2 - with: - railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }} - project_id: ${{ secrets.RAILWAY_PROJECT_ID }} - environment_name: 'production' + environment_name: 'staging' preview_environment_name: 'pr-${{ github.event.pull_request.number }}' + environment_variables: + '{"DATABASE_URL": "postgres://user:pass@host/db"}' branch_name: ${{ github.head_ref }} cleanup: 'true' - From 97226d665654c03208d4c91a362961bf3cd29ace Mon Sep 17 00:00:00 2001 From: Duy Tran Date: Wed, 10 Dec 2025 18:05:44 +0700 Subject: [PATCH 3/4] feat(): update action --- .github/workflows/railway-preview.yml | 92 +++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/.github/workflows/railway-preview.yml b/.github/workflows/railway-preview.yml index 9698bd6..df244f8 100644 --- a/.github/workflows/railway-preview.yml +++ b/.github/workflows/railway-preview.yml @@ -14,20 +14,102 @@ concurrency: cancel-in-progress: true jobs: - deploy-preview: + deploy: runs-on: ubuntu-latest + if: ${{ github.event.action != 'closed' }} + steps: - name: Checkout repository uses: actions/checkout@v4 - - name: Railway Preview Deploy + - name: Deploy to Railway uses: ayungavis/railway-preview-deploy@v1.0.2 with: railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }} project_id: ${{ secrets.RAILWAY_PROJECT_ID }} environment_name: 'staging' preview_environment_name: 'pr-${{ github.event.pull_request.number }}' - environment_variables: - '{"DATABASE_URL": "postgres://user:pass@host/db"}' + environment_variables: | + { + "DATABASE_URL": "postgres://username:password@hostname/db" + } + branch_name: ${{ github.head_ref }} + + - name: Post deployment info + run: + echo "Preview deployed at ${{ steps.deploy.outputs.service_domain }}" + + - name: Post or update deployment comment + if: ${{ steps.test-action.outputs.service_domain != '' }} + uses: actions/github-script@v7 + with: + script: | + const marker = ''; // Unique marker to identify the comment + const { data: commits } = await github.rest.pulls.listCommits({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.issue.number, + per_page: 100 + }); + const latestCommit = commits[commits.length - 1]; + const latestCommitSha = latestCommit.sha.substring(0, 7); + const latestCommitAuthor = latestCommit.commit.author.name; + + + const { data: comments } = await github.rest.issues.listComments({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo + }); + + const body = ` + ${marker} + 🚀 **Deployment success!** + + - \`web\` deployed at [${{ steps.test-action.outputs.service_domain }}](https://${{ steps.test-action.outputs.service_domain }}) + + --- + + *commit: ${latestCommitSha}* + *author: ${latestCommitAuthor}* + `; + + const existingComment = comments.find(comment => comment.body.includes(marker)); + + if (existingComment) { + await github.rest.issues.updateComment({ + comment_id: existingComment.id, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + core.info(`Updated comment ID: ${existingComment.id}`); + } else { + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }); + core.info('Created a new comment'); + } + + cleanup: + runs-on: ubuntu-latest + if: + ${{ github.event.pull_request.merged == true || github.event.action == + 'closed' }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Cleanup Railway Environment + uses: ayungavis/railway-preview-deploy@v1.0.2 + with: + railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }} + project_id: ${{ secrets.RAILWAY_PROJECT_ID }} + environment_name: production + preview_environment_name: 'pr-${{ github.event.pull_request.number }}' branch_name: ${{ github.head_ref }} - cleanup: 'true' + cleanup: 'true' \ No newline at end of file From 77ea2e2bdb7f1a3582f17ef1a141e860a12b1cbc Mon Sep 17 00:00:00 2001 From: Duy Tran Date: Wed, 10 Dec 2025 18:06:57 +0700 Subject: [PATCH 4/4] feat(): update action --- .github/workflows/railway-preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/railway-preview.yml b/.github/workflows/railway-preview.yml index df244f8..e39144b 100644 --- a/.github/workflows/railway-preview.yml +++ b/.github/workflows/railway-preview.yml @@ -27,7 +27,7 @@ jobs: with: railway_api_token: ${{ secrets.RAILWAY_API_TOKEN }} project_id: ${{ secrets.RAILWAY_PROJECT_ID }} - environment_name: 'staging' + environment_name: 'production' preview_environment_name: 'pr-${{ github.event.pull_request.number }}' environment_variables: | {