Skip to content

Commit

Permalink
Merge pull request #7 from DopplerHQ/install-sh
Browse files Browse the repository at this point in the history
Install CLI via install.sh on Linux and Darwin
  • Loading branch information
Piccirello authored Nov 15, 2021
2 parents 3f09ae1 + 3469c16 commit 72db35b
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, ubuntu-16.04, macos-latest, windows-latest, windows-2016]
os: [ubuntu-latest, ubuntu-18.04, macos-latest, windows-latest, windows-2016]
name: Install the cli
steps:
- name: Checkout
Expand All @@ -15,4 +15,3 @@ jobs:
id: install
- name: Test CLI
run: doppler --version

37 changes: 20 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
const core = require('@actions/core');
const tc = require('@actions/tool-cache');
const io = require('@actions/io');
const { execSync } = require('child_process');

const workspace = process.env.GITHUB_WORKSPACE;
const binDir = `${workspace}/bin`;

try {
run();
} catch (error) {
run().catch(error => {
core.setFailed(error.message);
}
})

async function run() {
switch (process.platform) {
Expand All @@ -18,14 +17,9 @@ async function run() {
await installZip(binDir, url);
break;
}
case "linux": {
const url = "https://cli.doppler.com/download?os=linux&arch=amd64&format=tar";
await installTar(binDir, url);
break;
}
case "linux":
case "darwin": {
const url = "https://cli.doppler.com/download?os=macos&arch=amd64&format=tar";
await installTar(binDir, url);
await executeInstallSh(binDir)
break;
}
default: {
Expand All @@ -34,16 +28,25 @@ async function run() {
}
}

async function installTar(path, url) {
async function installZip(path, url) {
await io.mkdirP(path);
const downloadPath = await tc.downloadTool(url);
await tc.extractTar(downloadPath, path);
await tc.extractZip(downloadPath, path);
core.addPath(path);
}

async function installZip(path, url) {
await io.mkdirP(path);
async function executeInstallSh(installPath) {
// download script
const url = "https://cli.doppler.com/install.sh";
const downloadPath = await tc.downloadTool(url);
await tc.extractZip(downloadPath, path);
core.addPath(path);
execSync(`chmod +x ${downloadPath}`);

// execute script
await io.mkdirP(installPath);
const installCommand = `${downloadPath} --debug --no-package-manager --install-path ${installPath}`
stdout = execSync(installCommand, { timeout: 15000 });
console.log(Buffer.from(stdout).toString("utf-8"))

// add binary to PATH
core.addPath(installPath);
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cli-action",
"version": "1.0.1",
"version": "1.0.2",
"description": "GitHub Action to install the Doppler CLI",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 72db35b

Please sign in to comment.