mirror of
https://github.com/werf/actions.git
synced 2026-02-06 03:16:25 +03:00
Compare commits
15 Commits
dependabot
...
v1.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7aaf2cce6b | ||
|
|
95ff181e6a | ||
|
|
c5e105e95e | ||
|
|
8047e055e2 | ||
|
|
7425cd9c3c | ||
|
|
4033ce9a92 | ||
|
|
6acc213146 | ||
|
|
f507c4f344 | ||
|
|
93f4252af6 | ||
|
|
bd74d436c7 | ||
|
|
4e62aa309e | ||
|
|
697f06e4a1 | ||
|
|
47e7c4a185 | ||
|
|
7c8622c3d6 | ||
|
|
156c73b693 |
@@ -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.1.23+fix50
|
||||||
|
|
||||||
|
- run: werf version
|
||||||
68
README.md
68
README.md
@@ -1,30 +1,42 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://github.com/werf/werf/raw/master/docs/images/werf-logo.svg?sanitize=true" style="max-height:100%;" height="175">
|
<img src="https://werf.io/assets/images/werf-logo.svg?sanitize=true" style="max-height:100%;" height="175">
|
||||||
</p>
|
</p>
|
||||||
___
|
___
|
||||||
|
|
||||||
This action set allows you to organize CI/CD with GitHub Actions and [werf](https://github.com/werf/werf). The set consists of several independent and complex actions:
|
This action set allows you to organize CI/CD with GitHub Actions and [werf](https://github.com/werf/werf). The set consists of several independent and complex actions:
|
||||||
|
|
||||||
- [werf/actions/converge](https://github.com/werf/actions/tree/master/converge)
|
- [werf/actions/converge](https://github.com/werf/actions/tree/v1.1/converge)
|
||||||
- [werf/actions/build-and-publish](https://github.com/werf/actions/tree/master/build-and-publish)
|
- [werf/actions/build-and-publish](https://github.com/werf/actions/tree/v1.1/build-and-publish)
|
||||||
- [werf/actions/build](https://github.com/werf/actions/tree/master/build)
|
- [werf/actions/build](https://github.com/werf/actions/tree/v1.1/build)
|
||||||
- [werf/actions/publish](https://github.com/werf/actions/tree/master/build)
|
- [werf/actions/publish](https://github.com/werf/actions/tree/v1.1/build)
|
||||||
- [werf/actions/deploy](https://github.com/werf/actions/tree/master/deploy)
|
- [werf/actions/deploy](https://github.com/werf/actions/tree/v1.1/deploy)
|
||||||
- [werf/actions/dismiss](https://github.com/werf/actions/tree/master/dismiss)
|
- [werf/actions/dismiss](https://github.com/werf/actions/tree/v1.1/dismiss)
|
||||||
- [werf/actions/run](https://github.com/werf/actions/tree/master/run)
|
- [werf/actions/run](https://github.com/werf/actions/tree/v1.1/run)
|
||||||
- [werf/actions/cleanup](https://github.com/werf/actions/tree/master/cleanup)
|
- [werf/actions/cleanup](https://github.com/werf/actions/tree/v1.1/cleanup)
|
||||||
|
|
||||||
Each action combines all the necessary steps in itself and logic may be divided into environment setup and launching the corresponding command.
|
Each action combines all the necessary steps in itself and logic may be divided into environment setup and launching the corresponding command.
|
||||||
|
|
||||||
**Ready-to-use GitHub Actions Workflows** for different CI/CD workflows are available [here](https://werf.io/documentation/advanced/ci_cd/github_actions.html#complete-set-of-configurations-for-ready-made-workflows).
|
**Ready-to-use GitHub Actions Workflows** for different CI/CD workflows are available [here](https://werf.io/v1.1-alpha/documentation/guides/github_ci_cd_integration.html#complete-set-of-configurations-for-ready-made-workflows).
|
||||||
|
|
||||||
> Also, there is another action — [werf/actions/install](https://github.com/werf/actions/tree/master/install). With this action a user can just install werf and use binary within job steps for own purposes
|
> Also, there is another action — [werf/actions/install](https://github.com/werf/actions/tree/v1.1/install). With this action a user can just install werf and use binary within job steps for own purposes
|
||||||
|
|
||||||
|
## Versioning
|
||||||
|
|
||||||
|
When using actions, select the version corresponding to the `MAJOR.MINOR` version of werf:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
# run converge with actual werf version for 1.1 alpha channel
|
||||||
|
- uses: werf/actions/converge@v1.1
|
||||||
|
|
||||||
|
# run converge with actual werf version for 1.2 alpha channel
|
||||||
|
- uses: werf/actions/converge@v1.2
|
||||||
|
```
|
||||||
|
|
||||||
## Environment setup in details
|
## Environment setup in details
|
||||||
|
|
||||||
### werf binary setup
|
### werf binary setup
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for 1.1 alpha channel (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
@@ -77,6 +89,21 @@ Any werf option can be defined with environment variables:
|
|||||||
WERF_TAG_CUSTOM_TAG2: tag2
|
WERF_TAG_CUSTOM_TAG2: tag2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Working with container registry
|
||||||
|
|
||||||
|
Due to the fact that the new GitHub container registry (`ghcr.io`) does not currently support removal, all actions default to the old one (`docker.pkg.github.com`).
|
||||||
|
|
||||||
|
If necessary, the user can define an arbitrary container registry using the `WERF_REPO` and `WERF_REPO_IMPLEMENTATION` environment variables.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: werf/actions/converge@v1.1
|
||||||
|
env:
|
||||||
|
WERF_REPO: "gcr.io/company/app"
|
||||||
|
WERF_REPO_IMPLEMENTATION: "gcr"
|
||||||
|
```
|
||||||
|
|
||||||
|
To learn how to work with the different container registries, see the corresponding [article in the werf documentation](https://werf.io/v1.1-alpha/documentation/reference/working_with_docker_registries.html).
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
### converge
|
### converge
|
||||||
@@ -229,6 +256,23 @@ werf:
|
|||||||
WERF_ENV: production
|
WERF_ENV: production
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# FAQ
|
||||||
|
|
||||||
|
## werf always rebuilds images on new commit
|
||||||
|
|
||||||
|
Make sure to use `fetch-depth: 0` setting in the checkout action, like follows:
|
||||||
|
|
||||||
|
```
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
```
|
||||||
|
|
||||||
|
By default fetch-depth set to `1` which disables git history when checking out code. werf cache selection algorithm uses git history to determine whether some image bound to some commit could be used as a cache when building current commit (current commit should be descendant to the cache commit).
|
||||||
|
|
||||||
|
Setting `fetch-depth` to `0` enables full fetch of git history and it is a **recommended** approach. It is also possible to limit fetch history with some decent number of commits, which would enable images caching limited to that number of commits, but this would have a negative impact on cache reproducibility.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
Apache License 2.0, see [LICENSE](LICENSE)
|
Apache License 2.0, see [LICENSE](LICENSE)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@ The action combines all the necessary steps in itself and logic may be divided i
|
|||||||
|
|
||||||
### werf binary setup
|
### werf binary setup
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
|
|||||||
63765
build/index.js
63765
build/index.js
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@ The action combines all the necessary steps in itself and logic may be divided i
|
|||||||
|
|
||||||
### werf binary setup
|
### werf binary setup
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
|
|||||||
63787
cleanup/index.js
63787
cleanup/index.js
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@ The action combines all the necessary steps in itself and logic may be divided i
|
|||||||
|
|
||||||
### werf binary setup
|
### werf binary setup
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
|
|||||||
63789
converge/index.js
63789
converge/index.js
File diff suppressed because one or more lines are too long
63783
deploy/index.js
63783
deploy/index.js
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@ The action combines all the necessary steps in itself and logic may be divided i
|
|||||||
|
|
||||||
### werf binary setup
|
### werf binary setup
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
|
|||||||
63757
dismiss/index.js
63757
dismiss/index.js
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@
|
|||||||
</p>
|
</p>
|
||||||
___
|
___
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
|
|||||||
65453
install/index.js
65453
install/index.js
File diff suppressed because one or more lines are too long
3900
package-lock.json
generated
3900
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.1.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": ">=3.3.1"
|
"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",
|
||||||
|
|||||||
63789
publish/index.js
63789
publish/index.js
File diff suppressed because one or more lines are too long
@@ -9,7 +9,7 @@ The action combines all the necessary steps in itself and logic may be divided i
|
|||||||
|
|
||||||
### werf binary setup
|
### werf binary setup
|
||||||
|
|
||||||
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://github.com/werf/werf#backward-compatibility-promise)).
|
By default, all actions setup actual werf version for [1.1 alpha channel](https://werf.io/releases.html) (more details about channels, werf release cycle and compatibility promise [here](https://werf.io/installation.html#all-changes-in-werf-go-through-all-stability-channels)).
|
||||||
Using the `channel` input the user can switch the release channel.
|
Using the `channel` input the user can switch the release channel.
|
||||||
|
|
||||||
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
> This is recommended approach to be up-to-date and to use actual werf version without changing configurations
|
||||||
|
|||||||
63907
run/index.js
63907
run/index.js
File diff suppressed because one or more lines are too long
121
src/manager.ts
121
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()
|
||||||
|
switch (platform) {
|
||||||
|
case 'linux':
|
||||||
|
case 'darwin':
|
||||||
|
this.os = platform
|
||||||
|
break
|
||||||
|
case 'win32':
|
||||||
this.os = 'windows'
|
this.os = 'windows'
|
||||||
} else {
|
break
|
||||||
this.os = process.platform.toString()
|
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)
|
||||||
}
|
}
|
||||||
@@ -62,16 +82,8 @@ export class Manager {
|
|||||||
const tmpFile = tmp.fileSync()
|
const tmpFile = tmp.fileSync()
|
||||||
const tmpFilePath = tmpFile.name
|
const tmpFilePath = tmpFile.name
|
||||||
await this.Exec(['ci-env', 'github', '--as-env-file', '-o', tmpFilePath])
|
await this.Exec(['ci-env', 'github', '--as-env-file', '-o', tmpFilePath])
|
||||||
dotenv.config({path: tmpFilePath})
|
const res = dotenv.config({path: tmpFilePath})
|
||||||
|
console.log(res.parsed)
|
||||||
fs.readFile(tmpFilePath, null, function(err, contents) {
|
|
||||||
if (err) {
|
|
||||||
console.error(err)
|
|
||||||
} else {
|
|
||||||
console.log(contents.toString())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
tmpFile.removeCallback()
|
tmpFile.removeCallback()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,35 +115,29 @@ export class Manager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _getActualBinaryUrl(): Promise<string> {
|
private async _getActualBinaryUrl(): Promise<string> {
|
||||||
try {
|
|
||||||
let url: string
|
|
||||||
let query: {}
|
|
||||||
|
|
||||||
if (this.version !== '') {
|
if (this.version !== '') {
|
||||||
url = WERF_API_GET_VERSION_URL_METHOD
|
const version = this.version.slice('v'.length)
|
||||||
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)
|
const url = `${WERF_TUF_SERVER_URL}/targets/channels/${werf.MAJOR_MINOR_GROUP}/${this.channel}`
|
||||||
|
try {
|
||||||
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) {
|
} 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)
|
||||||
@@ -141,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
|
||||||
@@ -167,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