Skip to content

Commit

Permalink
Merge pull request #2 from imbsky/format
Browse files Browse the repository at this point in the history
Format everything
  • Loading branch information
vic authored Dec 26, 2019
2 parents 90e34f3 + 2cafc92 commit 6db718d
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 62 deletions.
10 changes: 4 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

Features

* Add `asdf-vm/actions/install`
- Add `asdf-vm/actions/install`

Action for installing your plugins and tool-versions.

* Add `asdf-vm/actions/plugin-test`
- Add `asdf-vm/actions/plugin-test`

Action for testing new asdf plugins.

* Add `asdf-vm/actions/plugin-add`
- Add `asdf-vm/actions/plugin-add`

Lower lever action for installing the plugins from official repos.

* Add `asdf-vm/actions/setup`
- Add `asdf-vm/actions/setup`

Lower level action for installing asdf itself.


8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This repo provides a collection of asdf related actions for use in your workflow

These two actions are probaly the most useful:

* `asdf-vm/actions/install` - Install your `.tool-versions` plugins and tools.
- `asdf-vm/actions/install` - Install your `.tool-versions` plugins and tools.

```yaml
steps:
Expand All @@ -16,7 +16,7 @@ These two actions are probaly the most useful:
See [action.yml](install/action.yml) inputs.
* `asdf-vm/actions/plugin-test` - Test your shiny new asdf plugin.
- `asdf-vm/actions/plugin-test` - Test your shiny new asdf plugin.

```yaml
steps:
Expand All @@ -35,10 +35,10 @@ These two actions are probaly the most useful:
These actions are used internally by the above ones. And you wont need
to use them directly, unless you actually want ;)

* `asdf-vm/actions/plugins-add` - Only install plugins, not tool versions.
- `asdf-vm/actions/plugins-add` - Only install plugins, not tool versions.

See [action.yml](plugins-add/action.yml) inputs.

* `asdf-vm/actions/setup` - Just installs asdf itself.
- `asdf-vm/actions/setup` - Just installs asdf itself.

See [action.yml](setup/action.yml) inputs.
10 changes: 5 additions & 5 deletions install/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'AsdfInstall'
description: 'Install your versioned tools with asdf'
author: 'Victor Borja <vborja@apache.org>'
name: "AsdfInstall"
description: "Install your versioned tools with asdf"
author: "Victor Borja <vborja@apache.org>"
runs:
using: 'node12'
main: 'index.js'
using: "node12"
main: "index.js"
inputs:
tool_versions:
description: "If present, this value will be written to the .tool-versions file."
Expand Down
8 changes: 3 additions & 5 deletions lib/install/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as path from "path";
import pluginsAdd from "../plugins-add";


const toolsInstall = async () => {
await pluginsAdd();

const before = core.getInput("before_install", {required: false});
const before = core.getInput("before_install", { required: false });
if (before) {
await exec.exec('bash', ['-c', before]);
await exec.exec("bash", ["-c", before]);
}
await exec.exec('asdf', ['install']);
await exec.exec("asdf", ["install"]);
};

export default toolsInstall;
32 changes: 21 additions & 11 deletions lib/plugin-test/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as path from "path";
import setupAsdf from "../setup";


