Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 27 additions & 33 deletions .github/workflows/railway-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,39 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Deploy to Railway Preview
id: 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: 'production'
preview_environment_name: 'pr-${{ github.event.pull_request.number }}-${{ github.sha }}'
preview_environment_name: 'pr-${{ github.event.pull_request.number }}'
environment_variables: |
{
"DATABASE_URL": "postgres://username:password@hostname/db"
}
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 }}"
run:
echo "Preview deployed at ${{ steps.deploy.outputs.service_domain }}"

- name: Post or update deployment comment
if: ${{ steps.deploy.outputs.service_domain != '' }}
if: ${{ steps.test-action.outputs.service_domain != '' }}
uses: actions/github-script@v7
with:
script: |
const marker = '<!-- railway-preview-comment -->';

const marker = '<!-- preview-comment -->'; // 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: 1
per_page: 100
});

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,
Expand All @@ -65,23 +63,18 @@ jobs:
});

const body = `
${marker}
## 🚀 Railway Preview Deployment
${marker} <!-- This marker helps identify the comment for future updates -->
🚀 **Deployment success!**

**Preview URL:** [https://${{ steps.deploy.outputs.service_domain }}](https://${{ steps.deploy.outputs.service_domain }})
- \`web\` deployed at [${{ steps.test-action.outputs.service_domain }}](https://${{ steps.test-action.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.*

*commit: ${latestCommitSha}*
*author: ${latestCommitAuthor}*
`;

const existingComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes(marker)
);
const existingComment = comments.find(comment => comment.body.includes(marker));

if (existingComment) {
await github.rest.issues.updateComment({
Expand All @@ -90,32 +83,33 @@ jobs:
repo: context.repo.repo,
body: body
});
console.log(`Updated comment ID: ${existingComment.id}`);
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
});
console.log('Created a new comment');
core.info('Created a new comment');
}

cleanup:
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.merged == true || github.event.action == 'closed' }}
if:
${{ github.event.pull_request.merged == true || github.event.action ==
'closed' }}

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Cleanup Railway Preview Environment
- 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'
environment_name: production
preview_environment_name: 'pr-${{ github.event.pull_request.number }}'
branch_name: ${{ github.head_ref }}
cleanup: 'true'

cleanup: 'true'
9 changes: 9 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';

@Controller()
export class AppController {
@Get()
getHello(): string {
return 'hello';
}
}
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ 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: [
ConfigModule.forRoot({
isGlobal: true
}),
AuthModule, UserModule, BookmarkModule, PrismaModule],
controllers: [AppController],
})
export class AppModule {}
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ async function bootstrap() {
whitelist: true
}));
const port = process.env.PORT || 3333;
await app.listen(port);
}
bootstrap();