Skip to content

Commit

Permalink
Merge branch 'fallback-neovim-stable' into master (fix #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Sep 8, 2020
2 parents 9807db6 + a63a9f8 commit bf797db
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 19 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- run: npm ci
- run: npm test
- name: Run unit tests
run: npm test
env:
GITHUB_TOKEN: ${{ github.token }}
- run: npm run lint
- uses: actions/setup-python@v1
- run: pip install yamllint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/test/*.js
/scripts/*.js
*.js.map
/env.sh
11 changes: 9 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ inputs:
required: false
default: 'stable'
neovim:
description: 'Setting to true will install Neovim.'
description: >
Setting to true will install Neovim.
required: false
default: false
token:
description: >
Personal access token. It is used for calling GitHub API. The API call happens when Neovim
asset is not found and needs to fallback.
default: ${{ github.token }}

outputs:
executable:
description: 'Absolute file path to the installed executable'
description: >
Absolute file path to the installed executable.
runs:
using: 'node12'
Expand Down
142 changes: 137 additions & 5 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"dependencies": {
"@actions/core": "^1.2.5",
"@actions/exec": "^1.0.4",
"@actions/github": "^4.0.0",
"@actions/io": "^1.0.2",
"node-fetch": "^2.6.1"
},
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface Config {
readonly version: string;
readonly neovim: boolean;
readonly os: Os;
readonly token: string | null;
}

function getBoolean(input: string, def: boolean): boolean {
Expand Down Expand Up @@ -67,5 +68,6 @@ export function loadConfigFromInputs(): Config {
version: getVersion(neovim),
neovim,
os: getOs(),
token: getInput('token') ?? null,
};
}
18 changes: 13 additions & 5 deletions src/install_linux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Installed } from './install';
import type { Config } from './config';
import { exec } from './shell';
import { buildVim } from './vim';
import { downloadNeovim } from './neovim';
import { downloadNeovim, downloadStableNeovim } from './neovim';

async function installVimStable(): Promise<Installed> {
core.debug('Installing stable Vim on Linux using apt');
Expand All @@ -25,20 +25,28 @@ async function installVim(ver: string | null): Promise<Installed> {
};
}

async function installNeovim(ver: string): Promise<Installed> {
core.debug(`Installing Neovim version '${ver}' on Linux`);
const nvimDir = await downloadNeovim(ver, 'linux');
function neovimInstalled(nvimDir: string): Installed {
return {
executable: 'nvim',
binDir: path.join(nvimDir, 'bin'),
};
}

async function installNeovim(ver: string): Promise<Installed> {
core.debug(`Installing Neovim version '${ver}' on Linux`);
return neovimInstalled(await downloadNeovim(ver, 'linux'));
}

async function installStableNeovim(token: string | null): Promise<Installed> {
core.debug(`Installing Neovim version 'stable' on Linux`);
return neovimInstalled(await downloadStableNeovim('linux', token));
}

export function install(config: Config): Promise<Installed> {
if (config.neovim) {
switch (config.version) {
case 'stable':
return installNeovim('stable');
return installStableNeovim(config.token);
case 'nightly':
return installNeovim('nightly');
default:
Expand Down
18 changes: 13 additions & 5 deletions src/install_windows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as core from '@actions/core';
import type { Installed } from './install';
import type { Config } from './config';
import { installNightlyVimOnWindows, installVimOnWindows } from './vim';
import { downloadNeovim } from './neovim';
import { downloadNeovim, downloadStableNeovim } from './neovim';

async function installVimNightly(): Promise<Installed> {
core.debug('Installing nightly Vim on Windows');
Expand All @@ -29,20 +29,28 @@ async function installVim(ver: string): Promise<Installed> {
};
}

async function installNeovim(ver: string): Promise<Installed> {
core.debug(`Installing Neovim version '${ver}' on Windows`);
const nvimDir = await downloadNeovim(ver, 'windows');
function neovimInstalled(nvimDir: string): Installed {
return {
executable: 'nvim.exe',
binDir: path.join(nvimDir, 'bin'),
};
}

async function installNeovim(ver: string): Promise<Installed> {
core.debug(`Installing Neovim version '${ver}' on Windows`);
return neovimInstalled(await downloadNeovim(ver, 'windows'));
}

async function installStableNeovim(token: string | null): Promise<Installed> {
core.debug(`Installing Neovim version 'stable' on Windows`);
return neovimInstalled(await downloadStableNeovim('windows', token));
}

export function install(config: Config): Promise<Installed> {
if (config.neovim) {
switch (config.version) {
case 'stable':
return installNeovim('stable');
return installStableNeovim(config.token);
case 'nightly':
return installNeovim('nightly');
default:
Expand Down
Loading

0 comments on commit bf797db

Please sign in to comment.