Skip to content

Commit

Permalink
Merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedpair committed Oct 21, 2022
2 parents 9599666 + d23d55e commit bbf6e12
Show file tree
Hide file tree
Showing 190 changed files with 5,715 additions and 5,492 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/push-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-20.04, macos-latest, windows-latest ]
os:
- ubuntu-18.04
- ubuntu-20.04
- ubuntu-latest
- macos-latest
- windows-2019
- windows-latest
steps:
- uses: actions/checkout@main
- uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '12.x'
# Use the minimum supported mabl-cli Node.js LTS version here
node-version: '14.x'

- name: Install dependencies
run: npm ci
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
steps:
- uses: actions/setup-node@v2
with:
node-version: '12.x'
node-version: '16.x'
- uses: mablhq/setup-mabl-cli@v1
with:
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
steps:
- uses: actions/setup-node@v2
with:
node-version: '12.x'
node-version: '16.x'
- uses: mablhq/setup-mabl-cli@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ inputs:
description: (optional) The id of the workspace to configure as default for the CLI
required: false
runs:
using: "node12"
using: "node16"
main: "lib/index.js"
167 changes: 80 additions & 87 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
Expand All @@ -18,102 +22,91 @@ var __importStar = (this && this.__importStar) || function (mod) {
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const exec = __importStar(require("@actions/exec"));
const toolCache = __importStar(require("@actions/tool-cache"));
function run() {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const version = core.getInput('version', { required: false });
// Allow new or old syntax - some docs said 'workspace', others said 'workspace_id'
const workspaceId = (_b = (_a = core.getInput('workspace', { required: false })) !== null && _a !== void 0 ? _a : core.getInput('workspace_id', { required: false })) !== null && _b !== void 0 ? _b : core.getInput('workspace-id', { required: false }); // dash case is used by GitHub produced Actions
const apiKey = process.env.MABL_API_KEY;
const nodePath = yield findNode();
if (!nodePath) {
const REQUIRED_NODEJS_MAJOR_VERSION = 14;
async function run() {
const version = core.getInput('version', { required: false });
// Allow new or old syntax - some docs said 'workspace', others said 'workspace_id'
const workspaceId = core.getInput('workspace', { required: false }) ??
core.getInput('workspace_id', { required: false }) ??
core.getInput('workspace-id', { required: false }); // dash case is used by GitHub produced Actions
const apiKey = process.env.MABL_API_KEY;
const nodePath = await findNode();
if (!nodePath) {
return;
}
await installCli(nodePath, version);
if (apiKey) {
if (!(await authenticateWithApiKey(apiKey, nodePath))) {
return;
}
yield installCli(nodePath, version);
if (apiKey) {
if (!(yield authenticateWithApiKey(apiKey, nodePath))) {
return;
}
}
if (workspaceId) {
if (!apiKey) {
core.setFailed('Please specify api key as an environment variable');
return;
}
yield configureWorkspace(workspaceId, nodePath);
}
if (workspaceId) {
if (!apiKey) {
core.setFailed('Please specify api key as an environment variable');
return;
}
});
await configureWorkspace(workspaceId, nodePath);
}
}
function installCli(nodePath, version) {
return __awaiter(this, void 0, void 0, function* () {
const binPrefix = process.platform === 'win32' ? '' : 'bin/';
// --unsafe is required if the installation process needs to build keytar using node-gyp.
// There may be no pre-built binaries for keytar on the host OS. Currently this is the case only
// for linux.
const unsafeFlag = process.platform === 'linux' ? ' --unsafe' : '';
const installCommand = `./${binPrefix}npm install -g @mablhq/mabl-cli${version ? '@' + version : ''}${unsafeFlag}`;
const options = {
cwd: nodePath,
};
return exec.exec(installCommand, [], options);
});
async function installCli(nodePath, version) {
const binPrefix = process.platform === 'win32' ? '' : 'bin/';
// --unsafe is required if the installation process needs to build keytar using node-gyp.
// There may be no pre-built binaries for keytar on the host OS. Currently this is the case only
// for linux.
const unsafeFlag = process.platform === 'linux' ? ' --unsafe' : '';
const installCommand = `./${binPrefix}npm install -g @mablhq/mabl-cli${version ? '@' + version : ''}${unsafeFlag}`;
const options = {
cwd: nodePath,
};
return exec.exec(installCommand, [], options);
}
function configureWorkspace(workspace, nodePath) {
return __awaiter(this, void 0, void 0, function* () {
const options = {
cwd: nodePath,
};
try {
yield exec.exec(`mabl config set workspace ${workspace}`, [], options);
}
catch (error) {
core.setFailed(`Failed while trying to configure workspace with error ${error}`);
return false;
}
yield exec.exec(`mabl config list`, [], options);
return true;
});
async function configureWorkspace(workspace, nodePath) {
const options = {
cwd: nodePath,
};
try {
await exec.exec(`mabl config set workspace ${workspace}`, [], options);
}
catch (error) {
core.setFailed(`Failed while trying to configure workspace with error ${error}`);
return false;
}
await exec.exec(`mabl config list`, [], options);
return true;
}
function findNode() {
return __awaiter(this, void 0, void 0, function* () {
const allNodeVersions = yield toolCache.findAllVersions('node');
if (!(allNodeVersions && allNodeVersions[0])) {
core.setFailed('No node version installed. Please add a "actions/setup-node" step to your workflow or install a node version some other way.');
return;
}
const nodeVersion = allNodeVersions[0];
core.info(`Found node version ${nodeVersion}. Installing mabl CLI`);
return toolCache.find('node', nodeVersion);
});
async function findNode() {
const allNodeVersions = await toolCache.findAllVersions('node');
const nodeTargetVersion = allNodeVersions
.filter((version) => version.startsWith(`${REQUIRED_NODEJS_MAJOR_VERSION}.`))?.[0];
// If Node is installed, but the required version isn't, mark as a failure
if (allNodeVersions && allNodeVersions.length > 0 && !nodeTargetVersion) {
core.warning(`Could not find required Node.js version ${REQUIRED_NODEJS_MAJOR_VERSION}.x installed. This install will fallback to an unsupported version which may not function correctly.`);
}
const nodeVersion = nodeTargetVersion ?? allNodeVersions[0];
if (!(allNodeVersions && nodeVersion)) {
core.setFailed('No Node.js version installed. Please add a "actions/setup-node" step to your workflow or install a Node.js version some other way.');
return;
}
core.info(`Found node version ${nodeVersion}. Installing mabl CLI`);
return toolCache.find('node', nodeVersion);
}
function authenticateWithApiKey(apiKey, nodePath) {
return __awaiter(this, void 0, void 0, function* () {
const options = {
cwd: nodePath,
};
const command = `mabl auth activate-key ${apiKey}`;
try {
yield exec.exec(command, [], options);
}
catch (err) {
core.setFailed(`Failed while trying to activate API key with error ${err}`);
return false;
}
yield exec.exec('mabl auth info', [], options);
return true;
});
async function authenticateWithApiKey(apiKey, nodePath) {
const options = {
cwd: nodePath,
};
const command = `mabl auth activate-key ${apiKey}`;
try {
await exec.exec(command, [], options);
}
catch (err) {
core.setFailed(`Failed while trying to activate API key with error ${err}`);
return false;
}
await exec.exec('mabl auth info', [], options);
return true;
}
run();
Loading

0 comments on commit bbf6e12

Please sign in to comment.