Browse Source

Release script and CI fixes

tags/v1.4.4
DreamNet 1 year ago
parent
commit
fc09024298
4 changed files with 204 additions and 17 deletions
  1. 22
    13
      .github/workflows/ci.yml
  2. 6
    0
      src/.vscode/launch.json
  3. 5
    4
      src/package.json
  4. 171
    0
      src/scripts/release.js

+ 22
- 13
.github/workflows/ci.yml View File

@@ -30,8 +30,8 @@ jobs:
fail-fast: false
matrix:
os:
#- ubuntu-latest
#- windows-latest
- ubuntu-latest
- windows-latest
- macOS-latest
device:
- any
@@ -102,7 +102,7 @@ jobs:
- name: Use Yarn
run: npm install -g yarn

- name: Setup DreamPower
- name: Setup - DreamPower
working-directory: src/cli
run: |
${{ matrix.python }} -m pip install pyinstaller
@@ -117,26 +117,35 @@ jobs:
${{ matrix.python }} -m pip --no-cache-dir install ${{ matrix.torch-version }}
${{ matrix.python }} -m pip --no-cache-dir install torchvision==0.2.2.post3

- name: Setup DreamTime
- name: Setup - DreamTime
working-directory: src
run: |
yarn install

- name: Build DreamPower
- name: Build - DreamPower
working-directory: src/cli
run: |
${{ matrix.python }} -m PyInstaller main.py -y --onedir --name "dreampower" --distpath "../../dist" ${{ matrix.pyinstaller-args }}

- name: Build & Deploy DreamTime
- name: Lint - DreamTime
working-directory: src
run: |
yarn lint

- name: Build - DreamTime
working-directory: src
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
BUILD_DEVICE: ${{ matrix.device }}
run: |
yarn release --verbose --ci --github.assets="../dist/DreamTime-${{ matrix.os-short }}-${{ matrix.device }}.${{ matrix.os-ext }}"
yarn build

- name: Upload Internal Artifact
uses: actions/upload-artifact@v1
with:
name: ${{ matrix.os-short }}-${{ matrix.device }}
path: dist/DreamTime-${{ matrix.os-short }}-${{ matrix.device }}.${{ matrix.os-ext }}
- name: Deploy
working-directory: src/scripts
env:
GITHUB_TOKEN: ${{ secrets.TOKEN }}
GITHUB_SHA: ${{ github.sha }}
GITHUB_REF: ${{ github.ref }}
S3_ACCESS_KEY_ID: ${{ secrets.S3_ACCESS_KEY_ID }}
S3_SECRET_ACCESS_KEY: ${{ secrets.S3_SECRET_ACCESS_KEY }}
run: |
node release.js

+ 6
- 0
src/.vscode/launch.json View File

