Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first pass on config merging #3

Merged
merged 7 commits into from
May 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dump config file and print contents
  • Loading branch information
pirog committed May 5, 2023
commit e2b83ba7cb5300dba5a05166f75ce91ff2a40d05
31 changes: 31 additions & 0 deletions lib/get-gcf-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const path = require('path');

const getOClifBase = () => {
const base = process.env['XDG_CACHE_HOME'] ||
(process.platform === 'win32' && process.env.LOCALAPPDATA) ||
path.join(getOClifHome(), '.config');
return path.join(base, 'lando');
};

const getOClifHome = () => {
switch (process.platform) {
case 'darwin':
case 'linux':
return process.env.HOME || os.homedir() || os.tmpdir();
case 'win32':
return process.env.HOME ||
(process.env.HOMEDRIVE && process.env.HOMEPATH && path.join(process.env.HOMEDRIVE, process.env.HOMEPATH)) ||
process.env.USERPROFILE ||
os.homedir() ||
os.tmpdir();
}
};

module.exports = (mlv = 3) => {
// if this is lando 3 then
if (mlv === 3) return path.join(getOClifHome, '.lando', 'config.yml');
// otherwise we assume lando 4
return path.join(getOClifBase(), 'config.yaml');
};
51 changes: 22 additions & 29 deletions setup-lando.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ const os = require('os');
const path = require('path');
const set = require('lodash.set');
const tc = require('@actions/tool-cache');
const yaml = require('js-yaml');

const {execSync} = require('child_process');
const {GitHub, getOctokitOptions} = require('@actions/github/lib/utils');
const {paginateRest} = require('@octokit/plugin-paginate-rest');

const getConfigFile = require('./lib/get-config-file');
const getDownloadUrl = require('./lib/get-download-url');
const getGCFPath = require('./lib/get-gcf-path');
const getInputs = require('./lib/get-inputs');
const getFileVersion = require('./lib/get-file-version');
const getObjectKeys = require('./lib/get-object-keys');
const resolveVersionSpec = require('./lib/resolve-version-spec');

// const sleep = ms => {
// return new Promise(res => setTimeout(res, ms));
// };

const main = async () => {
// start by getting the inputs
const inputs = getInputs();
Expand Down Expand Up @@ -100,37 +98,32 @@ const main = async () => {
core.addPath(toolDir);
core.setOutput('lando-path', landoPath);

// if we have any config then lets set that
if (inputs.configFile || inputs.config) {
// start with either the config file or an empty object
const config = getConfigFile(inputs.configFile) || {};
// if we have config then loop through that and set
if (inputs.config) {
inputs.config.forEach(line => {
const key = line.split('=')[0];
const value = line.split('=')[1];
set(config, key, value);
});
}

// set config info
core.startGroup('Configuration information');
getObjectKeys(config).forEach(key => core.info(`${key}: ${get(config, key)}`));
core.endGroup();
// start with either the config file or an empty object
const config = getConfigFile(inputs.configFile) || {};
// if we have config then loop through that and set
if (inputs.config) {
inputs.config.forEach(line => {
const key = line.split('=')[0];
const value = line.split('=')[1];
set(config, key, value);
});
}

// @TODO:
// determine lando config to set?
// load in file if set, warn if file does not exist
// merge multiline config over config
// set the config as needed, also set some sort of githubactions thing
// query the config again to make sure it is set?
// set config info
core.startGroup('Configuration information');
getObjectKeys(config).forEach(key => core.info(`${key}: ${get(config, key)}`));
core.endGroup();

// await io.mkdirP('path/to/make');
// write the config file to disk
const gcf = getGCFPath();
await io.mkdirP(path.dirname(gcf));
fs.writeFileSync(gcf, yaml.dump(config));

// get version
await exec.exec('lando', ['version']);
// get config if appropriate
// get config
await exec.exec('cat', [gcf]);

// catch unexpected
} catch (error) {
core.setFailed(error.message);
Expand Down