const pluginTest = async () => {
await setupAsdf();
const command = core.getInput("command", {required: true});
const version = core.getInput("version", {required: true});
const plugin = (core.getInput("plugin", {required: false}) || process.env.GITHUB_REPOSITORY.split('/')[1]).replace('asdf-', '');
const giturl = (core.getInput("giturl", {required: false}) || `https://github.com/${process.env.GITHUB_REPOSITORY}`);
const gitref = (core.getInput("gitref", {required: false}) || process.env.GITHUB_SHA);
await exec.exec('asdf', [
'plugin-test',
plugin, giturl, '--asdf-tool-version', version, '--asdf-plugin-gitref', gitref, command
const command = core.getInput("command", { required: true });
const version = core.getInput("version", { required: true });
const plugin = (
core.getInput("plugin", { required: false }) ||
process.env.GITHUB_REPOSITORY.split("/")[1]
).replace("asdf-", "");
const giturl =
core.getInput("giturl", { required: false }) ||
`https://github.com/${process.env.GITHUB_REPOSITORY}`;
const gitref =
core.getInput("gitref", { required: false }) || process.env.GITHUB_SHA;
await exec.exec("asdf", [
"plugin-test",
plugin,
giturl,
"--asdf-tool-version",
version,
"--asdf-plugin-gitref",
gitref,
command
]);
};

const pluginTestAll = async () => {
core.startGroup('Test plugin');
core.startGroup("Test plugin");
await pluginTest();
core.endGroup();
};
Expand Down
22 changes: 10 additions & 12 deletions lib/plugins-add/index.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import * as core from "@actions/core";
import * as io from "@actions/io";
import * as exec from "@actions/exec";
import * as path from "path";
import {promises as fs} from 'fs';
import { promises as fs } from "fs";
import setupAsdf from "../setup";

const pluginsAdd = async () => {
await setupAsdf();
let tool_versions = core.getInput("tool_versions", {required: false});
let tool_versions = core.getInput("tool_versions", { required: false });

if (tool_versions) {
await fs.writeFile(".tool-versions", tool_versions, {encoding: 'utf8'});
await fs.writeFile(".tool-versions", tool_versions, { encoding: "utf8" });
} else {
tool_versions = await fs.readFile(".tool-versions", {encoding: 'utf8'});
tool_versions = await fs.readFile(".tool-versions", { encoding: "utf8" });
}

const pluginNames =
tool_versions.split("\n")
.map(x => x.replace(/#.*/, '').trim())
.filter(x => x.length > 0)
.map(x => x.split(' ')[0]);
const pluginNames = tool_versions
.split("\n")
.map(x => x.replace(/#.*/, "").trim())
.filter(x => x.length > 0)
.map(x => x.split(" ")[0]);

await pluginNames.reduce(async (promise, pluginName) => {
await promise;
return exec.exec('asdf', ["plugin-add", pluginName]);
return exec.exec("asdf", ["plugin-add", pluginName]);
}, Promise.resolve());
};

Expand Down
14 changes: 10 additions & 4 deletions lib/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ import * as io from "@actions/io";
import * as path from "path";

const setupAsdf = async () => {
const asdfPath = await io.which('asdf', false);
if (asdfPath) { return; }
const asdfPath = await io.which("asdf", false);
if (asdfPath) {
return;
}
const asdfDir = path.join(process.env.HOME, ".asdf");
core.exportVariable("ASDF_DIR", asdfDir);
core.exportVariable("ASDF_DATA_DIR", asdfDir);
core.addPath(`${asdfDir}/bin`);
core.addPath(`${asdfDir}/shims`);
core.info(`Clonning asdf into ASDF_DIR: ${asdfDir}`);
const branch = core.getInput("asdf_branch", {required: true});
const branch = core.getInput("asdf_branch", { required: true });
await exec.exec("git", [
"clone", "--depth", "1", "--branch", branch,
"clone",
"--depth",
"1",
"--branch",
branch,
"https://github.com/asdf-vm/asdf.git",
asdfDir
]);
Expand Down
10 changes: 5 additions & 5 deletions plugin-test/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'TestPlugin'
description: 'Test your asdf plugin'
author: 'Victor Borja <vborja@apache.org>'
name: "TestPlugin"
description: "Test your asdf plugin"
author: "Victor Borja <vborja@apache.org>"
runs:
using: 'node12'
main: 'index.js'
using: "node12"
main: "index.js"
inputs:
command:
description: "Command used to test your plugin tool. Something with --version or --help"
Expand Down
10 changes: 5 additions & 5 deletions plugins-add/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'PluginsInstall'
description: 'Install the plugins listed on your .tool-versions file.'
author: 'Victor Borja <vborja@apache.org>'
name: "PluginsInstall"
description: "Install the plugins listed on your .tool-versions file."
author: "Victor Borja <vborja@apache.org>"
runs:
using: 'node12'
main: 'index.js'
using: "node12"
main: "index.js"
inputs:
asdf_branch:
description: "asdf branch to clone"
Expand Down
10 changes: 5 additions & 5 deletions setup/action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: 'Setup asdf'
description: 'Install tools versioned with asdf'
author: 'Victor Borja <vborja@apache.org>'
name: "Setup asdf"
description: "Install tools versioned with asdf"
author: "Victor Borja <vborja@apache.org>"
runs:
using: 'node12'
main: 'index.js'
using: "node12"
main: "index.js"
inputs:
asdf_branch:
description: "asdf branch to clone"
Expand Down

0 comments on commit 6db718d

Please sign in to comment.