diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4c476a4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,48 @@ +name: Release + +on: + push: + branches: [master] + +jobs: + release: + name: Release + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GH_TOKEN }} + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + persist-credentials: false + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 14.x + registry-url: https://registry.npmjs.org + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v14-${{ runner.os }}-refs/heads/master-${{ hashFiles('package.json') }} + restore-keys: npm-v14-${{ runner.os }}-refs/heads/master- + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Releasing + run: | + npm run release + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + GIT_AUTHOR_NAME: slsplus + GIT_AUTHOR_EMAIL: yuga.sun.bj@gmail.com + GIT_COMMITTER_NAME: slsplus + GIT_COMMITTER_EMAIL: yuga.sun.bj@gmail.com diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..e8bdb44 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,45 @@ +name: Test + +on: + pull_request: + branches: [master] + +jobs: + test: + name: Test + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # Ensure connection with 'master' branch + fetch-depth: 2 + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 14.x + registry-url: https://registry.npmjs.org + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v14-${{ runner.os }}-${{ github.ref }}- + npm-v14-${{ runner.os }}-refs/heads/master- + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + - name: Running integration tests + run: npm run test + env: + TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} + TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..3840792 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,45 @@ +name: Validate + +on: + pull_request: + branches: [master] + +jobs: + lintAndFormatting: + name: Lint & Formatting + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + # Ensure connection with 'master' branch + fetch-depth: 2 + + - name: Install Node.js and npm + uses: actions/setup-node@v1 + with: + node-version: 14.x + registry-url: https://registry.npmjs.org + + - name: Retrieve dependencies from cache + id: cacheNpm + uses: actions/cache@v2 + with: + path: | + ~/.npm + node_modules + key: npm-v14-${{ runner.os }}-${{ github.ref }}-${{ hashFiles('package.json') }} + restore-keys: | + npm-v14-${{ runner.os }}-${{ github.ref }}- + npm-v14-${{ runner.os }}-refs/heads/master- + + - name: Install dependencies + if: steps.cacheNpm.outputs.cache-hit != 'true' + run: | + npm update --no-save + npm update --save-dev --no-save + + - name: Validate Formatting + run: npm run prettier:fix + - name: Validate Lint rules + run: npm run lint:fix diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index d78fad9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,23 +0,0 @@ -language: node_js - -node_js: - - 10 - -install: - - npm install - -# should change to serverless registry publish -jobs: - include: - # Define the release stage that runs semantic-release - - stage: release - node_js: 10.18 - # Advanced: optionally overwrite your default `script` step to skip the tests - # script: skip - deploy: - provider: script - skip_cleanup: true - on: - branch: master - script: - - npm run release diff --git a/CHANGELOG.md b/CHANGELOG.md index d2ad28a..12205d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [0.1.0](https://github.com/serverless-components/tencent-website/compare/v0.0.15...v0.1.0) (2020-10-15) + + +### Features + +* support replace deployment ([c05c223](https://github.com/serverless-components/tencent-website/commit/c05c223988f7eb4e7e70af5656d44a295e66c260)) + ## [0.0.15](https://github.com/serverless-components/tencent-website/compare/v0.0.14...v0.0.15) (2020-10-13) diff --git a/README.md b/README.md index f2d78a0..77cbcda 100644 --- a/README.md +++ b/README.md @@ -152,3 +152,9 @@ $ touch .env # 腾讯云的配置信息 TENCENT_SECRET_ID=123 TENCENT_SECRET_KEY=123 ``` + +## License + +MIT License + +Copyright (c) 2020 Tencent Cloud, Inc. diff --git a/docs/configure.md b/docs/configure.md index 320d8d5..55394c9 100644 --- a/docs/configure.md +++ b/docs/configure.md @@ -21,6 +21,7 @@ inputs: region: ap-guangzhou bucketName: my-bucket protocol: http + replace: false # 是否替换式部署 hosts: - host: abc.com async: true @@ -88,55 +89,56 @@ inputs: 主要参数描述 -| 参数名称 | 是否必选 | 默认值 | 描述 | -| ------------------ | :------: | :----------: | :---------------------------------------------------------------------------------------- | -| [src](#执行目录) | 是 | | 该项目的代码信息,参数参考执行目录 | -| region | 否 | ap-guangzhou | 代码上传所在的 cos 区域。默认为广州区。 | -| bucketName | 是 | | Bucket 名称。 不允许大写字母。如果你不加 AppId 后缀,则默认自动会为你加上。 | -| protocol | 否 | https | 请求协议。Https 或 http | -| env | 否 | | 环境变量参数文件。会将 env 下配置的参数写入 env.js 文件中,将该文件打包上传到你的代码里。 | -| envPath | 否 | | 生成的 env.js 存放在你项目中的路径。默认是当前工作路径。 | -| [cors](#跨域配置) | 否 | | 跨域访问配置 | -| [hosts](#CDN-配置) | 否 | | CND 加速域名配置 | +| 参数名称 | 必选 | 默认值 | 描述 | +| ------------------ | :--: | :------------: | :---------------------------------------------------------------------------------------- | +| [src](#执行目录) | 是 | | 该项目的代码信息,参数参考执行目录 | +| bucketName | 是 | | Bucket 名称。 不允许大写字母。如果你不加 AppId 后缀,则默认自动会为你加上。 | +| region | 否 | `ap-guangzhou` | 代码上传所在的 cos 区域。区。 | +| replace | 否 | `false` | 是否是替换式部署,如果为 `true`,部署时将 `先删除对应 bucket 的所有旧文件`。 | +| protocol | 否 | `https` | 请求协议。`https` 或 `http` | +| env | 否 | | 环境变量参数文件。会将 env 下配置的参数写入 env.js 文件中,将该文件打包上传到你的代码里。 | +| envPath | 否 | | 生成的 env.js 存放在你项目中的路径。默认是当前工作路径。 | +| [cors](#跨域配置) | 否 | | 跨域访问配置 | +| [hosts](#CDN-配置) | 否 | | CND 加速域名配置 | ### 执行目录 -| 参数名称 | 是否必选 | 默认值 | 描述 | -| -------- | :------: | :--------: | :----------------------------------------------------------- | -| src | 是 | | 你构建的项目代码目录。 | -| dist | 否 | | 钩子脚本执行构建后,输出的目录。如果配置 `hook`, 此参数必填 | -| hook | 否 | | 钩子脚本。在你项目代码上传之前执行。 | -| index | 否 | index.html | 网站 index 页面 | -| error | 否 | error.html | 网站 error 页面 | +| 参数名称 | 必选 | 默认值 | 描述 | +| -------- | :--: | :----------: | :----------------------------------------------------------- | +| src | 是 | | 你构建的项目代码目录。 | +| dist | 否 | | 钩子脚本执行构建后,输出的目录。如果配置 `hook`, 此参数必填 | +| hook | 否 | | 钩子脚本。在你项目代码上传之前执行。 | +| index | 否 | `index.html` | 网站 index 页面 | +| error | 否 | `error.html` | 网站 error 页面 | ### 跨域配置 参考: https://cloud.tencent.com/document/product/436/8279 -| 参数 | 是否必选 | 类型 | Description | -| -------------- | :------: | -------- | :--------------------------------------------------------------------------------------------- | -| id | 否 | String | 规则 ID | -| allowedMethods | 是 | String[] | 允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE | -| allowedOrigins | 是 | String[] | 允许的访问来源,支持通配符`*`,格式为:`协议://域名[:端口]`,例如:`http://www.qq.com` | -| allowedHeaders | 是 | | 在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符`*` | -| maxAgeSeconds | shi | | 设置 OPTIONS 请求得到结果的有效期 | +| 参数 | 必选 | 类型 | Description | +| -------------- | :--: | -------- | :--------------------------------------------------------------------------------------------- | +| id | 否 | String | 规则 ID | +| allowedMethods | 是 | String[] | 允许的 HTTP 操作,枚举值:GET,PUT,HEAD,POST,DELETE | +| allowedOrigins | 是 | String[] | 允许的访问来源,支持通配符`*`,格式为:`协议://域名[:端口]`,例如:`http://www.qq.com` | +| allowedHeaders | 是 | | 在发送 OPTIONS 请求时告知服务端,接下来的请求可以使用哪些自定义的 HTTP 请求头部,支持通配符`*` | +| maxAgeSeconds | 是 | | 设置 OPTIONS 请求得到结果的有效期 | ### CDN 配置 -| 参数名称 | 是否必选 | 默认 | 描述 | -| ----------- | -------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- | -| async | 否 | `false` | 是否为异步操作,如果为 true,则不会等待 CDN 创建或更新成功再返回, | -| area | 否 | `mainland` | 域名加速区域,mainland:中国境内加速,overseas:中国境外加速,global:全球加速,(使用中国境外加速、全球加速时,需要先开通中国境外加速服务) | -| autoRefresh | 否 | `false` | 是否自动刷新 CDN | -| onlyRefresh | 否 | `false` | 是否只刷新预热 CDN,如果为 `true`,那么只进行刷新预热操作,不会更新 CDN 配置 | -| refreshCdn | 否 | | 刷新 CDN 相关配置,参考 [refreshCdn](#refreshCdn) | -| pushCdn | 否 | | 预热 CDN 相关配置,参考 [pushCdn](#pushCdn) | -| host | 是 | | 需要接入的 CDN 域名。 | -| https | 否 | | Https 加速配置,参考:https://cloud.tencent.com/document/api/228/30987#Https | -| cacheKey | 否 | | 节点缓存键配置,参考:https://cloud.tencent.com/document/api/228/30987#CacheKey | -| cache | 否 | | 缓存过期时间配置,参考: https://cloud.tencent.com/document/api/228/30987#Cache | -| referer | 否 | '' | 防盗链设置,参考: https://cloud.tencent.com/document/api/228/30987#Referer | -| ipFilter | 否 | '' | IP 黑白名单配置,参考: https://cloud.tencent.com/document/api/228/30987#IpFilter | +| 参数名称 | 必选 | 默认 | 描述 | +| ----------- | ---- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- | +| async | 否 | `false` | 是否为异步操作,如果为 true,则不会等待 CDN 创建或更新成功再返回, | +| area | 否 | `mainland` | 域名加速区域,mainland:中国境内加速,overseas:中国境外加速,global:全球加速,(使用中国境外加速、全球加速时,需要先开通中国境外加速服务) | +| autoRefresh | 否 | `false` | 是否自动刷新 CDN | +| onlyRefresh | 否 | `false` | 是否只刷新预热 CDN,如果为 `true`,那么只进行刷新预热操作,不会更新 CDN 配置 | +| refreshCdn | 否 | | 刷新 CDN 相关配置,参考 [refreshCdn](#refreshCdn) | +| pushCdn | 否 | | 预热 CDN 相关配置,参考 [pushCdn](#pushCdn) | +| host | 是 | | 需要接入的 CDN 域名。 | +| https | 否 | | Https 加速配置,参考:https://cloud.tencent.com/document/api/228/30987#Https | +| cacheKey | 否 | | 节点缓存键配置,参考:https://cloud.tencent.com/document/api/228/30987#CacheKey | +| cache | 否 | | 缓存过期时间配置,参考: https://cloud.tencent.com/document/api/228/30987#Cache | +| referer | 否 | '' | 防盗链设置,参考: https://cloud.tencent.com/document/api/228/30987#Referer | +| ipFilter | 否 | '' | IP 黑白名单配置,参考: https://cloud.tencent.com/document/api/228/30987#IpFilter | > 注意:`async` 参数对于配置多个 CDN 域名需求,或者在 CI 流程中时,建议配置成 `true`,不然会导致 serverless cli 执行超时,或者 CI 流程超时。 @@ -144,12 +146,12 @@ inputs: #### refreshCdn -| 参数名称 | 是否必选 | 默认 | 描述 | -| -------- | -------- | ---- | ------------------- | -| urls | 否 | [] | 需要刷新的 CDN 目录 | +| 参数名称 | 必选 | 默认 | 描述 | +| -------- | ---- | ---- | ------------------- | +| urls | 否 | [] | 需要刷新的 CDN 目录 | #### pushCdn -| 参数名称 | 是否必选 | 默认 | 描述 | -| -------- | -------- | ---- | ------------------- | -| urls | 否 | [] | 需要预热的 CDN URLs | +| 参数名称 | 必选 | 默认 | 描述 | +| -------- | ---- | ---- | ------------------- | +| urls | 否 | [] | 需要预热的 CDN URLs | diff --git a/package.json b/package.json index 26e171b..db19134 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "publishConfig": { "access": "public" }, + "description": "Easily deploy serverless websites (e.g. Vue.js, React, static) to Tencent Cloud with the Serverless Framework", "scripts": { - "int-test": "jest ./tests/integration.test.js --testEnvironment node", - "test": "npm run lint && npm run prettier && npm run int-test", + "test": "jest ./tests/integration.test.js --testEnvironment node", "commitlint": "commitlint -f HEAD@{15}", "lint": "eslint --ext .js,.ts,.tsx .", "lint:fix": "eslint --fix --ext .js,.ts,.tsx .", @@ -57,5 +57,26 @@ "lint-staged": "^10.0.8", "prettier": "^1.19.1", "semantic-release": "^17.0.4" - } + }, + "directories": { + "doc": "docs", + "example": "example", + "test": "tests" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/serverless-components/tencent-website.git" + }, + "keywords": [ + "serverless-website", + "serverless", + "website", + "serverless-framework", + "serverless-components", + "tencent-cloud" + ], + "bugs": { + "url": "https://github.com/serverless-components/tencent-website/issues" + }, + "homepage": "https://github.com/serverless-components/tencent-website#readme" } diff --git a/serverless.component.yml b/serverless.component.yml index 51107cb..7361c7b 100644 --- a/serverless.component.yml +++ b/serverless.component.yml @@ -1,5 +1,5 @@ name: website -version: 0.0.15 +version: 0.1.0 author: 'Tencent Cloud, Inc.' org: 'Tencent Cloud, Inc.' description: Deploy a static website on Tencent Cloud. diff --git a/src/package.json b/src/package.json index 44d3032..c4e77b5 100644 --- a/src/package.json +++ b/src/package.json @@ -1,7 +1,7 @@ { "dependencies": { "download": "^8.0.0", - "tencent-component-toolkit": "^1.17.2", + "tencent-component-toolkit": "^1.17.3", "type": "^2.1.0" } } diff --git a/src/utils.js b/src/utils.js index 590fd7b..9fe8688 100644 --- a/src/utils.js +++ b/src/utils.js @@ -65,6 +65,7 @@ const prepareInputs = async (instance, inputs) => { removeAppid(inputs.bucketName, appId) || `sls-website-${region}-${generateId()}` return { + replace: inputs.replace, useDefault: !code.src, code: { src: sourceDirectory, diff --git a/tests/integration.test.js b/tests/integration.test.js index 068fa8f..8af039d 100644 --- a/tests/integration.test.js +++ b/tests/integration.test.js @@ -1,3 +1,5 @@ +const path = require('path') +require('dotenv').config({path: path.join(__dirname, '..', '.env.test')}) const { generateId, getServerlessSdk } = require('./utils') // set enough timeout for deployment to finish @@ -11,22 +13,24 @@ const instanceYaml = { name: `website-integration-tests-${generateId()}`, stage: 'dev', inputs: { - src: './example', + src: path.join(__dirname, '..', 'example'), bucketName: 'my-bucket', region: 'ap-guangzhou' } } -// get credentials from process.env but need to init empty credentials object const credentials = { - tencent: {} + tencent: { + SecretId: process.env.TENCENT_SECRET_ID, + SecretKey: process.env.TENCENT_SECRET_KEY, + } } // get serverless construct sdk const sdk = getServerlessSdk(instanceYaml.org) it('should successfully deploy website app', async () => { - const instance = await sdk.deploy(instanceYaml, { tencent: {} }) + const instance = await sdk.deploy(instanceYaml, credentials) expect(instance).toBeDefined() expect(instance.instanceName).toEqual(instanceYaml.name)