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

add dvc_version input for optionally installing DVC #93

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ This action gives you:
and on-premise computing resources for training models.
- The freedom 🦅 to mix and match CML with your favorite data science tools and
environments.

Note that CML does not include DVC and its dependencies (see the
[Setup DVC Action](https://github.com/iterative/setup-dvc)).
- Optional installation of DVC and its dependencies.

## Usage

Expand Down Expand Up @@ -63,6 +61,15 @@ steps:
sudo: false
```

Optional installation of DVC:
```yaml
steps:
- uses: actions/checkout@v3
- uses: iterative/setup-cml@v1
with:
dvc_version: latest
```

## Inputs

The following inputs are supported.
Expand All @@ -74,6 +81,9 @@ The following inputs are supported.
`true`
- `force` - (optional) Forces the install. Useful in scenarios where CML is
already installed and in use. Defaults to `false`
- `dvc_version` - (optional) Installs the specified version of DVC. By default
DVC will not be installed. `latest` can be used to install the most recent
DVC release.

## A complete example

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ inputs:
description: Force install CML if it exists.
default: false
required: false
dvc_version:
description: Optional version of DVC to install (eg. '3.0.0' or 'latest'). By default DVC will not be installed.
default: false
required: false
runs:
using: node16
main: dist/index.js
Expand Down
48 changes: 24 additions & 24 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion src/github-action.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const core = require('@actions/core');
const { setupCml } = require('./utils');
const { setupCml, setupDVC } = require('./utils');

(async () => {
try {
const version = core.getInput('version');
const sudo = core.getBooleanInput('sudo');
const force = core.getBooleanInput('force');
await setupCml({ version, sudo, force });
const dvcVersion = core.getInput('dvc_version');
await setupDVC({ dvcVersion });
} catch (error) {
core.setFailed(error.message);
}
Expand Down
90 changes: 90 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const setupCml = async opts => {
if (ver === 'latest') ver = await exec('npm show @dvcorg/cml version');
if (!force && cmlVer.includes(ver)) {
console.log(`CML ${version} is already installed. Nothing to do.`);
console.log(
await exec(`cml ci`)
);
return;
}
} catch (err) {}
Expand All @@ -58,7 +61,94 @@ const setupCml = async opts => {
}`
)
);

console.log(
await exec(`cml ci`)
);
};

const download = async (url, path) => {
const res = await fetch(url);
const fileStream = fs.createWriteStream(path);
await new Promise((resolve, reject) => {
if (res.status !== 200) return reject(new Error(res.statusText));
res.body.pipe(fileStream);
res.body.on('error', err => {
reject(err);
});
fileStream.on('finish', function() {
resolve();
});
});
};

const getLatestVersion = async () => {
const endpoint = 'https://updater.dvc.org';
const response = await fetch(endpoint, { method: 'GET' });
const { version } = await response.json();

return version;
};

const setupDVC = async opts => {
const { platform } = process;
let { version = '' } = opts;
if (!version) return;

if (version === 'latest') {
version = await getLatestVersion();
}

if (platform === 'linux') {
let sudo = '';
try {
sudo = await exec('which sudo');
} catch (err) {}
try {
const dvcURL = `https://dvc.org/download/linux-deb/dvc-${version}`;
console.log(`Installing DVC from: ${dvcURL}`);
await download(dvcURL, 'dvc.deb');
} catch (err) {
console.log('DVC Download Failed, trying from GitHub Releases');
const dvcURL = `https://github.com/iterative/dvc/releases/download/${version}/dvc_${version}_amd64.deb`;
console.log(`Installing DVC from: ${dvcURL}`);
await download(dvcURL, 'dvc.deb');
}
console.log(
await exec(
`${sudo} apt update && ${sudo} apt install -y --allow-downgrades git ./dvc.deb && ${sudo} rm -f 'dvc.deb'`
)
);
}

if (platform === 'darwin') {
try {
const dvcURL = `https://dvc.org/download/osx/dvc-${version}`;
console.log(`Installing DVC from: ${dvcURL}`);
await download(dvcURL, 'dvc.pkg');
} catch (err) {
console.log('DVC Download Failed, trying from GitHub Releases');
const dvcURL = `https://github.com/iterative/dvc/releases/download/${version}/dvc-${version}.pkg`;
console.log(`Installing DVC from: ${dvcURL}`);
await download(dvcURL, 'dvc.pkg');
}
console.log(
await exec(`sudo installer -pkg "dvc.pkg" -target / && rm -f "dvc.pkg"`)
);
}

if (platform === 'win32') {
console.log('Installing DVC with pip');
console.log(
await exec(
`pip install --upgrade dvc[all]${
version !== 'latest' ? `==${version}` : ''
}`
)
);
}
};

exports.exec = exec;
exports.setupCml = setupCml;
exports.setupDVC = setupDVC;