Merge pull request #44 from werf/feat_use_trdl_binaries

feat: download binaries directly from the trdl repository
This commit is contained in:
Alexey Igrychev
2021-10-28 12:24:38 +01:00
committed by GitHub
11 changed files with 156425 additions and 239174 deletions
+4 -37
View File
@@ -1,6 +1,6 @@
{
"plugins": ["@typescript-eslint"],
"extends": ["plugin:github/es6"],
"plugins": ["@typescript-eslint", "github"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended","plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
@@ -13,43 +13,10 @@
"eslint-comments/no-use": "off",
"import/no-namespace": "off",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-ignore": "error",
"camelcase": "off",
"@typescript-eslint/camelcase": "error",
"@typescript-eslint/class-name-casing": "error",
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",
"@typescript-eslint/no-namespace": "error",
"@typescript-eslint/no-non-null-assertion": "warn",
"@typescript-eslint/no-object-literal-type-assertion": "error",
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
"@typescript-eslint/semi": ["error", "never"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/unbound-method": "error"
"i18n-text/no-en": "off",
"sort-imports": "off"
},
"env": {
"node": true,
+43
View File
@@ -0,0 +1,43 @@
name: Test
on:
push:
jobs:
channel:
name: By channel
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install
uses: ./install
- run: werf version
version:
name: By version
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Install
uses: ./install
with:
version: v1.2.35
- run: werf version
+25101 -39217
View File
File diff suppressed because one or more lines are too long
+25101 -39217
View File
File diff suppressed because one or more lines are too long
+25100 -39216
View File
File diff suppressed because one or more lines are too long
+25086 -39202
View File
File diff suppressed because one or more lines are too long
+26043 -40159
View File
File diff suppressed because one or more lines are too long
+4647 -2739
View File
File diff suppressed because it is too large Load Diff
+12 -12
View File
@@ -1,29 +1,29 @@
{
"name": "werf-actions",
"version": "1.1.0",
"version": "1.2.1",
"description": "",
"main": "lib",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "2.x",
"@actions/tool-cache": "1.x",
"dotenv": "8.2.x",
"ncc": "^0.3.6",
"semver": "^7.3.2",
"@actions/core": "^1.6.0",
"@actions/github": "^5.0.0",
"@actions/tool-cache": "^1.7.1",
"dotenv": "10.0.x",
"semver": "^7.3.5",
"string-argv": "^0.3.1",
"superagent": "^3.8.3",
"superagent": "^6.1.0",
"tmp": "^0.2.1",
"typescript-string-operations": "^1.4.0",
"ws": ">=7.4.6"
"ws": ">=8.2.3"
},
"devDependencies": {
"@types/node": "^12.19.1",
"@types/semver": "^7.3.4",
"@types/superagent": "^4.1.10",
"@types/tmp": "^0.2.0",
"@typescript-eslint/parser": "^2.8.0",
"eslint": "^5.x",
"eslint-plugin-github": "^2.0.0",
"@typescript-eslint/eslint-plugin": "^5.1.0",
"@typescript-eslint/parser": "^5.1.0",
"eslint": "^7.32.0",
"eslint-plugin-github": "^4.3.2",
"js-yaml": "^3.13.1",
"node-fetch": ">=2.6.1",
"prettier": "^1.19.1",
+25217 -39331
View File
File diff suppressed because one or more lines are too long
+71 -44
View File
@@ -12,9 +12,9 @@ import * as dotenv from 'dotenv'
import * as werf from './werf'
import {ValidateWerfVersion} from './common'
const WERF_API_GET_CHANNEL_VERSION_URL_METHOD =
'https://werf.io/api/getChannelVersionURL'
const WERF_API_GET_VERSION_URL_METHOD = 'https://werf.io/api/getVersionURL'
const WERF_TUF_SERVER_URL = 'https://tuf.werf.io'
const CACHE_TOOL_NAME = 'werf'
const CACHE_TOOL_DIR = 'werf-tools'
export class Manager {
private readonly channel: string
@@ -32,24 +32,44 @@ export class Manager {
ValidateWerfVersion(this.version)
}
if (process.platform.toString() === 'win32') {
this.os = 'windows'
} else {
this.os = process.platform.toString()
const platform = process.platform.toString()
switch (platform) {
case 'linux':
case 'darwin':
this.os = platform
break
case 'win32':
this.os = 'windows'
break
default:
throw new Error(String.Format(`The platform ${platform} not supported`))
}
this.arch = process.arch
const arch = process.arch
switch (arch) {
case 'x64':
this.arch = 'amd64'
break
case 'arm64':
this.arch = 'arm64'
break
default:
throw new Error(String.Format(`The architecture ${arch} not supported`))
}
}
public async Install(): Promise<void> {
const actualBinaryUrl = await this._getActualBinaryUrl()
const binaryName = actualBinaryUrl.substring(
actualBinaryUrl.lastIndexOf('/') + 1
)
const cachedPath = cache.find(
'werf',
CACHE_TOOL_NAME,
Manager._toolVersionCacheID(actualBinaryUrl)
)
if (cachedPath) {
this.binaryPath = path.join(cachedPath, 'werf')
this.binaryPath = path.join(cachedPath, binaryName)
} else {
this.binaryPath = await this._downloadAndCache(actualBinaryUrl)
}
@@ -95,35 +115,29 @@ export class Manager {
}
private async _getActualBinaryUrl(): Promise<string> {
if (this.version !== '') {
const version = this.version.slice('v'.length)
return this._constructReleaseUrl(version)
}
const url = `${WERF_TUF_SERVER_URL}/targets/channels/${werf.MAJOR_MINOR_GROUP}/${this.channel}`
try {
let url: string
let query: {}
if (this.version !== '') {
url = WERF_API_GET_VERSION_URL_METHOD
query = {
version: this.version,
os: this.os,
arch: this.arch
}
} else {
url = WERF_API_GET_CHANNEL_VERSION_URL_METHOD
query = {
group: werf.MAJOR_MINOR_GROUP,
channel: this.channel,
os: this.os,
arch: this.arch
}
}
const resp = await request.get(url).query(query)
return resp.body.data.toString()
const resp = await request
.get(url)
.buffer(true)
.parse(request.parse['application/octet-stream'])
const version = resp.body.toString().trim()
return this._constructReleaseUrl(version)
} catch (err) {
if (err.response && err.response.error) {
let errMessage = err.response.error.message
if (err.response.text) {
errMessage = String.Format('{0}\n{1}', errMessage, err.response.text)
errMessage = String.Format(
'{0}: {1}\n{2}',
url,
errMessage,
err.response.text
)
}
throw Error(errMessage)
@@ -133,19 +147,32 @@ export class Manager {
}
}
private _constructReleaseUrl(version: string): string {
let ext = ''
if (this.os === 'windows') {
ext = '.exe'
}
return String.Format(
'{0}/targets/releases/{1}/{2}-{3}/bin/werf{4}',
WERF_TUF_SERVER_URL,
version,
this.os,
this.arch,
ext
)
}
private async _downloadAndCache(binaryUrl: string): Promise<string> {
const binaryName = binaryUrl.substring(binaryUrl.lastIndexOf('/') + 1)
const downloadedBinaryPath = await cache.downloadTool(binaryUrl)
const parsedDownloadedBinaryPath = path.parse(downloadedBinaryPath)
const cacheDownloadToolDir = parsedDownloadedBinaryPath.dir
const tmpWerfVersionBinaryPath = path.join(cacheDownloadToolDir, 'werf.tmp')
const werfVersionDir = path.join(
const cacheDownloadToolDir = path.dirname(downloadedBinaryPath)
const tmpWerfVersionBinaryPath = path.join(
cacheDownloadToolDir,
parsedDownloadedBinaryPath.name
)
const werfVersionBinaryPath = path.join(
werfVersionDir,
String.Format('werf{0}', parsedDownloadedBinaryPath.ext)
`${binaryName}.tmp`
)
const werfVersionDir = path.join(cacheDownloadToolDir, CACHE_TOOL_DIR)
const werfVersionBinaryPath = path.join(werfVersionDir, binaryName)
// werf-x.x.x -> werf.tmp
// werf.tmp -> werf-x.x.x/werf
@@ -159,7 +186,7 @@ export class Manager {
await cache.cacheDir(
werfVersionDir,
'werf',
CACHE_TOOL_NAME,
Manager._toolVersionCacheID(binaryUrl)
)