Skip to content

Commit

Permalink
feat(kubectl-set-context): now the action will set context if passed any
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-ra committed Jul 24, 2023
1 parent 0a73da9 commit 36d16a0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
13 changes: 11 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ inputs:
description: 'The generic chart address'

context:
required: true
required: false
description: 'The kubernetes target context'
default: 'default'

token:
required: true
Expand All @@ -19,11 +18,21 @@ inputs:
required: true
description: 'Kubernetes config file to connect'

releaseName:
required: false
description: 'The name of your release'
default: ${{ github.repository.name }}

valuesPath:
required: false
description: 'The values path to use it with generic chart'
default: '.helm/values.yaml'

namespace:
required: false
description: 'The namespace you want to deploy your services'
default: 'default'

runs:
using: 'node16'
main: 'dist/index.js'
2 changes: 2 additions & 0 deletions src/handlers/deploy-helm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ export async function deployHelmChart(
namespace: string = 'default'
): Promise<void> {
info('deploying works')

execSync('kubectl get pods')
}
23 changes: 23 additions & 0 deletions src/handlers/kubectl-set-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {execSync} from 'child_process'
import {repositoryDirectory} from '../constants/repositoryDirectory'
import * as core from '@actions/core'
import {errorHandler} from '../helpers/error-handler'

export async function setContext(context?: string) {
try {
if (!context) {
return
}

core.info('Configuring context')
execSync(`kubectl config set-context ${context}`, {
stdio: 'inherit',
cwd: repositoryDirectory
})

core.info(`Context successfully is set to ${context}`)
} catch (error) {
core.error('error in setting context')
errorHandler(error)
}
}
2 changes: 1 addition & 1 deletion src/handlers/setup-kubectl-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export async function setupKubectlConfig(kubeConfig: string) {
throw new Error('No kubeConfig provided')
}

core.info('Preparing the kubeconfig file')
core.info('Preparing the kubeConfig file')
await writeFile('kubeconfig', kubeConfig)

execSync(
Expand Down
10 changes: 6 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {setupKubectlConfig} from './handlers/setup-kubectl-config'
import {execSync} from 'child_process'
import {repositoryDirectory} from './constants/repositoryDirectory'
import {errorHandler} from './helpers/error-handler'
import {deployHelmChart} from './handlers/deploy-helm'

async function run(): Promise<void> {
try {
Expand All @@ -13,8 +14,10 @@ async function run(): Promise<void> {
trimWhitespace: true
})

const valuesPath = core.getInput('valuesPath', {required: true})
const context = core.getInput('context', {required: true})
const valuesPath = core.getInput('valuesPath')
const releaseName = core.getInput('releaseName')
const namespace = core.getInput('namespace')
const context = core.getInput('context', {required: false})
const token = core.getInput('token', {required: true})
const kubeConfig = core.getInput('kubeConfig', {required: true})

Expand All @@ -23,8 +26,7 @@ async function run(): Promise<void> {
await installKubectl()
await setupKubectlConfig(kubeConfig)
await installHelm()

execSync(`ls -lha`, {stdio: 'inherit', cwd: repositoryDirectory})
await deployHelmChart(releaseName, genericChart, namespace)

return
} catch (error) {
Expand Down

0 comments on commit 36d16a0

Please sign in to comment.