Skip to content
Open
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
61 changes: 61 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: CI

permissions:
contents: read
issues: write
pull-requests: write

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 18

- id: install_deps
name: Install dependencies
run: npm ci

- id: run_tests
name: Run tests
run: npm test

- id: build_image
name: Build Docker image
run: docker build -t ${{ github.repository }}:${{ github.sha }} .

- name: Notify result
if: always()
uses: actions/github-script@v6
with:
script: |
const result = (process.env.RESULT || 'unknown');
const runUrl = `${process.env.GITHUB_SERVER_URL}/${context.repo.owner}/${context.repo.repo}/actions/runs/${process.env.GITHUB_RUN_ID}`;
const message = result === 'success'
? `✅ CI succeeded: ${runUrl}`
: `❌ CI result: ${result}. See details: ${runUrl}`;
const pr = context.payload.pull_request;
const isFork = pr && pr.head.repo.full_name !== `${context.repo.owner}/${context.repo.repo}`;
if (pr) {
if (isFork) {
core.info(`Skipping PR comment because this run originated from a fork: ${pr.head.repo.full_name}`);
} else {
await github.rest.issues.createComment({owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.number, body: message});
}
} else if (result !== 'success') {
await github.rest.issues.create({owner: context.repo.owner, repo: context.repo.repo, title: `CI ${result} - ${context.sha}`, body: message});
}
env:
RESULT: ${{ (steps.install_deps.outcome == 'success' && steps.run_tests.outcome == 'success' && steps.build_image.outcome == 'success') && 'success' || 'failure' }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:18-alpine

WORKDIR /app

COPY package*.json ./
RUN npm install --production

COPY . .

ENV PORT=3000
EXPOSE 3000

CMD ["node", "app.js"]
13 changes: 8 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ const port = process.env.PORT || 3001;

app.get("/", (req, res) => res.type('html').send(html));

const server = app.listen(port, () => console.log(`Example app listening on port ${port}!`));
if (require.main === module) {
const server = app.listen(port, () => console.log(`Example app listening on port ${port}!`));

server.keepAliveTimeout = 120 * 1000;
server.headersTimeout = 120 * 1000;
server.keepAliveTimeout = 120 * 1000;
server.headersTimeout = 120 * 1000;
}

const html = `
<!DOCTYPE html>
<html>
<head>
<title>Hello from Render!</title>
<title>Hello 23520210 - Vo Chi Cuong!</title>
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.5.1/dist/confetti.browser.min.js"></script>
<script>
setTimeout(() => {
Expand Down Expand Up @@ -54,8 +56,9 @@ const html = `
</head>
<body>
<section>
Hello from Render!
Hello 23520210 - Vo Chi Cuong!
</section>
</body>
</html>
`
module.exports = app;
Binary file added docker.pdf
Binary file not shown.
Binary file added git.pdf
Binary file not shown.
Loading