Travis ui tests (#57)
* Prepare travis is tests * Fix ffmpeg travis source * Trying xenial * Move shell scripts * Upload video assets * Upload video assets * Change text input method * Add ui test docker support * Fix travis docker build * Fix asset uploader * Fix dockerfile * Update dockerfile * Change writeText behavior * Fix type error * Fix exit codes * Fix types * fix upload * Fix writeText * Fix argument name * Add test scenarios * Enable vnc and change mqtt host
This commit is contained in:
86
scripts/uploadVideoAsset.ts
Executable file
86
scripts/uploadVideoAsset.ts
Executable file
@@ -0,0 +1,86 @@
|
||||
#!node_modules/.bin/ts-node
|
||||
import axios from 'axios'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import * as mime from 'mime'
|
||||
|
||||
const githubToken = process.env.GH_TOKEN
|
||||
|
||||
async function tagUrl(tag: string): Promise<string | undefined> {
|
||||
const response = await axios.get(`https://api.github.com/repos/thomasnordquist/mqtt-explorer/releases?access_token=${githubToken}`)
|
||||
const tagRelease = response.data.find((release: any) => release.tag_name === tag)
|
||||
|
||||
return tagRelease ? cleanUploadUrl(tagRelease.upload_url) : undefined
|
||||
}
|
||||
|
||||
async function createDraft(tag: string) {
|
||||
console.log('create draft')
|
||||
|
||||
const response = await axios({
|
||||
method: 'post',
|
||||
url: `https://api.github.com/repos/thomasnordquist/mqtt-explorer/releases?access_token=${githubToken}`,
|
||||
data: {
|
||||
tag_name: tag,
|
||||
name: tag.slice(1),
|
||||
draft: true,
|
||||
},
|
||||
})
|
||||
|
||||
return cleanUploadUrl(response.data.upload_url)
|
||||
}
|
||||
|
||||
function cleanUploadUrl(url: string) {
|
||||
return url.match(/(.*){/)![1]
|
||||
}
|
||||
|
||||
async function uploadAsset() {
|
||||
const tag: string | undefined = process.env.GIT_TAG
|
||||
const files = process.argv.slice(2)
|
||||
|
||||
if (!tag || files.length === 0) {
|
||||
console.log('Nothing to do')
|
||||
return
|
||||
}
|
||||
|
||||
let uploadUrl: string | undefined
|
||||
try {
|
||||
uploadUrl = await tagUrl(tag)
|
||||
if (!uploadUrl) {
|
||||
console.log('tag does not exist')
|
||||
try {
|
||||
uploadUrl = await createDraft(tag)
|
||||
} catch (error) {
|
||||
console.error('failed to create draft', error.stack)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('failed to find tag release', error.stack)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (uploadUrl) {
|
||||
console.log(uploadUrl)
|
||||
for (const file of files) {
|
||||
console.log('uploading file', file)
|
||||
await uploadFile(uploadUrl, file)
|
||||
console.log('upload completed')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function uploadFile(uploadUrl: string, file: string) {
|
||||
const data = fs.readFileSync(file)
|
||||
const mimeType = mime.getType(path.extname(file))
|
||||
|
||||
return await axios({
|
||||
data,
|
||||
method: 'post',
|
||||
url: `${uploadUrl}?name=${path.basename(file)}&access_token=${githubToken}`,
|
||||
headers: {
|
||||
'Content-Type': mimeType,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
uploadAsset()
|
||||
Reference in New Issue
Block a user