Skip to content

Commit c05c223

Browse files
committed
feat: support replace deployment
1 parent f893699 commit c05c223

File tree

11 files changed

+225
-76
lines changed

11 files changed

+225
-76
lines changed

.github/workflows/release.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches: [master]
6+
7+
jobs:
8+
release:
9+
name: Release
10+
runs-on: ubuntu-latest
11+
env:
12+
GH_TOKEN: ${{ secrets.GH_TOKEN }}
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v2
16+
with:
17+
persist-credentials: false
18+
19+
- name: Install Node.js and npm
20+
uses: actions/setup-node@v1
21+
with:
22+
node-version: 14.x
23+
registry-url: https://registry.npmjs.org
24+
25+
- name: Retrieve dependencies from cache
26+
id: cacheNpm
27+
uses: actions/cache@v2
28+
with:
29+
path: |
30+
~/.npm
31+
node_modules
32+
key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }}
33+
restore-keys: npm-v14-${{ runner.os }}-refs/heads/master-
34+
35+
- name: Install dependencies
36+
if: steps.cacheNpm.outputs.cache-hit != 'true'
37+
run: |
38+
npm update --no-save
39+
npm update --save-dev --no-save
40+
- name: Releasing
41+
run: |
42+
npm run release
43+
env:
44+
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
45+
GIT_AUTHOR_NAME: slsplus
46+
GIT_AUTHOR_EMAIL: yuga.sun.bj@gmail.com
47+
GIT_COMMITTER_NAME: slsplus
48+
GIT_COMMITTER_EMAIL: yuga.sun.bj@gmail.com

.github/workflows/test.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
test:
9+
name: Test
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
with:
15+
# Ensure connection with 'master' branch
16+
fetch-depth: 2
17+
18+
- name: Install Node.js and npm
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: 14.x
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Retrieve dependencies from cache
25+
id: cacheNpm
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.npm
30+
node_modules
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
- name: Running integration tests
42+
run: npm run test
43+
env:
44+
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
45+
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}

.github/workflows/validate.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Validate
2+
3+
on:
4+
pull_request:
5+
branches: [master]
6+
7+
jobs:
8+
lintAndFormatting:
9+
name: Lint & Formatting
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout repository
13+
uses: actions/checkout@v2
14+
with:
15+
# Ensure connection with 'master' branch
16+
fetch-depth: 2
17+
18+
- name: Install Node.js and npm
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: 14.x
22+
registry-url: https://registry.npmjs.org
23+
24+
- name: Retrieve dependencies from cache
25+
id: cacheNpm
26+
uses: actions/cache@v2
27+
with:
28+
path: |
29+
~/.npm
30+
node_modules
31+
key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }}
32+
restore-keys: |
33+
npm-v14-${{ runner.os }}-${{ github.ref }}-
34+
npm-v14-${{ runner.os }}-refs/heads/master-
35+
36+
- name: Install dependencies
37+
if: steps.cacheNpm.outputs.cache-hit != 'true'
38+
run: |
39+
npm update --no-save
40+
npm update --save-dev --no-save
41+
42+
- name: Validate Formatting
43+
run: npm run prettier:fix
44+
- name: Validate Lint rules
45+
run: npm run lint:fix

