Skip to content

Commit

Permalink
Checkout remote config files prior to styles
Browse files Browse the repository at this point in the history
  • Loading branch information
jdkato committed Dec 3, 2019
1 parent 9a1298c commit a2e12a0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 78 deletions.
47 changes: 20 additions & 27 deletions lib/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,11 @@ const exec = __importStar(require("@actions/exec"));
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const request = __importStar(require("request-promise-native"));
/**
* These environment variables are exposed for GitHub Actions.
*
* See https://bit.ly/2WlFUD7 for more information.
*/
const { GITHUB_TOKEN, GITHUB_WORKSPACE } = process.env;
/**
* Parse our user input and set up our Vale environment.
*/
function get(tmp) {
function get(tmp, tok, dir) {
return __awaiter(this, void 0, void 0, function* () {
// Add Vale, as copied in Docker, to the `$PATH` for later use:
//
// NOTE: This *should* be done already by the container `jdkato/vale`.
core.addPath('/bin');
const userToken = GITHUB_TOKEN;
const workspace = GITHUB_WORKSPACE;
// Get the current version of Vale:
let version = '';
yield exec.exec('vale', ['-v'], {
Expand All @@ -46,19 +34,11 @@ function get(tmp) {
}
});
version = version.split(' ').slice(-1)[0];
// Install our user-specified styles:
const styles = core.getInput('styles').split('\n');
for (const style of styles) {
if (style !== '') {
const name = style.split('/').slice(-1)[0].split('.zip')[0];
core.info(`Installing style '${name}' ...`);
yield exec.exec('vale', ['install', name, style], {
cwd: workspace
});
}
}
let args = ['--no-exit', '--output=JSON'];
// Check if we were given an external config file:
// Check if we were given an external config file.
//
// NOTE: We need to do this first because we may not have a local config file
// to read the `StylesPath` from.
const config = core.getInput('config');
if (config !== '') {
core.info(`Downloading external config '${config}' ...`);
Expand All @@ -78,12 +58,25 @@ function get(tmp) {
}
});
}
// Install our user-specified styles:
const styles = core.getInput('styles').split('\n');
for (const style of styles) {
if (style !== '') {
const name = style.split('/').slice(-1)[0].split('.zip')[0];
core.info(`Installing style '${name}' ...`);
let cmd = ['install', name, style];
if (args.length > 2) {
cmd = args.concat(cmd);
}
yield exec.exec('vale', cmd, { cwd: dir });
}
}
// Figure out what we're supposed to lint:
const files = core.getInput('files');
if (files == 'all') {
args.push('.');
}
else if (fs.existsSync(path.resolve(workspace, files))) {
else if (fs.existsSync(path.resolve(dir, files))) {
args.push(files);
}
else {
Expand All @@ -92,7 +85,7 @@ function get(tmp) {
}
core.info(`Vale set-up comeplete; using '${args}'.`);
return {
token: userToken, workspace: workspace, args: args, version: version
token: tok, workspace: dir, args: args, version: version
};
});
}
Expand Down
14 changes: 10 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ const tmp = __importStar(require("tmp"));
const execa = require("execa");
const check_1 = require("./check");
const input = __importStar(require("./input"));
/**
* These environment variables are exposed for GitHub Actions.
*
* See https://bit.ly/2WlFUD7 for more information.
*/
const { GITHUB_TOKEN, GITHUB_WORKSPACE } = process.env;
function run(actionInput) {
return __awaiter(this, void 0, void 0, function* () {
const startedAt = new Date().toISOString();
Expand All @@ -43,12 +49,12 @@ exports.run = run;
function main() {
return __awaiter(this, void 0, void 0, function* () {
try {
// TODO: core.info('::add-matcher::vale.json');
const tmpobj = tmp.fileSync({ postfix: '.ini' });
const actionInput = yield input.get(tmpobj);
const userToken = GITHUB_TOKEN;
const workspace = GITHUB_WORKSPACE;
const tmpobj = tmp.fileSync({ postfix: '.ini', dir: workspace });
const actionInput = yield input.get(tmpobj, userToken, workspace);
yield run(actionInput);
tmpobj.removeCallback();
// TODO: core.info('::remove-matcher owner=vale::');
}
catch (error) {
core.setFailed(error.message);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vale-action",
"version": "1.0.0",
"version": "1.0.2",
"description": "The official GitHub Action for Vale -- install, manage, and run Vale with ease.",
"main": "lib/main.js",
"scripts": {
Expand Down
67 changes: 25 additions & 42 deletions src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@ import * as fs from 'fs';
import * as path from 'path';
import * as request from 'request-promise-native';

/**
* These environment variables are exposed for GitHub Actions.
*
* See https://bit.ly/2WlFUD7 for more information.
*/
const {
GITHUB_TOKEN,
GITHUB_WORKSPACE
} = process.env;


/**
* Our expected input.
*
Expand All @@ -26,24 +15,13 @@ const {
* @args are Vale's run-time arguments.
*/
export interface Input {
token: string,
workspace: string,
version: string,
args: string[]
token: string, workspace: string, version: string, args: string[]
}

/**
* Parse our user input and set up our Vale environment.
*/
export async function get(tmp: any): Promise<Input> {
// Add Vale, as copied in Docker, to the `$PATH` for later use:
//
// NOTE: This *should* be done already by the container `jdkato/vale`.
core.addPath('/bin');

const userToken = GITHUB_TOKEN as string;
const workspace = GITHUB_WORKSPACE as string;

export async function get(tmp: any, tok: string, dir: string): Promise<Input> {
// Get the current version of Vale:
let version = '';
await exec.exec('vale', ['-v'], {
Expand All @@ -53,21 +31,11 @@ export async function get(tmp: any): Promise<Input> {
});
version = version.split(' ').slice(-1)[0];

// Install our user-specified styles:
const styles = core.getInput('styles').split('\n');
for (const style of styles) {
if (style !== '') {
const name = style.split('/').slice(-1)[0].split('.zip')[0];
core.info(`Installing style '${name}' ...`);
await exec.exec('vale', ['install', name, style], {
cwd: workspace
});
}
}

let args: string[] = ['--no-exit', '--output=JSON'];

// Check if we were given an external config file:
// Check if we were given an external config file.
//
// NOTE: We need to do this first because we may not have a local config file
// to read the `StylesPath` from.
const config = core.getInput('config');
if (config !== '') {
core.info(`Downloading external config '${config}' ...`);
Expand All @@ -87,20 +55,35 @@ export async function get(tmp: any): Promise<Input> {
});
}

// Install our user-specified styles:
const styles = core.getInput('styles').split('\n');
for (const style of styles) {
if (style !== '') {
const name = style.split('/').slice(-1)[0].split('.zip')[0];
core.info(`Installing style '${name}' ...`);

let cmd = ['install', name, style];
if (args.length > 2) {
cmd = args.concat(cmd);
}
await exec.exec('vale', cmd, {cwd: dir});
}
}

// Figure out what we're supposed to lint:
const files = core.getInput('files');
if (files == 'all') {
args.push('.');
} else if (fs.existsSync(path.resolve(workspace, files))) {
args.push(files)
} else if (fs.existsSync(path.resolve(dir, files))) {
args.push(files)
} else {
core.warning(
`User-specified path (${files}) doesn't exist; falling back to 'all'.`)
`User-specified path (${files}) doesn't exist; falling back to 'all'.`)
args.push('.');
}

core.info(`Vale set-up comeplete; using '${args}'.`);
return {
token: userToken, workspace: workspace, args: args, version: version
token: tok, workspace: dir, args: args, version: version
}
}
15 changes: 11 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ import execa = require('execa');
import {CheckRunner} from './check';
import * as input from './input';

/**
* These environment variables are exposed for GitHub Actions.
*
* See https://bit.ly/2WlFUD7 for more information.
*/
const {GITHUB_TOKEN, GITHUB_WORKSPACE} = process.env;

export async function run(actionInput: input.Input): Promise<void> {
const startedAt = new Date().toISOString();
const alertResp = await execa('vale', actionInput.args);
Expand All @@ -27,15 +34,15 @@ export async function run(actionInput: input.Input): Promise<void> {

async function main(): Promise<void> {
try {
// TODO: core.info('::add-matcher::vale.json');
const userToken = GITHUB_TOKEN as string;
const workspace = GITHUB_WORKSPACE as string;

const tmpobj = tmp.fileSync({postfix: '.ini'});
const actionInput = await input.get(tmpobj);
const tmpobj = tmp.fileSync({postfix: '.ini', dir: workspace});
const actionInput = await input.get(tmpobj, userToken, workspace);

await run(actionInput);

tmpobj.removeCallback();
// TODO: core.info('::remove-matcher owner=vale::');
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit a2e12a0

Please sign in to comment.