Skip to content

Commit 1392d68

Browse files
feat: Netlify & Github Actions added
1 parent b6950f5 commit 1392d68

File tree

7 files changed

+150
-16
lines changed

7 files changed

+150
-16
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy to Netlify Hosting on merge
2+
"on":
3+
push:
4+
branches:
5+
- master
6+
jobs:
7+
build_and_deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- run: npm ci && npm run build:ssr
12+
- uses: nwtgck/actions-netlify@v2
13+
with:
14+
publish-dir: "./dist/angular-signals-database/browser"
15+
production-branch: master
16+
production-deploy: true
17+
github-token: ${{ secrets.GITHUB_TOKEN }}
18+
deploy-message: "Deploy from GitHub Actions"
19+
netlify-config-path: "./netlify.toml"
20+
env:
21+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
22+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Deploy to Netlify Hosting on PR
2+
"on": pull_request
3+
jobs:
4+
build_and_preview:
5+
if: "${{ github.event.pull_request.head.repo.full_name == github.repository }}"
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v3
9+
- run: npm ci && npm run build:ssr
10+
- uses: nwtgck/actions-netlify@v2
11+
with:
12+
publish-dir: "./dist/angular-signals-database/browser"
13+
production-branch: master
14+
github-token: ${{ secrets.GITHUB_TOKEN }}
15+
deploy-message: "Deploy from GitHub Actions"
16+
enable-pull-request-comment: true
17+
enable-commit-comment: true
18+
overwrites-pull-request-comment: true
19+
netlify-config-path: "./netlify.toml"
20+
env:
21+
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
22+
NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }}

netlify.toml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
[[redirects]]
22
from = "/*"
3-
to = "/index.html"
3+
to = "/.netlify/functions/start"
44
status = 200
5-
5+
6+
[build]
7+
command = "ng build --configuration production && npm run copy:files"
8+
publish = "netlify/functions/"
9+
10+
[functions]
11+
included_files = ["dist/**"]

netlify/functions/start.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
const serverless = require('serverless-http');
2+
const { app } = require("./dist/angular-signals-database/server/main");
3+
4+
exports.handler = serverless((app));

package-lock.json

+79-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
"build": "ng build",
88
"watch": "ng build --watch --configuration development",
99
"test": "ng test",
10+
"test:ci": "ng test --no-watch --no-progress --browsers=ChromeHeadlessCI",
1011
"dev:ssr": "ng run angular-signals-database:serve-ssr",
1112
"serve:ssr": "node dist/angular-signals-database/server/main.js",
13+
"copy:files": "node ./scripts/copyFiles.js",
1214
"build:ssr": "ng build && ng run angular-signals-database:server",
1315
"prerender": "ng run angular-signals-database:prerender"
1416
},
@@ -25,9 +27,12 @@
2527
"@angular/platform-browser-dynamic": "^16.1.2",
2628
"@angular/platform-server": "^16.1.2",
2729
"@angular/router": "^16.1.2",
30+
"@netlify/functions": "^1.6.0",
2831
"@nguniversal/express-engine": "^16.1.0",
2932
"express": "^4.15.2",
33+
"fs-extra": "^11.1.1",
3034
"rxjs": "~7.8.1",
35+
"serverless-http": "^3.2.0",
3136
"tslib": "^2.5.3",
3237
"zone.js": "~0.13.1"
3338
},
@@ -47,4 +52,4 @@
4752
"karma-jasmine-html-reporter": "~2.1.0",
4853
"typescript": "~5.0.3"
4954
}
50-
}
55+
}

scripts/copyFiles.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const fs = require("fs-extra");
2+
3+
(async () => {
4+
const src = "./dist";
5+
const copy = "./netlify/functions/dist";
6+
7+
await fs.remove(copy);
8+
await fs.copy(src, copy);
9+
})();

0 commit comments

Comments
 (0)