Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
cc087242
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cc087242
编写于
11月 05, 2019
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update sync-mooncake.ts
上级
098c2486
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
55 deletion
+14
-55
build/azure-pipelines/common/sync-mooncake.ts
build/azure-pipelines/common/sync-mooncake.ts
+14
-55
未找到文件。
build/azure-pipelines/common/sync-mooncake.ts
浏览文件 @
cc087242
...
...
@@ -8,7 +8,7 @@
import
*
as
url
from
'
url
'
;
import
*
as
azure
from
'
azure-storage
'
;
import
*
as
mime
from
'
mime
'
;
import
{
DocumentClient
,
RetrievedDocument
}
from
'
documentdb
'
;
import
{
CosmosClient
}
from
'
@azure/cosmos
'
;
function
log
(...
args
:
any
[])
{
console
.
log
(...[
`[
${
new
Date
().
toISOString
()}
]`
,
...
args
]);
...
...
@@ -23,7 +23,7 @@ if (process.argv.length < 3) {
process
.
exit
(
-
1
);
}
interface
Build
extends
RetrievedDocument
{
interface
Build
{
assets
:
Asset
[];
}
...
...
@@ -38,62 +38,20 @@ interface Asset {
supportsFastUpdate
?:
boolean
;
}
function
updateBuild
(
commit
:
string
,
quality
:
string
,
platform
:
string
,
type
:
string
,
asset
:
Asset
):
Promise
<
void
>
{
const
client
=
new
DocumentClient
(
process
.
env
[
'
AZURE_DOCUMENTDB_ENDPOINT
'
]
!
,
{
masterKey
:
process
.
env
[
'
AZURE_DOCUMENTDB_MASTERKEY
'
]
});
const
collection
=
'
dbs/builds/colls/
'
+
quality
;
const
updateQuery
=
{
query
:
'
SELECT TOP 1 * FROM c WHERE c.id = @id
'
,
parameters
:
[{
name
:
'
@id
'
,
value
:
commit
}]
};
let
updateTries
=
0
;
function
_update
():
Promise
<
void
>
{
updateTries
++
;
return
new
Promise
<
void
>
((
c
,
e
)
=>
{
client
.
queryDocuments
(
collection
,
updateQuery
).
toArray
((
err
,
results
)
=>
{
if
(
err
)
{
return
e
(
err
);
}
if
(
results
.
length
!==
1
)
{
return
e
(
new
Error
(
'
No documents
'
));
}
const
release
=
results
[
0
];
async
function
sync
(
commit
:
string
,
quality
:
string
):
Promise
<
void
>
{
log
(
`Synchronizing Mooncake assets for
${
quality
}
,
${
commit
}
...`
);
release
.
assets
=
[
...
release
.
assets
.
filter
((
a
:
any
)
=>
!
(
a
.
platform
===
platform
&&
a
.
type
===
type
)),
asset
];
const
client
=
new
CosmosClient
({
endpoint
:
process
.
env
[
'
AZURE_DOCUMENTDB_ENDPOINT
'
]
!
,
key
:
process
.
env
[
'
AZURE_DOCUMENTDB_MASTERKEY
'
]
});
const
container
=
client
.
database
(
'
builds
'
).
container
(
quality
);
client
.
replaceDocument
(
release
.
_self
,
release
,
err
=>
{
if
(
err
&&
err
.
code
===
409
&&
updateTries
<
5
)
{
return
c
(
_update
());
}
if
(
err
)
{
return
e
(
err
);
}
const
query
=
`SELECT TOP 1 * FROM c WHERE c.id = "
${
commit
}
"`
;
const
res
=
await
container
.
items
.
query
<
Build
>
(
query
,
{}).
fetchAll
();
log
(
'
Build successfully updated.
'
);
c
();
});
});
});
if
(
res
.
resources
.
length
!==
1
)
{
throw
new
Error
(
`No builds found for
${
commit
}
`
);
}
return
_update
();
}
async
function
sync
(
commit
:
string
,
quality
:
string
):
Promise
<
void
>
{
log
(
`Synchronizing Mooncake assets for
${
quality
}
,
${
commit
}
...`
);
const
cosmosdb
=
new
DocumentClient
(
process
.
env
[
'
AZURE_DOCUMENTDB_ENDPOINT
'
]
!
,
{
masterKey
:
process
.
env
[
'
AZURE_DOCUMENTDB_MASTERKEY
'
]
});
const
collection
=
`dbs/builds/colls/
${
quality
}
`
;
const
query
=
{
query
:
'
SELECT TOP 1 * FROM c WHERE c.id = @id
'
,
parameters
:
[{
name
:
'
@id
'
,
value
:
commit
}]
};
const
build
=
await
new
Promise
<
Build
>
((
c
,
e
)
=>
{
cosmosdb
.
queryDocuments
(
collection
,
query
).
toArray
((
err
,
results
)
=>
{
if
(
err
)
{
return
e
(
err
);
}
if
(
results
.
length
!==
1
)
{
return
e
(
new
Error
(
'
No documents
'
));
}
c
(
results
[
0
]
as
Build
);
});
});
const
build
=
res
.
resources
[
0
];
log
(
`Found build for
${
commit
}
, with
${
build
.
assets
.
length
}
assets`
);
...
...
@@ -140,8 +98,9 @@ async function sync(commit: string, quality: string): Promise<void> {
await
new
Promise
((
c
,
e
)
=>
readStream
.
pipe
(
writeStream
).
on
(
'
finish
'
,
c
).
on
(
'
error
'
,
e
));
log
(
` Updating build in DB...`
);
asset
.
mooncakeUrl
=
`
${
process
.
env
[
'
MOONCAKE_CDN_URL
'
]}${
blobPath
}
`
;
await
updateBuild
(
commit
,
quality
,
asset
.
platform
,
asset
.
type
,
asset
);
const
mooncakeUrl
=
`
${
process
.
env
[
'
MOONCAKE_CDN_URL
'
]}${
blobPath
}
`
;
await
container
.
scripts
.
storedProcedure
(
'
setAssetMooncakeUrl
'
)
.
execute
(
''
,
[
commit
,
asset
.
platform
,
asset
.
type
,
mooncakeUrl
]);
log
(
` Done ✔️`
);
}
catch
(
err
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录