mirror of
https://github.com/imranismail/setup-kustomize.git
synced 2026-06-13 01:14:19 +00:00
Compare commits
28 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60866b9f80 | ||
|
|
91ce0fb611 | ||
|
|
13cc3947ac | ||
|
|
548304dcdd | ||
|
|
366ebb426b | ||
|
|
0b4205889c | ||
|
|
509da12cc4 | ||
|
|
b7c602d150 | ||
|
|
d6406c9ed5 | ||
|
|
965f29eaf7 | ||
|
|
41e7f9975d | ||
|
|
45c217953c | ||
|
|
ae749a83d7 | ||
|
|
0c2f32dde2 | ||
|
|
59f3d52ca7 | ||
|
|
ff25099d8b | ||
|
|
359e84cbc9 | ||
|
|
430fa071e8 | ||
|
|
b0afa08459 | ||
|
|
9503343f5a | ||
|
|
51957eba2f | ||
|
|
399ab9d4d6 | ||
|
|
f54a2cb09e | ||
|
|
2a4b82aea8 | ||
|
|
fff6152ccc | ||
|
|
dd60f3d86e | ||
|
|
3f35d588be | ||
|
|
823fe14c9e |
10
.eslintrc
10
.eslintrc
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"plugins": ["jest", "@typescript-eslint"],
|
"plugins": ["jest", "@typescript-eslint"],
|
||||||
"extends": ["plugin:github/es6"],
|
"extends": ["plugin:github/recommended"],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"parserOptions": {
|
"parserOptions": {
|
||||||
"ecmaVersion": 9,
|
"ecmaVersion": 9,
|
||||||
@@ -16,13 +16,11 @@
|
|||||||
"@typescript-eslint/no-require-imports": "error",
|
"@typescript-eslint/no-require-imports": "error",
|
||||||
"@typescript-eslint/array-type": "error",
|
"@typescript-eslint/array-type": "error",
|
||||||
"@typescript-eslint/await-thenable": "error",
|
"@typescript-eslint/await-thenable": "error",
|
||||||
"@typescript-eslint/ban-ts-ignore": "error",
|
"@typescript-eslint/ban-ts-comment": "error",
|
||||||
"camelcase": "off",
|
"camelcase": "off",
|
||||||
"@typescript-eslint/camelcase": "error",
|
"@typescript-eslint/consistent-type-assertions": "error",
|
||||||
"@typescript-eslint/class-name-casing": "error",
|
|
||||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
"@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-array-constructor": "error",
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "error",
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
@@ -32,7 +30,6 @@
|
|||||||
"@typescript-eslint/no-misused-new": "error",
|
"@typescript-eslint/no-misused-new": "error",
|
||||||
"@typescript-eslint/no-namespace": "error",
|
"@typescript-eslint/no-namespace": "error",
|
||||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
"@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-qualifier": "error",
|
||||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||||
"@typescript-eslint/no-useless-constructor": "error",
|
"@typescript-eslint/no-useless-constructor": "error",
|
||||||
@@ -40,7 +37,6 @@
|
|||||||
"@typescript-eslint/prefer-for-of": "warn",
|
"@typescript-eslint/prefer-for-of": "warn",
|
||||||
"@typescript-eslint/prefer-function-type": "warn",
|
"@typescript-eslint/prefer-function-type": "warn",
|
||||||
"@typescript-eslint/prefer-includes": "error",
|
"@typescript-eslint/prefer-includes": "error",
|
||||||
"@typescript-eslint/prefer-interface": "error",
|
|
||||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||||
"@typescript-eslint/promise-function-async": "error",
|
"@typescript-eslint/promise-function-async": "error",
|
||||||
"@typescript-eslint/require-array-sort-compare": "error",
|
"@typescript-eslint/require-array-sort-compare": "error",
|
||||||
|
|||||||
9
.github/dependabot.yml
vendored
Normal file
9
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
# Enable version updates for npm
|
||||||
|
- package-ecosystem: 'npm'
|
||||||
|
# Look for `package.json` and `lock` files in the `root` directory
|
||||||
|
directory: '/'
|
||||||
|
# Check the npm registry for updates every day (weekdays)
|
||||||
|
schedule:
|
||||||
|
interval: 'daily'
|
||||||
16
.github/workflows/checkin.yml
vendored
16
.github/workflows/checkin.yml
vendored
@@ -1,16 +0,0 @@
|
|||||||
name: "build-test"
|
|
||||||
on: # rebuild any PRs and main branch changes
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- 'releases/*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build: # make sure build/ci work properly
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- run: |
|
|
||||||
npm ci
|
|
||||||
npm run all
|
|
||||||
23
.github/workflows/test.yml
vendored
Normal file
23
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
name: 'build-test'
|
||||||
|
on: # rebuild any PRs and main branch changes
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- 'releases/*'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build: # make sure build/ci work properly
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- run: |
|
||||||
|
npm install
|
||||||
|
- run: |
|
||||||
|
npm run all
|
||||||
|
test: # make sure the action works on a clean machine without building
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: ./
|
||||||
|
- run: kustomize version
|
||||||
11
.prettierrc
11
.prettierrc
@@ -1,11 +0,0 @@
|
|||||||
{
|
|
||||||
"printWidth": 80,
|
|
||||||
"tabWidth": 2,
|
|
||||||
"useTabs": false,
|
|
||||||
"semi": false,
|
|
||||||
"singleQuote": true,
|
|
||||||
"trailingComma": "none",
|
|
||||||
"bracketSpacing": false,
|
|
||||||
"arrowParens": "avoid",
|
|
||||||
"parser": "typescript"
|
|
||||||
}
|
|
||||||
10
.prettierrc.json
Normal file
10
.prettierrc.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"printWidth": 80,
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"semi": false,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "none",
|
||||||
|
"bracketSpacing": false,
|
||||||
|
"arrowParens": "avoid"
|
||||||
|
}
|
||||||
1
.tool-versions
Normal file
1
.tool-versions
Normal file
@@ -0,0 +1 @@
|
|||||||
|
nodejs 14.12.0
|
||||||
42
CHANGELOG.MD
Normal file
42
CHANGELOG.MD
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## v1.5.2
|
||||||
|
|
||||||
|
### Security
|
||||||
|
|
||||||
|
- Bump @actions/core to v1.2.6 to address deprecations raised in #30
|
||||||
|
|
||||||
|
## v1.5.1
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Cache kustomize by requested version spec as key
|
||||||
|
|
||||||
|
## v1.5.0
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Simplified asset look up
|
||||||
|
|
||||||
|
## v1.4.0
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Adds support for semver version ranges. Example: 3.x, 3.2.x
|
||||||
|
- Add a step in the workflow to test the action with default value
|
||||||
|
|
||||||
|
## v1.2.0
|
||||||
|
|
||||||
|
N/A
|
||||||
|
|
||||||
|
## v1.1.0
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Support for new download path for kustomize
|
||||||
|
|
||||||
|
## v1.0.0
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Update metadata
|
||||||
36
DEVELOPER.MD
36
DEVELOPER.MD
@@ -4,29 +4,32 @@
|
|||||||
|
|
||||||
# Create a JavaScript Action using TypeScript
|
# Create a JavaScript Action using TypeScript
|
||||||
|
|
||||||
Use this template to bootstrap the creation of a JavaScript action.:rocket:
|
Use this template to bootstrap the creation of a TypeScript action.:rocket:
|
||||||
|
|
||||||
This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.
|
This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.
|
||||||
|
|
||||||
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
|
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
|
||||||
|
|
||||||
## Create an action from this template
|
## Create an action from this template
|
||||||
|
|
||||||
Click the `Use this Template` and provide the new repo details for your action
|
Click the `Use this Template` and provide the new repo details for your action
|
||||||
|
|
||||||
## Code in Master
|
## Code in Main
|
||||||
|
|
||||||
|
Install the dependencies
|
||||||
|
|
||||||
Install the dependencies
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install
|
$ npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Build the typescript and package it for distribution
|
Build the typescript and package it for distribution
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run build && npm run pack
|
$ npm run build && npm run package
|
||||||
```
|
```
|
||||||
|
|
||||||
Run the tests :heavy_check_mark:
|
Run the tests :heavy_check_mark:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ npm test
|
||||||
|
|
||||||
@@ -55,9 +58,9 @@ import * as core from '@actions/core';
|
|||||||
...
|
...
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
@@ -70,23 +73,26 @@ See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/R
|
|||||||
|
|
||||||
## Publish to a distribution branch
|
## Publish to a distribution branch
|
||||||
|
|
||||||
Actions are run from GitHub repos so we will checkin the packed dist folder.
|
Actions are run from GitHub repos so we will checkin the packed dist folder.
|
||||||
|
|
||||||
Then run [ncc](https://github.com/zeit/ncc) and push the results:
|
Then run [ncc](https://github.com/zeit/ncc) and push the results:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run pack
|
$ npm run package
|
||||||
$ git add dist
|
$ git add dist
|
||||||
$ git commit -a -m "prod dependencies"
|
$ git commit -a -m "prod dependencies"
|
||||||
$ git push origin releases/v1
|
$ git push origin releases/v1
|
||||||
```
|
```
|
||||||
|
|
||||||
Your action is now published! :rocket:
|
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
|
||||||
|
|
||||||
|
Your action is now published! :rocket:
|
||||||
|
|
||||||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
|
||||||
|
|
||||||
## Validate
|
## Validate
|
||||||
|
|
||||||
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)])
|
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
uses: ./
|
uses: ./
|
||||||
@@ -94,8 +100,8 @@ with:
|
|||||||
milliseconds: 1000
|
milliseconds: 1000
|
||||||
```
|
```
|
||||||
|
|
||||||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
|
See the [actions tab](https://github.com/actions/typescript-action/actions) for runs of this action! :rocket:
|
||||||
|
|
||||||
## Usage:
|
## Usage:
|
||||||
|
|
||||||
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
|
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -1,4 +1,10 @@
|
|||||||
## TLDR
|

|
||||||
|
|
||||||
|
## Description
|
||||||
|
|
||||||
|
Install any kustomize version as a step in your workflow
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
on:
|
on:
|
||||||
@@ -12,7 +18,7 @@ jobs:
|
|||||||
needs:
|
needs:
|
||||||
- publish-image
|
- publish-image
|
||||||
steps:
|
steps:
|
||||||
- uses: imranismail/setup-kustomize@master
|
- uses: imranismail/setup-kustomize@v1
|
||||||
with:
|
with:
|
||||||
kustomize-version: "3.1.0"
|
kustomize-version: "3.1.0"
|
||||||
- run: git clone https://${REPO_TOKEN}@github.com/org/deployment.git .
|
- run: git clone https://${REPO_TOKEN}@github.com/org/deployment.git .
|
||||||
|
|||||||
@@ -17,14 +17,24 @@ describe('installer tests', () => {
|
|||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await io.rmRF(toolDir)
|
await io.rmRF(toolDir)
|
||||||
await io.rmRF(tempDir)
|
await io.rmRF(tempDir)
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
it('Acquires the max satisfying version range', async () => {
|
||||||
await io.rmRF(toolDir)
|
await installer.getKustomize('~> 3.0')
|
||||||
await io.rmRF(tempDir)
|
const kustomizeDir = path.join(toolDir, 'kustomize', '~> 3.0', os.arch())
|
||||||
}, 100000)
|
expect(fs.existsSync(`${kustomizeDir}.complete`)).toBe(true)
|
||||||
|
|
||||||
it('Acquires kustomize version 3.2.0 successfully', async () => {
|
if (IS_WINDOWS) {
|
||||||
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize.exe'))).toBe(true)
|
||||||
|
} else {
|
||||||
|
expect(fs.existsSync(path.join(kustomizeDir, 'kustomize'))).toBe(true)
|
||||||
|
expect(() =>
|
||||||
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
|
).not.toThrow()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Acquires kustomize version 3.2.0', async () => {
|
||||||
await installer.getKustomize('3.2.0')
|
await installer.getKustomize('3.2.0')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch())
|
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.0', os.arch())
|
||||||
|
|
||||||
@@ -38,9 +48,9 @@ describe('installer tests', () => {
|
|||||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
).not.toThrow()
|
).not.toThrow()
|
||||||
}
|
}
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
it('Acquires kustomize version 3.2.1 successfully', async () => {
|
it('Acquires kustomize version 3.2.1', async () => {
|
||||||
await installer.getKustomize('3.2.1')
|
await installer.getKustomize('3.2.1')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())
|
const kustomizeDir = path.join(toolDir, 'kustomize', '3.2.1', os.arch())
|
||||||
|
|
||||||
@@ -54,9 +64,9 @@ describe('installer tests', () => {
|
|||||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
).not.toThrow()
|
).not.toThrow()
|
||||||
}
|
}
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
it('Acquires kustomize version 3.3.0 successfully', async () => {
|
it('Acquires kustomize version 3.3.0', async () => {
|
||||||
await installer.getKustomize('3.3.0')
|
await installer.getKustomize('3.3.0')
|
||||||
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())
|
const kustomizeDir = path.join(toolDir, 'kustomize', '3.3.0', os.arch())
|
||||||
|
|
||||||
@@ -70,7 +80,7 @@ describe('installer tests', () => {
|
|||||||
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
fs.accessSync(path.join(kustomizeDir, 'kustomize'), fs.constants.X_OK)
|
||||||
).not.toThrow()
|
).not.toThrow()
|
||||||
}
|
}
|
||||||
}, 100000)
|
})
|
||||||
|
|
||||||
it('Throws if no location contains correct kustomize version', async () => {
|
it('Throws if no location contains correct kustomize version', async () => {
|
||||||
let thrown = false
|
let thrown = false
|
||||||
|
|||||||
7208
dist/index.js
vendored
7208
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
1
dist/index.js.map
vendored
Normal file
1
dist/index.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
3912
dist/sourcemap-register.js
vendored
Normal file
3912
dist/sourcemap-register.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,9 @@ module.exports = {
|
|||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/*.test.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
testRunner: 'jest-circus/runner',
|
testRunner: 'jest-circus/runner',
|
||||||
|
testTimeout: 60000,
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.ts$': 'ts-jest'
|
'^.+\\.ts$': 'ts-jest'
|
||||||
},
|
},
|
||||||
verbose: true
|
verbose: true
|
||||||
}
|
}
|
||||||
|
|||||||
6252
package-lock.json
generated
6252
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@@ -9,9 +9,9 @@
|
|||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"pack": "ncc build",
|
"package": "ncc build --source-map",
|
||||||
"test": "jest",
|
"test": "jest -i",
|
||||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
"all": "npm run build && npm run format && npm run lint && npm run package && npm test"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -25,26 +25,27 @@
|
|||||||
"author": "Imran Ismail",
|
"author": "Imran Ismail",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.0",
|
"@actions/core": "^1.2.6",
|
||||||
"@actions/io": "^1.0.2",
|
"@actions/io": "^1.0.2",
|
||||||
"@actions/tool-cache": "^1.3.3",
|
"@actions/tool-cache": "^1.3.3",
|
||||||
"semver": "^7.1.3",
|
"@octokit/plugin-retry": "^3.0.6",
|
||||||
"typed-rest-client": "^1.7.2"
|
"@octokit/rest": "^18.0.6",
|
||||||
|
"semver": "^7.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.23",
|
"@types/jest": "^26.0.14",
|
||||||
"@types/node": "^12.7.12",
|
"@types/node": "^14.11.8",
|
||||||
"@types/semver": "^7.1.0",
|
"@types/semver": "^7.3.4",
|
||||||
"@typescript-eslint/parser": "^2.8.0",
|
"@typescript-eslint/parser": "^4.4.1",
|
||||||
"@zeit/ncc": "^0.20.5",
|
"@zeit/ncc": "^0.22.3",
|
||||||
"eslint": "^5.16.0",
|
"eslint": "^7.10.0",
|
||||||
"eslint-plugin-github": "^2.0.0",
|
"eslint-plugin-github": "^4.0.1",
|
||||||
"eslint-plugin-jest": "^22.21.0",
|
"eslint-plugin-jest": "^24.1.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"jest-circus": "^24.9.0",
|
"jest-circus": "^26.5.3",
|
||||||
"js-yaml": "^3.13.1",
|
"js-yaml": "^3.13.1",
|
||||||
"prettier": "^1.19.1",
|
"prettier": "^2.1.2",
|
||||||
"ts-jest": "^24.2.0",
|
"ts-jest": "^24.2.0",
|
||||||
"typescript": "^3.6.4"
|
"typescript": "^4.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
227
src/installer.ts
227
src/installer.ts
@@ -1,15 +1,19 @@
|
|||||||
// Load tempDirectory before it gets wiped by tool-cache
|
// Load tempDirectory before it gets wiped by tool-cache
|
||||||
|
import {Octokit} from '@octokit/rest'
|
||||||
|
import {retry} from '@octokit/plugin-retry'
|
||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import * as tc from '@actions/tool-cache'
|
import * as cache from '@actions/tool-cache'
|
||||||
import * as restm from 'typed-rest-client/RestClient'
|
|
||||||
import * as os from 'os'
|
|
||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import * as semver from 'semver'
|
import * as semver from 'semver'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''
|
let tempDirectory = process.env['RUNNER_TEMPDIRECTORY'] || ''
|
||||||
|
|
||||||
const osPlat: string = os.platform()
|
const RetriableOctokit = Octokit.plugin(retry)
|
||||||
const osArch: string = os.arch()
|
const octokit = new RetriableOctokit()
|
||||||
|
const versionRegex = /\d+\.?\d*\.?\d*/
|
||||||
|
const toolName = 'kustomize'
|
||||||
|
const platform = process.platform
|
||||||
|
const arch = process.arch === 'x64' ? 'amd64' : process.arch
|
||||||
|
|
||||||
if (!tempDirectory) {
|
if (!tempDirectory) {
|
||||||
let baseLocation
|
let baseLocation
|
||||||
@@ -26,186 +30,99 @@ if (!tempDirectory) {
|
|||||||
tempDirectory = path.join(baseLocation, 'actions', 'temp')
|
tempDirectory = path.join(baseLocation, 'actions', 'temp')
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getKustomize(versionSpec: string): Promise<void> {
|
export async function getKustomize(targetVersion: string): Promise<void> {
|
||||||
// check cache
|
if (!semver.validRange(targetVersion))
|
||||||
let toolPath: string
|
throw new Error(`invalid semver requested: ${targetVersion}`)
|
||||||
|
|
||||||
toolPath = tc.find('kustomize', versionSpec)
|
let kustomizePath = cache.find('kustomize', targetVersion)
|
||||||
|
|
||||||
// If not found in cache, download
|
if (!kustomizePath) {
|
||||||
if (!toolPath) {
|
const version = await getMaxSatisfyingVersion(targetVersion)
|
||||||
let version: string
|
kustomizePath = await acquireVersion(version)
|
||||||
const c = semver.clean(versionSpec) || ''
|
}
|
||||||
// If explicit version
|
|
||||||
if (semver.valid(c) != null) {
|
|
||||||
// version to download
|
|
||||||
version = versionSpec
|
|
||||||
} else {
|
|
||||||
// query kustomize for a matching version
|
|
||||||
version = await queryLatestMatch(versionSpec)
|
|
||||||
if (!version) {
|
|
||||||
throw new Error(
|
|
||||||
`Unable to find Kustomize version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check cache
|
return core.addPath(kustomizePath)
|
||||||
toolPath = tc.find('kustomize', version)
|
}
|
||||||
|
|
||||||
|
interface Version {
|
||||||
|
resolved: string
|
||||||
|
target: string
|
||||||
|
url: string
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getMaxSatisfyingVersion(
|
||||||
|
targetVersion: string
|
||||||
|
): Promise<Version> {
|
||||||
|
const version = {target: targetVersion}
|
||||||
|
const availableVersions: Map<string, string> = new Map()
|
||||||
|
|
||||||
|
for await (const response of octokit.paginate.iterator(
|
||||||
|
octokit.repos.listReleases,
|
||||||
|
{
|
||||||
|
owner: 'kubernetes-sigs',
|
||||||
|
repo: 'kustomize'
|
||||||
}
|
}
|
||||||
|
)) {
|
||||||
|
for (const release of response.data) {
|
||||||
|
const matchingAsset = release.assets.find(
|
||||||
|
asset =>
|
||||||
|
asset.name.includes('kustomize') &&
|
||||||
|
asset.name.includes(platform) &&
|
||||||
|
asset.name.includes(arch)
|
||||||
|
)
|
||||||
|
|
||||||
if (!toolPath) {
|
if (matchingAsset) {
|
||||||
// download, extract, cache
|
const kustomizeVersion = (versionRegex.exec(release.name) || []).shift()
|
||||||
toolPath = await acquireKustomize(version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core.addPath(toolPath)
|
if (kustomizeVersion != null) {
|
||||||
}
|
availableVersions.set(
|
||||||
|
kustomizeVersion,
|
||||||
interface IAsset {
|
matchingAsset.browser_download_url
|
||||||
browser_download_url: string
|
)
|
||||||
name: string
|
}
|
||||||
}
|
|
||||||
|
|
||||||
interface IKustomizeVersion {
|
|
||||||
name: string
|
|
||||||
assets: IAsset[]
|
|
||||||
}
|
|
||||||
|
|
||||||
async function queryLatestMatch(versionSpec: string): Promise<string> {
|
|
||||||
let dataFileName: string
|
|
||||||
|
|
||||||
switch (osPlat) {
|
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
case 'win32':
|
|
||||||
dataFileName = osPlat
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (osArch) {
|
|
||||||
case 'x64':
|
|
||||||
dataFileName = `${dataFileName}_amd64`
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
dataFileName = `${dataFileName}_${osArch}`
|
|
||||||
}
|
|
||||||
|
|
||||||
const versions: string[] = []
|
|
||||||
const dataUrl =
|
|
||||||
'https://api.github.com/repos/kubernetes-sigs/kustomize/releases'
|
|
||||||
const rest: restm.RestClient = new restm.RestClient('setup-kustomize')
|
|
||||||
const kustomizeVersions: IKustomizeVersion[] =
|
|
||||||
(await rest.get<IKustomizeVersion[]>(dataUrl)).result || []
|
|
||||||
|
|
||||||
for (const kustomizeVersion of kustomizeVersions) {
|
|
||||||
if (
|
|
||||||
kustomizeVersion.assets.some(asset => asset.name.includes(dataFileName))
|
|
||||||
) {
|
|
||||||
const version = semver.clean(kustomizeVersion.name)
|
|
||||||
|
|
||||||
if (version != null) {
|
|
||||||
versions.push(version)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return evaluateVersions(versions, versionSpec)
|
const resolved = semver.maxSatisfying(
|
||||||
}
|
[...availableVersions.keys()],
|
||||||
|
version.target
|
||||||
|
)
|
||||||
|
|
||||||
function evaluateVersions(versions: string[], versionSpec: string): string {
|
if (!resolved) {
|
||||||
let version = ''
|
throw new Error(
|
||||||
|
`Unable to find Kustomize version '${version.target}' for platform '${platform}' and architecture ${arch}.`
|
||||||
core.debug(`evaluating ${versions.length} versions`)
|
)
|
||||||
|
|
||||||
versions = versions.sort((a, b) => {
|
|
||||||
if (semver.gt(a, b)) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
return -1
|
|
||||||
})
|
|
||||||
|
|
||||||
for (let i = versions.length - 1; i >= 0; i--) {
|
|
||||||
const potential: string = versions[i]
|
|
||||||
const satisfied: boolean = semver.satisfies(potential, versionSpec)
|
|
||||||
if (satisfied) {
|
|
||||||
version = potential
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version) {
|
const url = availableVersions.get(resolved) as string
|
||||||
core.debug(`matched: ${version}`)
|
|
||||||
} else {
|
|
||||||
core.debug('match not found')
|
|
||||||
}
|
|
||||||
|
|
||||||
return version
|
return {...version, resolved, url}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function acquireKustomize(version: string): Promise<string> {
|
async function acquireVersion(version: Version): Promise<string> {
|
||||||
version = semver.clean(version) || ''
|
const toolFilename =
|
||||||
|
process.platform === 'win32' ? `${toolName}.exe` : toolName
|
||||||
let downloadUrl: string
|
|
||||||
let toolPath: string
|
let toolPath: string
|
||||||
let toolFilename = 'kustomize'
|
|
||||||
const toolName = 'kustomize'
|
|
||||||
|
|
||||||
if (osPlat === 'win32') {
|
|
||||||
toolFilename = `${toolFilename}.exe`
|
|
||||||
}
|
|
||||||
|
|
||||||
if (semver.gte(version, '3.3.0')) {
|
|
||||||
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${version}/kustomize_v${version}_%{os}_%{arch}.tar.gz`
|
|
||||||
} else if (semver.gte(version, '3.2.1')) {
|
|
||||||
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/v${version}/kustomize_kustomize.v${version}_%{os}_%{arch}`
|
|
||||||
} else {
|
|
||||||
downloadUrl = `https://github.com/kubernetes-sigs/kustomize/releases/download/v${version}/kustomize_${version}_%{os}_%{arch}`
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (osPlat) {
|
|
||||||
case 'win32':
|
|
||||||
if (semver.lte(version, '3.2.1'))
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`)
|
|
||||||
downloadUrl = downloadUrl.replace('%{os}', 'windows')
|
|
||||||
if (semver.lt(version, '3.3.0')) downloadUrl = `${downloadUrl}.exe`
|
|
||||||
break
|
|
||||||
case 'linux':
|
|
||||||
case 'darwin':
|
|
||||||
downloadUrl = downloadUrl.replace('%{os}', osPlat)
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected OS '${osPlat}'`)
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (osArch) {
|
|
||||||
case 'x64':
|
|
||||||
downloadUrl = downloadUrl.replace('%{arch}', 'amd64')
|
|
||||||
break
|
|
||||||
default:
|
|
||||||
throw new Error(`Unexpected Arch '${osArch}'`)
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
toolPath = await tc.downloadTool(downloadUrl)
|
toolPath = await cache.downloadTool(version.url)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.debug(err)
|
core.debug(err)
|
||||||
throw new Error(`Failed to download version ${version}: ${err}`)
|
throw new Error(`Failed to download version ${version.target}: ${err}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (downloadUrl.endsWith('.tar.gz')) {
|
if (version.url.endsWith('.tar.gz')) {
|
||||||
toolPath = await tc.extractTar(toolPath)
|
toolPath = await cache.extractTar(toolPath)
|
||||||
toolPath = path.join(toolPath, toolFilename)
|
toolPath = path.join(toolPath, toolFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (osPlat) {
|
switch (process.platform) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
fs.chmodSync(toolPath, 0o755)
|
fs.chmodSync(toolPath, 0o755)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
return await tc.cacheFile(toolPath, toolFilename, toolName, version)
|
return await cache.cacheFile(toolPath, toolFilename, toolName, version.target)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user