发布1.0版本
This commit is contained in:
parent
bbab50bce7
commit
e7060a31d2
@ -8,6 +8,14 @@ inputs:
|
|||||||
description: Deploy Image Url
|
description: Deploy Image Url
|
||||||
required: true
|
required: true
|
||||||
default: ''
|
default: ''
|
||||||
|
config-path:
|
||||||
|
description: Deployment Config Path
|
||||||
|
required: false
|
||||||
|
default: 'deploy/config.json'
|
||||||
|
cluster-path:
|
||||||
|
description: Deployment Cluster Path
|
||||||
|
required: false
|
||||||
|
default: 'deploy/cluster/'
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: node20
|
using: node20
|
||||||
|
|||||||
171948
dist/index.js
generated
vendored
171948
dist/index.js
generated
vendored
File diff suppressed because it is too large
Load Diff
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
42
package-lock.json
generated
42
package-lock.json
generated
@ -10,7 +10,9 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@kubernetes/client-node": "^1.3.0"
|
"@kubernetes/client-node": "^1.3.0",
|
||||||
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
|
"lodash": "^4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^1.2.9",
|
"@eslint/compat": "^1.2.9",
|
||||||
@ -20,6 +22,7 @@
|
|||||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
"@rollup/plugin-typescript": "^12.1.1",
|
"@rollup/plugin-typescript": "^12.1.1",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
|
"@types/lodash": "^4.17.17",
|
||||||
"@types/node": "^20.17.48",
|
"@types/node": "^20.17.48",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
||||||
"@typescript-eslint/parser": "^8.32.1",
|
"@typescript-eslint/parser": "^8.32.1",
|
||||||
@ -3023,6 +3026,26 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@rollup/plugin-json": {
|
||||||
|
"version": "6.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz",
|
||||||
|
"integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@rollup/pluginutils": "^5.1.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"rollup": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@rollup/plugin-node-resolve": {
|
"node_modules/@rollup/plugin-node-resolve": {
|
||||||
"version": "16.0.1",
|
"version": "16.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-16.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-16.0.1.tgz",
|
||||||
@ -3078,7 +3101,6 @@
|
|||||||
"version": "5.1.4",
|
"version": "5.1.4",
|
||||||
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.4.tgz",
|
"resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.4.tgz",
|
||||||
"integrity": "sha512-USm05zrsFxYLPdWWq+K3STlWiT/3ELn3RcV5hJMghpeAIhxfsUIg6mt12CBJBInWMV4VneoV7SfGv8xIwo2qNQ==",
|
"integrity": "sha512-USm05zrsFxYLPdWWq+K3STlWiT/3ELn3RcV5hJMghpeAIhxfsUIg6mt12CBJBInWMV4VneoV7SfGv8xIwo2qNQ==",
|
||||||
"dev": true,
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/estree": "^1.0.0",
|
"@types/estree": "^1.0.0",
|
||||||
"estree-walker": "^2.0.2",
|
"estree-walker": "^2.0.2",
|
||||||
@ -3493,7 +3515,6 @@
|
|||||||
"version": "1.0.7",
|
"version": "1.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.7.tgz",
|
||||||
"integrity": "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==",
|
"integrity": "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/graceful-fs": {
|
"node_modules/@types/graceful-fs": {
|
||||||
@ -3558,6 +3579,13 @@
|
|||||||
"integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==",
|
"integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/lodash": {
|
||||||
|
"version": "4.17.17",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.17.tgz",
|
||||||
|
"integrity": "sha512-RRVJ+J3J+WmyOTqnz3PiBLA501eKwXl2noseKOrNo/6+XEHjTAxO4xHvxQB6QuNm+s4WRbn6rSiap8+EA+ykFQ==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "20.17.48",
|
"version": "20.17.48",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.48.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.48.tgz",
|
||||||
@ -6483,8 +6511,7 @@
|
|||||||
"node_modules/estree-walker": {
|
"node_modules/estree-walker": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
|
||||||
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
|
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"node_modules/esutils": {
|
"node_modules/esutils": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
@ -8806,7 +8833,7 @@
|
|||||||
"version": "4.17.21",
|
"version": "4.17.21",
|
||||||
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||||
"dev": true
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/lodash.memoize": {
|
"node_modules/lodash.memoize": {
|
||||||
"version": "4.1.2",
|
"version": "4.1.2",
|
||||||
@ -9516,7 +9543,6 @@
|
|||||||
"version": "4.0.2",
|
"version": "4.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz",
|
||||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||||
"dev": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=12"
|
||||||
},
|
},
|
||||||
@ -10257,7 +10283,7 @@
|
|||||||
"version": "4.41.0",
|
"version": "4.41.0",
|
||||||
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.41.0.tgz",
|
"resolved": "https://registry.npmjs.org/rollup/-/rollup-4.41.0.tgz",
|
||||||
"integrity": "sha512-HqMFpUbWlf/tvcxBFNKnJyzc7Lk+XO3FGc3pbNBLqEbOz0gPLRgcrlS3UF4MfUrVlstOaP/q0kM6GVvi+LrLRg==",
|
"integrity": "sha512-HqMFpUbWlf/tvcxBFNKnJyzc7Lk+XO3FGc3pbNBLqEbOz0gPLRgcrlS3UF4MfUrVlstOaP/q0kM6GVvi+LrLRg==",
|
||||||
"dev": true,
|
"devOptional": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/estree": "1.0.7"
|
"@types/estree": "1.0.7"
|
||||||
|
|||||||
@ -38,7 +38,9 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.11.1",
|
"@actions/core": "^1.11.1",
|
||||||
"@kubernetes/client-node": "^1.3.0"
|
"@kubernetes/client-node": "^1.3.0",
|
||||||
|
"@rollup/plugin-json": "^6.1.0",
|
||||||
|
"lodash": "^4.17.21"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/compat": "^1.2.9",
|
"@eslint/compat": "^1.2.9",
|
||||||
@ -48,6 +50,7 @@
|
|||||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
"@rollup/plugin-typescript": "^12.1.1",
|
"@rollup/plugin-typescript": "^12.1.1",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
|
"@types/lodash": "^4.17.17",
|
||||||
"@types/node": "^20.17.48",
|
"@types/node": "^20.17.48",
|
||||||
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
"@typescript-eslint/eslint-plugin": "^8.32.1",
|
||||||
"@typescript-eslint/parser": "^8.32.1",
|
"@typescript-eslint/parser": "^8.32.1",
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
import commonjs from '@rollup/plugin-commonjs'
|
import commonjs from '@rollup/plugin-commonjs'
|
||||||
import nodeResolve from '@rollup/plugin-node-resolve'
|
import nodeResolve from '@rollup/plugin-node-resolve'
|
||||||
import typescript from '@rollup/plugin-typescript'
|
import typescript from '@rollup/plugin-typescript'
|
||||||
|
import json from '@rollup/plugin-json'
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
input: 'src/index.ts',
|
input: 'src/index.ts',
|
||||||
@ -12,7 +13,12 @@ const config = {
|
|||||||
format: 'es',
|
format: 'es',
|
||||||
sourcemap: true
|
sourcemap: true
|
||||||
},
|
},
|
||||||
plugins: [typescript(), nodeResolve({ preferBuiltins: true }), commonjs()]
|
plugins: [
|
||||||
|
typescript(),
|
||||||
|
nodeResolve({ preferBuiltins: true }),
|
||||||
|
commonjs(),
|
||||||
|
json()
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
export default config
|
export default config
|
||||||
|
|||||||
67
src/main.ts
67
src/main.ts
@ -1,4 +1,15 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
|
import * as k8s from '@kubernetes/client-node'
|
||||||
|
import * as fs from 'fs'
|
||||||
|
import * as path from 'path'
|
||||||
|
import { filter, clone } from 'lodash'
|
||||||
|
|
||||||
|
interface Config {
|
||||||
|
branch: string
|
||||||
|
cluster: string
|
||||||
|
namespace: string
|
||||||
|
deployment: string
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main function for the action.
|
* The main function for the action.
|
||||||
@ -7,13 +18,57 @@ import * as core from '@actions/core'
|
|||||||
*/
|
*/
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const image: string = core.getInput('image')
|
//
|
||||||
// Debug logs are only output if the `ACTIONS_STEP_DEBUG` secret is true
|
const configPath = core.getInput('config-path')
|
||||||
console.log('image', image)
|
console.log('configPath:', configPath)
|
||||||
|
//
|
||||||
|
const clusterPath = core.getInput('cluster-path')
|
||||||
|
console.log('clusterPath:', clusterPath)
|
||||||
|
//
|
||||||
|
const deployImage: string = core.getInput('image')
|
||||||
|
console.log('image:', deployImage)
|
||||||
|
//
|
||||||
const branch: string = String(process.env.GITHUB_REF_NAME)
|
const branch: string = String(process.env.GITHUB_REF_NAME)
|
||||||
console.log('branch', branch)
|
console.log('branch:', branch)
|
||||||
// Log the current timestamp, wait, then log the new timestamp
|
//
|
||||||
core.debug(new Date().toTimeString())
|
const configJson = fs.readFileSync(path.join(__dirname, configPath), 'utf8')
|
||||||
|
console.log('configJson:', configJson)
|
||||||
|
const deployConfigArr = JSON.parse(configJson) as Config[]
|
||||||
|
console.log('deployConfigArr:', deployConfigArr)
|
||||||
|
const filterDeployConfig = filter(deployConfigArr, { branch: branch })
|
||||||
|
for (const deployConfig of filterDeployConfig) {
|
||||||
|
console.log('deployConfig:', deployConfig)
|
||||||
|
const kc = new k8s.KubeConfig()
|
||||||
|
kc.loadFromFile(
|
||||||
|
path.join(__dirname, clusterPath + deployConfig.cluster + '.yaml')
|
||||||
|
)
|
||||||
|
const k8sApi = kc.makeApiClient(k8s.AppsV1Api)
|
||||||
|
const nowDeployment = await k8sApi.readNamespacedDeployment({
|
||||||
|
name: deployConfig.deployment,
|
||||||
|
namespace: deployConfig.namespace
|
||||||
|
})
|
||||||
|
console.log('nowDeployment:', nowDeployment)
|
||||||
|
const deployment = clone(nowDeployment)
|
||||||
|
if (deployment.spec === undefined) {
|
||||||
|
console.log('deployment.spec is missing')
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (deployment.spec.template.spec === undefined) {
|
||||||
|
console.log('deployment.spec.template.spec is missing')
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if (deployment.spec.template.spec.containers.length === 0) {
|
||||||
|
console.log('deployment.spec.template.spec.containers is zero')
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
deployment.spec.template.spec.containers[0].image = deployImage
|
||||||
|
const deployRes = await k8sApi.patchNamespacedDeployment({
|
||||||
|
name: deployConfig.deployment,
|
||||||
|
namespace: deployConfig.namespace,
|
||||||
|
body: deployment
|
||||||
|
})
|
||||||
|
console.log('deployRes:', deployRes)
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Fail the workflow run if an error occurs
|
// Fail the workflow run if an error occurs
|
||||||
if (error instanceof Error) core.setFailed(error.message)
|
if (error instanceof Error) core.setFailed(error.message)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user