@@ -4,6 +4,12 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Active File",
"program": "${file}"
},
{
"type": "node",
"request": "launch",

+ 5
- 4
src/package.json View File

@@ -105,7 +105,7 @@
},
"nsis": {
"oneClick": false,
"artifactName": "${productName}-windows-${env.BUILD_DEVICE}.${ext}",
"artifactName": "${productName}-v${version}-windows-${env.BUILD_DEVICE}.${ext}",
"menuCategory": true,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
@@ -114,14 +114,14 @@
"license": "license.txt"
},
"deb": {
"artifactName": "${productName}-ubuntu-${env.BUILD_DEVICE}.${ext}",
"artifactName": "${productName}-v${version}-ubuntu-${env.BUILD_DEVICE}.${ext}",
"fpm": [
"--deb-no-default-config-files"
]
},
"dmg": {
"title": "${productName} v${version}",
"artifactName": "${productName}-macos-${env.BUILD_DEVICE}.${ext}"
"artifactName": "${productName}-v${version}-macos-${env.BUILD_DEVICE}.${ext}"
}
},
"scripts": {
@@ -182,6 +182,8 @@
"@nuxtjs/eslint-config": "^0.0.1",
"@nuxtjs/eslint-module": "^0.0.1",
"@nuxtjs/tailwindcss": "^1.1.2",
"@octokit/rest": "^16.28.7",
"aws-sdk": "^2.515.0",
"babel-eslint": "^10.0.1",
"cross-env": "^5.2.0",
"electron": "^5.0.6",
@@ -206,7 +208,6 @@
"nodemon": "^1.18.9",
"nuxtjs-electron": "^0.1.10",
"prettier": "^1.16.4",
"release-it": "^12.3.5",
"rollbar-sourcemap-webpack-plugin": "^2.5.1",
"sass-loader": "^7.1.0",
"tailwindcss": "^1.0.0"

+ 171
- 0
src/scripts/release.js View File

@@ -0,0 +1,171 @@
/*
* DreamTime | (C) 2019 by Ivan Bravo Bravo <ivan@dreamnet.tech>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License 3.0 as published by
* the Free Software Foundation.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

const Octokit = require('@octokit/rest')
const AWS = require('aws-sdk')
const mime = require('mime-types')
const _ = require('lodash')
const Deferred = require('deferred')
const fs = require('fs')
const path = require('path')
const pkg = require('../package.json')

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN
})

const S3Client = new AWS.S3({
accessKeyId: process.env.S3_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY,
endpoint: 'https://sfo2.digitaloceanspaces.com'
})

function getOS() {
if (process.platform === 'win32') {
return 'windows'
}
if (process.platform === 'darwin') {
return 'macos'
}

return 'ubuntu'
}

function getExt() {
if (process.platform === 'win32') {
return 'exe'
}
if (process.platform === 'darwin') {
return 'dmg'
}

return 'deb'
}

const isTagRelease = _.startsWith(process.env.GITHUB_REF, 'refs/tags')

const tagName = isTagRelease
? process.env.GITHUB_REF.split('/')[2]
: _.truncate(process.env.GITHUB_SHA, { length: 7, omission: '' })

const version = `v${pkg.version}`
const fileName = `DreamTime-${version}-${getOS()}`

const anyFileName = `${fileName}-any.${getExt()}`
const cpuFileName = `${fileName}-cpuonly.${getExt()}`

const anyFilePath = path.resolve(__dirname, '../../dist', anyFileName)
const cpuFilePath = path.resolve(__dirname, '../../dist', cpuFileName)

async function getGithubReleaseUrl() {
let response

try {
response = await octokit.repos.getReleaseByTag({
owner: 'private-dreamnet',
repo: 'dreamtime',
tag: tagName
})
} catch (err) {
if (err.status !== 404) {
throw err
}

try {
response = await octokit.repos.createRelease({
owner: 'private-dreamnet',
repo: 'dreamtime',
tag_name: tagName,
name: version,
prerelease: true,
draft: true
})
} catch (err) {
console.log(err)
throw err
}
}

return response.data.upload_url
}

function uploadToS3(filePath, fileName) {
const deferred = new Deferred()

S3Client.upload(
{
Bucket: 'dreamnet-cdn',
Key: `releases/dreamtime/${tagName}/${fileName}`,
Body: fs.createReadStream(filePath)
},
(err, response) => {
if (err) {
deferred.reject(err)
return
}

deferred.resolve(response)
}
)

return deferred.promise
}

async function uploadToGithub(filePath, fileName) {
const stats = fs.statSync(filePath)
const url = await getGithubReleaseUrl()

const response = await octokit.repos.uploadReleaseAsset({
url,
headers: {
'content-length': stats.size,
'content-type': mime.lookup(filePath)
},
name: fileName,
file: fs.createReadStream(filePath)
})

return response
}

async function upload(filePath, fileName) {
let response

if (isTagRelease) {
console.log(`Uploading ${fileName} to Github...`)
response = await uploadToGithub(filePath, fileName)
console.log('Github say: ', response)
}

console.log(`Uploading ${fileName} to S3...`)
response = await uploadToS3(filePath, fileName)
console.log('S3 say:', response)
}

if (fs.existsSync(anyFilePath)) {
console.log(`Uploading ${anyFileName}`)
upload(anyFilePath, anyFileName)

if (pkg.version === '1.2.0') {
const legacyAnyFileName = `${fileName}-x64.${getExt()}`
const legacy2AnyFileName = `DreamTime-vv${
pkg.version
}-${getOS()}-x64.${getExt()}`

upload(anyFilePath, legacyAnyFileName)
upload(anyFilePath, legacy2AnyFileName)
}
} else if (fs.existsSync(cpuFilePath)) {
console.log(`Uploading ${cpuFileName}`)
upload(cpuFilePath, cpuFileName)
} else {
console.log('No release found!')
}

Loading…
Cancel
Save