Skip to content

Commit f4608ad

Browse files
authored
feat: support policy and optimize deploy flow (#11)
* feat: support policy and optimize deploy flow * chore: remove unuse tests folder
1 parent d0fae91 commit f4608ad

25 files changed

+503
-339
lines changed

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ coverage
22
dist
33
node_modules
44
example
5-
*.test.js
6-
src/_src

.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: slsplus.sz@gmail.com
47+
GIT_COMMITTER_NAME: slsplus
48+
GIT_COMMITTER_EMAIL: slsplus.sz@gmail.com

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
SERVERLESS_PLATFORM_VENDOR: tencent
45+
GLOBAL_ACCELERATOR_NA: true
46+
TENCENT_APP_ID: ${{ secrets.TENCENT_APP_ID }}
47+
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
48+
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

.prettierignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ coverage
22
dist
33
node_modules
44
CHANGELOG.md
5-
*.test.js

.travis.yml

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

README.en.md

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

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# 腾讯云对象存储 COS 组件
22

3-
简体中文 | [English](https://github.com/serverless-components/tencent-cos/tree/master/README.en.md)
4-
53
## 简介
64

75
通过对象存储 COS 组件,可以快速,方便的创建,配置和管理腾讯云的 COS 存储桶
@@ -34,14 +32,14 @@ $ touch serverless.yml
3432
```yml
3533
# serverless.yml
3634

37-
org: orgDemo
3835
app: appDemo
3936
stage: dev
37+
4038
component: cos
4139
name: cosDemo
4240

4341
inputs:
44-
bucket: my-bucket
42+
bucket: bucket-demo
4543
region: ap-guangzhou
4644
```
4745
@@ -85,9 +83,9 @@ TENCENT_SECRET_KEY=123
8583

8684
> 如果没有腾讯云账号,请先 [注册新账号](https://cloud.tencent.com/register)。如果已有腾讯云账号,可以在 [API 密钥管理](https://console.cloud.tencent.com/cam/capi) 中获取 SecretId 和 SecretKey。
8785
88-
### 还支持哪些组件?
86+
### 使用文档
8987

90-
可以在 [Serverless Components](https://github.com/serverless/components) repo 中查询更多组件的信息。
88+
[使用文档](./docs/README.md)
9189

9290
## License
9391

__tests__/index.test.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const path = require('path')
2+
const axios = require('axios')
3+
const { generateId, getServerlessSdk } = require('./lib/utils')
4+
5+
const appId = process.env.TENCENT_APP_ID
6+
const credentials = {
7+
tencent: {
8+
SecretId: process.env.TENCENT_SECRET_ID,
9+
SecretKey: process.env.TENCENT_SECRET_KEY
10+
}
11+
}
12+
13+
const instanceYaml = {
14+
org: 'orgDemo',
15+
app: 'appDemo',
16+
component: 'cos@dev',
17+
name: `cos-integration-tests-${generateId()}`,
18+
stage: 'dev',
19+
inputs: {
20+
src: {
21+
src: path.join(__dirname, '..', 'example/src')
22+
},
23+
bucket: 'cos-integration-test',
24+
region: 'ap-guangzhou',
25+
acl: {
26+
permissions: 'public-read'
27+
}
28+
}
29+
}
30+
31+
const sdk = getServerlessSdk(instanceYaml.org, appId)
32+
33+
describe('COS', () => {
34+
it('deploy cos', async () => {
35+
const instance = await sdk.deploy(instanceYaml, credentials)
36+
37+
expect(instance).toBeDefined()
38+
expect(instance.instanceName).toEqual(instanceYaml.name)
39+
expect(instance.outputs.url).toBeDefined()
40+
expect(instance.outputs.region).toEqual(instanceYaml.inputs.region)
41+
// exist page
42+
const { data } = await axios.get(`${instance.outputs.url}/index.html`)
43+
expect(data).toContain('Serverless')
44+
})
45+
46+
it('deploy website', async () => {
47+
instanceYaml.inputs.website = true
48+
const instance = await sdk.deploy(instanceYaml, credentials)
49+
50+
expect(instance).toBeDefined()
51+
expect(instance.instanceName).toEqual(instanceYaml.name)
52+
expect(instance.outputs.website).toBeDefined()
53+
expect(instance.outputs.region).toEqual(instanceYaml.inputs.region)
54+
// exist page
55+
const { data } = await axios.get(instance.outputs.website)
56+
expect(data).toContain('Serverless')
57+
})
58+
59+
it('remove success', async () => {
60+
await sdk.remove(instanceYaml, credentials)
61+
const result = await sdk.getInstance(
62+
instanceYaml.org,
63+
instanceYaml.stage,
64+
instanceYaml.app,
65+
instanceYaml.name
66+
)
67+
68+
expect(result.instance.instanceStatus).toEqual('inactive')
69+
})
70+
})

__tests__/lib/utils.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const { ServerlessSDK } = require('@serverless/platform-client-china')
2+
3+
const generateId = () =>
4+
Math.random()
5+
.toString(36)
6+
.substring(6)
7+
8+
function sleep(ms) {
9+
return new Promise((resolve) => {
10+
setTimeout(() => {
11+
resolve(true)
12+
}, ms)
13+
})
14+
}
15+
16+
function getServerlessSdk(orgName, orgUid) {
17+
const sdk = new ServerlessSDK({
18+
context: {
19+
orgUid,
20+
orgName
21+
}
22+
})
23+
return sdk
24+
}
25+
26+
module.exports = { sleep, generateId, getServerlessSdk }

0 commit comments

Comments
 (0)