mirror of
https://github.com/werf/actions.git
synced 2026-02-05 10:56:23 +03:00
Refactor: combine common actions code into one function
This commit is contained in:
@@ -1,31 +1,9 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Manager} from './manager'
|
||||
import {
|
||||
ProcessGitHubContext,
|
||||
SetupKubeConfig,
|
||||
ValidateWerfVersion
|
||||
} from './common'
|
||||
import {PrepareEnvironAndRunWerfCommand} from './common'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
ProcessGitHubContext()
|
||||
|
||||
const kubeConfigBase64Data = core.getInput('kube-config-base64-data')
|
||||
if (kubeConfigBase64Data !== '') {
|
||||
SetupKubeConfig(kubeConfigBase64Data)
|
||||
}
|
||||
|
||||
const m = new Manager()
|
||||
await m.Install()
|
||||
|
||||
const versionOutput = await m.GetOutput(['version'])
|
||||
ValidateWerfVersion(versionOutput)
|
||||
|
||||
process.env.GITHUB_TOKEN =
|
||||
process.env.GITHUB_TOKEN || core.getInput('github-token')
|
||||
await m.PerformCIEnv()
|
||||
|
||||
await m.Exec(['build-and-publish'])
|
||||
await PrepareEnvironAndRunWerfCommand(['build-and-publish'])
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
@@ -1,30 +1,9 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Manager} from './manager'
|
||||
import {
|
||||
ProcessGitHubContext,
|
||||
SetupKubeConfig,
|
||||
ValidateWerfVersion
|
||||
} from './common'
|
||||
import {PrepareEnvironAndRunWerfCommand} from './common'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
ProcessGitHubContext()
|
||||
|
||||
const kubeConfigBase64Data = core.getInput('kube-config-base64-data')
|
||||
if (kubeConfigBase64Data !== '') {
|
||||
SetupKubeConfig(kubeConfigBase64Data)
|
||||
}
|
||||
|
||||
const m = new Manager()
|
||||
await m.Install()
|
||||
|
||||
const versionOutput = await m.GetOutput(['version'])
|
||||
ValidateWerfVersion(versionOutput)
|
||||
|
||||
process.env.GITHUB_TOKEN = core.getInput('github-token')
|
||||
await m.PerformCIEnv()
|
||||
|
||||
await m.Exec(['cleanup'])
|
||||
await PrepareEnvironAndRunWerfCommand(['cleanup'])
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
@@ -4,9 +4,37 @@ import * as fs from 'fs'
|
||||
import * as semver from 'semver'
|
||||
import {context} from '@actions/github'
|
||||
import {String} from 'typescript-string-operations'
|
||||
import {Manager} from './manager'
|
||||
|
||||
const minimalWerfVersion = 'v1.1.17'
|
||||
|
||||
export async function PrepareEnvironAndRunWerfCommand(
|
||||
args: string[]
|
||||
): Promise<void> {
|
||||
try {
|
||||
ProcessGitHubContext()
|
||||
|
||||
const kubeConfigBase64Data = core.getInput('kube-config-base64-data')
|
||||
if (kubeConfigBase64Data !== '') {
|
||||
SetupKubeConfig(kubeConfigBase64Data)
|
||||
}
|
||||
|
||||
const m = new Manager()
|
||||
await m.Install()
|
||||
|
||||
const versionOutput = await m.GetOutput(['version'])
|
||||
ValidateWerfVersion(versionOutput)
|
||||
|
||||
process.env.GITHUB_TOKEN =
|
||||
process.env.GITHUB_TOKEN || core.getInput('github-token')
|
||||
await m.PerformCIEnv()
|
||||
|
||||
await m.Exec(args)
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
}
|
||||
|
||||
export async function SetupKubeConfig(
|
||||
kubeConfigBase64Data: string
|
||||
): Promise<void> {
|
||||
|
||||
@@ -1,32 +1,10 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Manager} from './manager'
|
||||
import {
|
||||
ProcessGitHubContext,
|
||||
SetupKubeConfig,
|
||||
ValidateWerfVersion
|
||||
} from './common'
|
||||
import {PrepareEnvironAndRunWerfCommand} from './common'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
ProcessGitHubContext()
|
||||
|
||||
const kubeConfigBase64Data = core.getInput('kube-config-base64-data')
|
||||
if (kubeConfigBase64Data !== '') {
|
||||
SetupKubeConfig(kubeConfigBase64Data)
|
||||
}
|
||||
|
||||
const m = new Manager()
|
||||
await m.Install()
|
||||
|
||||
const versionOutput = await m.GetOutput(['version'])
|
||||
ValidateWerfVersion(versionOutput)
|
||||
|
||||
process.env.GITHUB_TOKEN =
|
||||
process.env.GITHUB_TOKEN || core.getInput('github-token')
|
||||
await m.PerformCIEnv()
|
||||
|
||||
process.env.WERF_ENV = core.getInput('env')
|
||||
await m.Exec(['converge'])
|
||||
await PrepareEnvironAndRunWerfCommand(['converge'])
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
@@ -1,32 +1,10 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Manager} from './manager'
|
||||
import {
|
||||
ProcessGitHubContext,
|
||||
SetupKubeConfig,
|
||||
ValidateWerfVersion
|
||||
} from './common'
|
||||
import {PrepareEnvironAndRunWerfCommand} from './common'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
ProcessGitHubContext()
|
||||
|
||||
const kubeConfigBase64Data = core.getInput('kube-config-base64-data')
|
||||
if (kubeConfigBase64Data !== '') {
|
||||
SetupKubeConfig(kubeConfigBase64Data)
|
||||
}
|
||||
|
||||
const m = new Manager()
|
||||
await m.Install()
|
||||
|
||||
const versionOutput = await m.GetOutput(['version'])
|
||||
ValidateWerfVersion(versionOutput)
|
||||
|
||||
process.env.GITHUB_TOKEN =
|
||||
process.env.GITHUB_TOKEN || core.getInput('github-token')
|
||||
await m.PerformCIEnv()
|
||||
|
||||
process.env.WERF_ENV = core.getInput('env')
|
||||
await m.Exec(['deploy'])
|
||||
await PrepareEnvironAndRunWerfCommand(['deploy'])
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
@@ -1,32 +1,10 @@
|
||||
import * as core from '@actions/core'
|
||||
import {Manager} from './manager'
|
||||
import {
|
||||
ProcessGitHubContext,
|
||||
SetupKubeConfig,
|
||||
ValidateWerfVersion
|
||||
} from './common'
|
||||
import {PrepareEnvironAndRunWerfCommand} from './common'
|
||||
|
||||
async function run(): Promise<void> {
|
||||
try {
|
||||
ProcessGitHubContext()
|
||||
|
||||
const kubeConfigBase64Data = core.getInput('kube-config-base64-data')
|
||||
if (kubeConfigBase64Data !== '') {
|
||||
SetupKubeConfig(kubeConfigBase64Data)
|
||||
}
|
||||
|
||||
const m = new Manager()
|
||||
await m.Install()
|
||||
|
||||
const versionOutput = await m.GetOutput(['version'])
|
||||
ValidateWerfVersion(versionOutput)
|
||||
|
||||
process.env.GITHUB_TOKEN =
|
||||
process.env.GITHUB_TOKEN || core.getInput('github-token')
|
||||
await m.PerformCIEnv()
|
||||
|
||||
process.env.WERF_ENV = core.getInput('env')
|
||||
await m.Exec(['dismiss'])
|
||||
await PrepareEnvironAndRunWerfCommand(['dismiss'])
|
||||
} catch (error) {
|
||||
core.setFailed(error.message)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user