mirror of
https://github.com/werf/actions.git
synced 2026-03-25 08:53:07 +03:00
Merge pull request #44 from werf/feat_use_trdl_binaries
feat: download binaries directly from the trdl repository
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["@typescript-eslint"],
|
"plugins": ["@typescript-eslint", "github"],
|
||||||
"extends": ["plugin:github/es6"],
|
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended","plugin:github/recommended"],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 9,
|
"ecmaVersion": 9,
|
||||||
@@ -13,43 +13,10 @@
|
|||||||
"eslint-comments/no-use": "off",
|
"eslint-comments/no-use": "off",
|
||||||
"import/no-namespace": "off",
|
"import/no-namespace": "off",
|
||||||
"no-unused-vars": "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",
|
"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",
|
"semi": "off",
|
||||||
"@typescript-eslint/semi": ["error", "never"],
|
"i18n-text/no-en": "off",
|
||||||
"@typescript-eslint/type-annotation-spacing": "error",
|
"sort-imports": "off"
|
||||||
"@typescript-eslint/unbound-method": "error"
|
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
|
|||||||
43
.github/workflows/test.yaml
vendored
Normal file
43
.github/workflows/test.yaml
vendored
Normal 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
|
||||||
64318
build/index.js
64318
build/index.js
File diff suppressed because one or more lines are too long
64318
cleanup/index.js
64318
cleanup/index.js
File diff suppressed because one or more lines are too long
64316
converge/index.js
64316
converge/index.js
File diff suppressed because one or more lines are too long
64288
dismiss/index.js
64288
dismiss/index.js
File diff suppressed because one or more lines are too long
66202
install/index.js
66202
install/index.js
File diff suppressed because one or more lines are too long
7386
package-lock.json
generated
7386
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
24
package.json
24
package.json
@@ -1,29 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "werf-actions",
|
"name": "werf-actions",
|
||||||
"version": "1.1.0",
|
"version": "1.2.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "lib",
|
"main": "lib",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.6.0",
|
||||||
"@actions/github": "2.x",
|
"@actions/github": "^5.0.0",
|
||||||
"@actions/tool-cache": "1.x",
|
"@actions/tool-cache": "^1.7.1",
|
||||||
"dotenv": "8.2.x",
|
"dotenv": "10.0.x",
|
||||||
"ncc": "^0.3.6",
|
"semver": "^7.3.5",
|
||||||
"semver": "^7.3.2",
|
|
||||||
"string-argv": "^0.3.1",
|
"string-argv": "^0.3.1",
|
||||||
"superagent": "^3.8.3",
|
"superagent": "^6.1.0",
|
||||||
"tmp": "^0.2.1",
|
"tmp": "^0.2.1",
|
||||||
"typescript-string-operations": "^1.4.0",
|
"typescript-string-operations": "^1.4.0",
|
||||||
"ws": ">=7.4.6"
|
"ws": ">=8.2.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^12.19.1",
|
"@types/node": "^12.19.1",
|
||||||
"@types/semver": "^7.3.4",
|
"@types/semver": "^7.3.4",
|
||||||
"@types/superagent": "^4.1.10",
|
"@types/superagent": "^4.1.10",
|
||||||
"@types/tmp": "^0.2.0",
|
"@types/tmp": "^0.2.0",
|
||||||
"@typescript-eslint/parser": "^2.8.0",
|
"@typescript-eslint/eslint-plugin": "^5.1.0",
|
||||||
"eslint": "^5.x",
|
"@typescript-eslint/parser": "^5.1.0",
|
||||||
"eslint-plugin-github": "^2.0.0",
|
"eslint": "^7.32.0",
|
||||||
|
"eslint-plugin-github": "^4.3.2",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"node-fetch": ">=2.6.1",
|
"node-fetch": ">=2.6.1",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^1.19.1",
|
||||||
|
|||||||
64548
run/index.js
64548
run/index.js
File diff suppressed because one or more lines are too long
115
src/manager.ts
115
src/manager.ts
@@ -12,9 +12,9 @@ import * as dotenv from 'dotenv'
|
|||||||
import * as werf from './werf'
|
import * as werf from './werf'
|
||||||
import {ValidateWerfVersion} from './common'
|
import {ValidateWerfVersion} from './common'
|
||||||
|
|
||||||
const WERF_API_GET_CHANNEL_VERSION_URL_METHOD =
|
const WERF_TUF_SERVER_URL = 'https://tuf.werf.io'
|
||||||
'https://werf.io/api/getChannelVersionURL'
|
const CACHE_TOOL_NAME = 'werf'
|
||||||
const WERF_API_GET_VERSION_URL_METHOD = 'https://werf.io/api/getVersionURL'
|
const CACHE_TOOL_DIR = 'werf-tools'
|
||||||
|
|
||||||
export class Manager {
|
export class Manager {
|
||||||
private readonly channel: string
|
private readonly channel: string
|
||||||
@@ -32,24 +32,44 @@ export class Manager {
|
|||||||
ValidateWerfVersion(this.version)
|
ValidateWerfVersion(this.version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform.toString() === 'win32') {
|
const platform = process.platform.toString()
|
||||||
this.os = 'windows'
|
switch (platform) {
|
||||||
} else {
|
case 'linux':
|
||||||
this.os = process.platform.toString()
|
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> {
|
public async Install(): Promise<void> {
|
||||||
const actualBinaryUrl = await this._getActualBinaryUrl()
|
const actualBinaryUrl = await this._getActualBinaryUrl()
|
||||||
|
|
||||||
|
const binaryName = actualBinaryUrl.substring(
|
||||||
|
actualBinaryUrl.lastIndexOf('/') + 1
|
||||||
|
)
|
||||||
const cachedPath = cache.find(
|
const cachedPath = cache.find(
|
||||||
'werf',
|
CACHE_TOOL_NAME,
|
||||||
Manager._toolVersionCacheID(actualBinaryUrl)
|
Manager._toolVersionCacheID(actualBinaryUrl)
|
||||||
)
|
)
|
||||||
if (cachedPath) {
|
if (cachedPath) {
|
||||||
this.binaryPath = path.join(cachedPath, 'werf')
|
this.binaryPath = path.join(cachedPath, binaryName)
|
||||||
} else {
|
} else {
|
||||||
this.binaryPath = await this._downloadAndCache(actualBinaryUrl)
|
this.binaryPath = await this._downloadAndCache(actualBinaryUrl)
|
||||||
}
|
}
|
||||||
@@ -95,35 +115,29 @@ export class Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _getActualBinaryUrl(): Promise<string> {
|
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 {
|
try {
|
||||||
let url: string
|
const resp = await request
|
||||||
let query: {}
|
.get(url)
|
||||||
|
.buffer(true)
|
||||||
if (this.version !== '') {
|
.parse(request.parse['application/octet-stream'])
|
||||||
url = WERF_API_GET_VERSION_URL_METHOD
|
const version = resp.body.toString().trim()
|
||||||
query = {
|
return this._constructReleaseUrl(version)
|
||||||
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()
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.response && err.response.error) {
|
if (err.response && err.response.error) {
|
||||||
let errMessage = err.response.error.message
|
let errMessage = err.response.error.message
|
||||||
if (err.response.text) {
|
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)
|
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> {
|
private async _downloadAndCache(binaryUrl: string): Promise<string> {
|
||||||
|
const binaryName = binaryUrl.substring(binaryUrl.lastIndexOf('/') + 1)
|
||||||
const downloadedBinaryPath = await cache.downloadTool(binaryUrl)
|
const downloadedBinaryPath = await cache.downloadTool(binaryUrl)
|
||||||
const parsedDownloadedBinaryPath = path.parse(downloadedBinaryPath)
|
const cacheDownloadToolDir = path.dirname(downloadedBinaryPath)
|
||||||
const cacheDownloadToolDir = parsedDownloadedBinaryPath.dir
|
const tmpWerfVersionBinaryPath = path.join(
|
||||||
const tmpWerfVersionBinaryPath = path.join(cacheDownloadToolDir, 'werf.tmp')
|
|
||||||
const werfVersionDir = path.join(
|
|
||||||
cacheDownloadToolDir,
|
cacheDownloadToolDir,
|
||||||
parsedDownloadedBinaryPath.name
|
`${binaryName}.tmp`
|
||||||
)
|
|
||||||
const werfVersionBinaryPath = path.join(
|
|
||||||
werfVersionDir,
|
|
||||||
String.Format('werf{0}', parsedDownloadedBinaryPath.ext)
|
|
||||||
)
|
)
|
||||||
|
const werfVersionDir = path.join(cacheDownloadToolDir, CACHE_TOOL_DIR)
|
||||||
|
const werfVersionBinaryPath = path.join(werfVersionDir, binaryName)
|
||||||
|
|
||||||
// werf-x.x.x -> werf.tmp
|
// werf-x.x.x -> werf.tmp
|
||||||
// werf.tmp -> werf-x.x.x/werf
|
// werf.tmp -> werf-x.x.x/werf
|
||||||
@@ -159,7 +186,7 @@ export class Manager {
|
|||||||
|
|
||||||
await cache.cacheDir(
|
await cache.cacheDir(
|
||||||
werfVersionDir,
|
werfVersionDir,
|
||||||
'werf',
|
CACHE_TOOL_NAME,
|
||||||
Manager._toolVersionCacheID(binaryUrl)
|
Manager._toolVersionCacheID(binaryUrl)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user