const core = require('@actions/core'); const { mkdir, writeFileSync, existsSync } = require('fs'); const os = require('os'); const path = require('path'); try { // `who-to-greet` input defined in action metadata file const kubeconfig = core.getInput('kubeconfig'); if(!kubeconfig){ throw { message: "kubeconfig should not be empty" } } const parentDir = path.join(os.homedir(),".kube") mkdir(parentDir,{recursive:true}) const configFile = path.join(parentDir,"config") if(existsSync(configFile) && !core.getBooleanInput("force")){ throw { message:".kube/config exists" } } writeFileSync(configFile,kubeconfig) core.info(`save kubeconfig to ${configFile}`); } catch (error) { core.setFailed(error.message); }