.travis.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,9 @@ $ touch .env # 腾讯云的配置信息
152152
TENCENT_SECRET_ID=123
153153
TENCENT_SECRET_KEY=123
154154
```
155+
156+
## License
157+
158+
MIT License
159+
160+
Copyright (c) 2020 Tencent Cloud, Inc.

docs/configure.md

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ inputs:
2121
region: ap-guangzhou
2222
bucketName: my-bucket
2323
protocol: http
24+
replace: false # 是否替换式部署
2425
hosts:
2526
- host: abc.com
2627
async: true
@@ -88,68 +89,69 @@ inputs:
8889
8990
主要参数描述
9091
91-
| 参数名称 | 是否必选 | 默认值 | 描述 |
92-
| ------------------ | :------: | :----------: | :---------------------------------------------------------------------------------------- |
93-
| [src](#执行目录) | 是 | | 该项目的代码信息,参数参考执行目录 |
94-
| region | 否 | ap-guangzhou | 代码上传所在的 cos 区域。默认为广州区。 |
95-
| bucketName | 是 | | Bucket 名称。 不允许大写字母。如果你不加 AppId 后缀,则默认自动会为你加上。 |
96-
| protocol | 否 | https | 请求协议。Https 或 http |
97-
| env | 否 | | 环境变量参数文件。会将 env 下配置的参数写入 env.js 文件中,将该文件打包上传到你的代码里。 |
98-
| envPath | 否 | | 生成的 env.js 存放在你项目中的路径。默认是当前工作路径。 |
99-
| [cors](#跨域配置) | 否 | | 跨域访问配置 |
100-
| [hosts](#CDN-配置) | 否 | | CND 加速域名配置 |
92+
| 参数名称 | 必选 | 默认值 | 描述 |
93+
| ------------------ | :--: | :------------: | :---------------------------------------------------------------------------------------- |
94+
| [src](#执行目录) | 是 | | 该项目的代码信息,参数参考执行目录 |
95+
| bucketName | 是 | | Bucket 名称。 不允许大写字母。如果你不加 AppId 后缀,则默认自动会为你加上。 |
96+
| region | 否 | `ap-guangzhou` | 代码上传所在的 cos 区域。区。 |
97+
| replace | 否 | `false` | 是否是替换式部署,如果为 `true`,部署时将 `先删除对应 bucket 的所有旧文件`。 |
98+
| protocol | 否 | `https` | 请求协议。`https` 或 `http` |
99+
| env | 否 | | 环境变量参数文件。会将 env 下配置的参数写入 env.js 文件中,将该文件打包上传到你的代码里。 |
100+
| envPath | 否 | | 生成的 env.js 存放在你项目中的路径。默认是当前工作路径。 |
101+
| [cors](#跨域配置) | 否 | | 跨域访问配置 |
102+
| [hosts](#CDN-配置) | 否 | | CND 加速域名配置 |
101103

102104
### 执行目录
103105

104-
| 参数名称 | 是否必选 | 默认值 | 描述 |
105-
| -------- | :------: | :--------: | :----------------------------------------------------------- |
106-
| src | | | 你构建的项目代码目录。 |
107-
| dist | | | 钩子脚本执行构建后,输出的目录。如果配置 `hook`, 此参数必填 |
108-
| hook | | | 钩子脚本。在你项目代码上传之前执行。 |
109-
| index | | index.html | 网站 index 页面 |
110-
| error | | error.html | 网站 error 页面 |
106+
| 参数名称 | 必选 | 默认值 | 描述 |
107+
| -------- | :--: | :----------: | :----------------------------------------------------------- |
108+
| src | 是 | | 你构建的项目代码目录。 |
109+
| dist | 否 | | 钩子脚本执行构建后,输出的目录。如果配置 `hook`, 此参数必填 |
110+
| hook | 否 | | 钩子脚本。在你项目代码上传之前执行。 |
111+
| index | 否 | `index.html` | 网站 index 页面 |
112+
| error | 否 | `error.html` | 网站 error 页面 |
111113

112114
### 跨域配置
113115

114116
参考: https://cloud.tencent.com/document/product/436/8279
115117

116-
| 参数 | 是否必选 | 类型 | Description |
117-
| -------------- | :------: | -------- | :--------------------------------------------------------------------------------------------- |
118-
| id | | String | 规则 ID |
119-
| allowedMethods | | String[] | 允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE |
120-
| allowedOrigins | | String[] | 允许的访问来源,支持通配符`*`,格式为:`协议://域名[:端口]`,例如:`http://www.qq.com` |
121-
| allowedHeaders | | | 在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符`*` |
122-
| maxAgeSeconds | shi | | 设置 OPTIONS 请求得到结果的有效期 |
118+
| 参数 | 必选 | 类型 | Description |
119+
| -------------- | :--: | -------- | :--------------------------------------------------------------------------------------------- |
120+
| id | | String | 规则 ID |
121+
| allowedMethods | | String[] | 允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE |
122+
| allowedOrigins | | String[] | 允许的访问来源,支持通配符`*`,格式为:`协议://域名[:端口]`,例如:`http://www.qq.com` |
123+
| allowedHeaders | | | 在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符`*` |
124+
| maxAgeSeconds | | | 设置 OPTIONS 请求得到结果的有效期 |
123125

