From f157d8c73194005bc41a0b057a4b7273b4775d46 Mon Sep 17 00:00:00 2001 From: James Ives Date: Thu, 7 Nov 2019 18:36:38 -0500 Subject: [PATCH] linting --- src/constants.ts | 20 +++++++++---------- src/git.ts | 50 ++++++++++++++++++++++++------------------------ src/main.ts | 6 +++--- src/util.ts | 8 ++++---- 4 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 42cb7a06..2558705d 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,21 +1,21 @@ -import * as core from '@actions/core'; -import * as github from '@actions/github'; +import * as core from "@actions/core"; +import * as github from "@actions/github"; -const {pusher, repository} = github.context.payload; +const { pusher, repository } = github.context.payload; export const workspace: any = process.env.GITHUB_WORKSPACE; // The build folder that stores the deployment data. -export const build = core.getInput('FOLDER', {required: true}); +export const build = core.getInput("FOLDER", { required: true }); // Required action data. export const action = { - gitHubRepository: repository ? repository.full_name : '', - gitHubToken: core.getInput('GITHUB_TOKEN'), - accessToken: core.getInput('ACCESS_TOKEN'), - branch: core.getInput('BRANCH'), - baseBranch: core.getInput('BASE_BRANCH') || 'master', - pusher, + gitHubRepository: repository ? repository.full_name : "", + gitHubToken: core.getInput("GITHUB_TOKEN"), + accessToken: core.getInput("ACCESS_TOKEN"), + branch: core.getInput("BRANCH"), + baseBranch: core.getInput("BASE_BRANCH") || "master", + pusher }; // Repository path used for commits/pushes. diff --git a/src/git.ts b/src/git.ts index 60fb4cae..72b102c9 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1,25 +1,25 @@ -import * as core from '@actions/core'; -import {cp} from '@actions/io'; -import {execute} from './util'; -import {workspace, build, action, repositoryPath} from './constants'; +import * as core from "@actions/core"; +import { cp } from "@actions/io"; +import { execute } from "./util"; +import { workspace, build, action, repositoryPath } from "./constants"; /** Generates the branch if it doesn't exist on the remote. * @returns {Promise} */ export async function init(): Promise { try { - const accessToken = core.getInput('ACCESS_TOKEN'); - const gitHubToken = core.getInput('GITHUB_TOKEN'); + const accessToken = core.getInput("ACCESS_TOKEN"); + const gitHubToken = core.getInput("GITHUB_TOKEN"); if (!accessToken && !gitHubToken) { core.setFailed( - 'You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy.', + "You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy." ); } - if (build.startsWith('/') || build.startsWith('./')) { + if (build.startsWith("/") || build.startsWith("./")) { core.setFailed( - `The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`, + `The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.` ); } @@ -29,7 +29,7 @@ export async function init(): Promise { } catch (error) { core.setFailed(`There was an error initializing the repository: ${error}`); } finally { - Promise.resolve('Initializion step complete...'); + Promise.resolve("Initializion step complete..."); } } @@ -39,20 +39,20 @@ export async function init(): Promise { export async function generateBranch(): Promise { try { console.log(`Creating ${action.branch} branch...`); - await execute(`git checkout ${action.baseBranch || 'master'}`, workspace); + await execute(`git checkout ${action.baseBranch || "master"}`, workspace); await execute(`git checkout --orphan ${action.branch}`, workspace); await execute(`git reset --hard`, workspace); await execute( `git commit --allow-empty -m "Initial ${action.branch} commit."`, - workspace, + workspace ); await execute(`git push ${repositoryPath} ${action.branch}`, workspace); } catch (error) { core.setFailed( - `There was an error creating the deployment branch: ${error}`, + `There was an error creating the deployment branch: ${error}` ); } finally { - Promise.resolve('Deployment branch creation step complete...'); + Promise.resolve("Deployment branch creation step complete..."); } } @@ -60,8 +60,8 @@ export async function generateBranch(): Promise { * @returns {Promise} */ export async function deploy(): Promise { - const temporaryDeploymentDirectory = 'temp-deployment-folder'; - const temporaryDeploymentBranch = 'temp-deployment-branch'; + const temporaryDeploymentDirectory = "temp-deployment-folder"; + const temporaryDeploymentBranch = "temp-deployment-branch"; /* Checks to see if the remote exists prior to deploying. @@ -69,19 +69,19 @@ export async function deploy(): Promise { */ const branchExists = await execute( `git ls-remote --heads ${repositoryPath} ${action.branch} | wc -l`, - workspace, + workspace ); if (!branchExists) { - console.log('Deployment branch does not exist. Creating....'); + console.log("Deployment branch does not exist. Creating...."); await generateBranch(); } // Checks out the base branch to begin the deployment process. - await execute(`git checkout ${action.baseBranch || 'master'}`, workspace); + await execute(`git checkout ${action.baseBranch || "master"}`, workspace); await execute(`git fetch origin`, workspace); await execute( `git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`, - workspace, + workspace ); /* @@ -89,23 +89,23 @@ export async function deploy(): Promise { Allows the user to specify the root if '.' is provided. */ await cp(`${build}/.`, temporaryDeploymentDirectory, { recursive: true, - force: true, + force: true }); // Commits to GitHub. await execute(`git add --all .`, temporaryDeploymentDirectory); await execute( `git checkout -b ${temporaryDeploymentBranch}`, - temporaryDeploymentDirectory, + temporaryDeploymentDirectory ); await execute( `git commit -m "Deploying to ${action.branch} from ${action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, - temporaryDeploymentDirectory, + temporaryDeploymentDirectory ); await execute( `git push ${repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, - temporaryDeploymentDirectory, + temporaryDeploymentDirectory ); - Promise.resolve('Commit step complete...'); + Promise.resolve("Commit step complete..."); } diff --git a/src/main.ts b/src/main.ts index 065ebc08..357a9715 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ -import * as core from '@actions/core'; -import {init, deploy} from './git'; +import * as core from "@actions/core"; +import { init, deploy } from "./git"; /** Initializes and runs the action. */ (async function() { @@ -10,6 +10,6 @@ import {init, deploy} from './git'; } catch (error) { core.setFailed(error.message); } finally { - console.log('Completed Deployment'); + console.log("Completed Deployment"); } })(); diff --git a/src/util.ts b/src/util.ts index ed37595c..a8fa2abd 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,4 +1,4 @@ -import {exec} from '@actions/exec'; +import { exec } from "@actions/exec"; /** Wrapper around the GitHub toolkit exec command which returns the output. * Also allows you to easily toggle the current working directory. @@ -7,15 +7,15 @@ import {exec} from '@actions/exec'; * @returns {Promise} - The output from the command. */ export async function execute(cmd: string, cwd: string): Promise { - let output = ''; + let output = ""; await exec(cmd, [], { cwd, listeners: { stdout: (data: Buffer) => { output += data.toString().trim(); - }, - }, + } + } }); return Promise.resolve(output);