124126
### CDN 配置
125127

126-
| 参数名称 | 是否必选 | 默认 | 描述 |
127-
| ----------- | -------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
128-
| async | 否 | `false` | 是否为异步操作,如果为 true,则不会等待 CDN 创建或更新成功再返回, |
129-
| area | 否 | `mainland` | 域名加速区域,mainland:中国境内加速,overseas:中国境外加速,global:全球加速,(使用中国境外加速、全球加速时,需要先开通中国境外加速服务) |
130-
| autoRefresh | 否 | `false` | 是否自动刷新 CDN |
131-
| onlyRefresh | 否 | `false` | 是否只刷新预热 CDN,如果为 `true`,那么只进行刷新预热操作,不会更新 CDN 配置 |
132-
| refreshCdn | 否 | | 刷新 CDN 相关配置,参考 [refreshCdn](#refreshCdn) |
133-
| pushCdn | 否 | | 预热 CDN 相关配置,参考 [pushCdn](#pushCdn) |
134-
| host | 是 | | 需要接入的 CDN 域名。 |
135-
| https | 否 | | Https 加速配置,参考:https://cloud.tencent.com/document/api/228/30987#Https |
136-
| cacheKey | 否 | | 节点缓存键配置,参考:https://cloud.tencent.com/document/api/228/30987#CacheKey |
137-
| cache | 否 | | 缓存过期时间配置,参考: https://cloud.tencent.com/document/api/228/30987#Cache |
138-
| referer | 否 | '' | 防盗链设置,参考: https://cloud.tencent.com/document/api/228/30987#Referer |
139-
| ipFilter | 否 | '' | IP 黑白名单配置,参考: https://cloud.tencent.com/document/api/228/30987#IpFilter |
128+
| 参数名称 | 必选 | 默认 | 描述 |
129+
| ----------- | ---- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
130+
| async | 否 | `false` | 是否为异步操作,如果为 true,则不会等待 CDN 创建或更新成功再返回, |
131+
| area | 否 | `mainland` | 域名加速区域,mainland:中国境内加速,overseas:中国境外加速,global:全球加速,(使用中国境外加速、全球加速时,需要先开通中国境外加速服务) |
132+
| autoRefresh | 否 | `false` | 是否自动刷新 CDN |
133+
| onlyRefresh | 否 | `false` | 是否只刷新预热 CDN,如果为 `true`,那么只进行刷新预热操作,不会更新 CDN 配置 |
134+
| refreshCdn | 否 | | 刷新 CDN 相关配置,参考 [refreshCdn](#refreshCdn) |
135+
| pushCdn | 否 | | 预热 CDN 相关配置,参考 [pushCdn](#pushCdn) |
136+
| host | 是 | | 需要接入的 CDN 域名。 |
137+
| https | 否 | | Https 加速配置,参考:https://cloud.tencent.com/document/api/228/30987#Https |
138+
| cacheKey | 否 | | 节点缓存键配置,参考:https://cloud.tencent.com/document/api/228/30987#CacheKey |
139+
| cache | 否 | | 缓存过期时间配置,参考: https://cloud.tencent.com/document/api/228/30987#Cache |
140+
| referer | 否 | '' | 防盗链设置,参考: https://cloud.tencent.com/document/api/228/30987#Referer |
141+
| ipFilter | 否 | '' | IP 黑白名单配置,参考: https://cloud.tencent.com/document/api/228/30987#IpFilter |
140142

141143
> 注意:`async` 参数对于配置多个 CDN 域名需求,或者在 CI 流程中时,建议配置成 `true`,不然会导致 serverless cli 执行超时,或者 CI 流程超时。
142144

143145
更多配置,请移至官方云 API 文档:https://cloud.tencent.com/document/product/228/41123
144146

145147
#### refreshCdn
146148

147-
| 参数名称 | 是否必选 | 默认 | 描述 |
148-
| -------- | -------- | ---- | ------------------- |
149-
| urls | 否 | [] | 需要刷新的 CDN 目录 |
149+
| 参数名称 | 必选 | 默认 | 描述 |
150+
| -------- | ---- | ---- | ------------------- |
151+
| urls | 否 | [] | 需要刷新的 CDN 目录 |
150152

151153
#### pushCdn
152154

153-
| 参数名称 | 是否必选 | 默认 | 描述 |
154-
| -------- | -------- | ---- | ------------------- |
155-
| urls | 否 | [] | 需要预热的 CDN URLs |
155+
| 参数名称 | 必选 | 默认 | 描述 |
156+
| -------- | ---- | ---- | ------------------- |
157+
| urls | 否 | [] | 需要预热的 CDN URLs |

package.json

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"publishConfig": {
55
"access": "public"
66
},
7+
"description": "Easily deploy serverless websites (e.g. Vue.js, React, static) to Tencent Cloud with the Serverless Framework",
78
"scripts": {
8-
"int-test": "jest ./tests/integration.test.js --testEnvironment node",
9-
"test": "npm run lint && npm run prettier && npm run int-test",
9+
"test": "jest ./tests/integration.test.js --testEnvironment node",
1010
"commitlint": "commitlint -f HEAD@{15}",
1111
"lint": "eslint --ext .js,.ts,.tsx .",
1212
"lint:fix": "eslint --fix --ext .js,.ts,.tsx .",
@@ -57,5 +57,26 @@
5757
"lint-staged": "^10.0.8",
5858
"prettier": "^1.19.1",
5959
"semantic-release": "^17.0.4"
60-
}
60+
},
61+
"directories": {
62+
"doc": "docs",
63+
"example": "example",
64+
"test": "tests"
65+
},
66+
"repository": {
67+
"type": "git",
68+
"url": "git+https://github.com/serverless-components/tencent-website.git"
69+
},
70+
"keywords": [
71+
"serverless-website",
72+
"serverless",
73+
"website",
74+
"serverless-framework",
75+
"serverless-components",
76+
"tencent-cloud"
77+
],
78+
"bugs": {
79+
"url": "https://github.com/serverless-components/tencent-website/issues"
80+
},
81+
"homepage": "https://github.com/serverless-components/tencent-website#readme"
6182
}

serverless.component.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: website
2-
version: 0.0.15
2+
version: 0.1.0
33
author: 'Tencent Cloud, Inc.'
44
org: 'Tencent Cloud, Inc.'
55
description: Deploy a static website on Tencent Cloud.

src/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"dependencies": {
33
"download": "^8.0.0",
4-
"tencent-component-toolkit": "^1.17.2",
4+
"tencent-component-toolkit": "^1.17.3",
55
"type": "^2.1.0"
66
}
77
}

src/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const prepareInputs = async (instance, inputs) => {
6565
removeAppid(inputs.bucketName, appId) || `sls-website-${region}-${generateId()}`
6666

6767
return {
68+
replace: inputs.replace,
6869
useDefault: !code.src,
6970
code: {
7071
src: sourceDirectory,

0 commit comments

Comments
 (0)