mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Migrates to eslint (#193)
This commit is contained in:
parent
d25f74597f
commit
b2acf87217
62
.eslintrc.json
Normal file
62
.eslintrc.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/es6"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"globals": {
|
||||
"fetch": true
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-ignore": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/camelcase": "error",
|
||||
"@typescript-eslint/class-name-casing": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "off",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-object-literal-type-assertion": "error",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-interface": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"@typescript-eslint/unbound-method": "error",
|
||||
"no-console": "off"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
20
README.md
20
README.md
@ -19,12 +19,12 @@ jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v2 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly.
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Build and Deploy
|
||||
- name: Build and Deploy 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
@ -56,7 +56,7 @@ import run, {
|
||||
init,
|
||||
deploy,
|
||||
generateBranch,
|
||||
actionInterface
|
||||
ActionInterface
|
||||
} from "github-pages-deploy-action";
|
||||
```
|
||||
|
||||
@ -134,7 +134,7 @@ With this configured you must add the `ssh-agent` step to your workflow and set
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy
|
||||
- name: Build and Deploy 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
SSH: true
|
||||
@ -155,7 +155,7 @@ jobs:
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
@ -165,12 +165,12 @@ jobs:
|
||||
npm install
|
||||
npm run-script build
|
||||
|
||||
- name: Install SSH Client
|
||||
- name: Install SSH Client 🔑
|
||||
uses: webfactory/ssh-agent@v0.2.0 # This step installs the ssh client into the workflow run. There's many options available for this on the action marketplace.
|
||||
with:
|
||||
ssh-private-key: ${{ secrets.DEPLOY_KEY }}
|
||||
|
||||
- name: Build and Deploy Repo
|
||||
- name: Build and Deploy Repo 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3-test
|
||||
with:
|
||||
BASE_BRANCH: master
|
||||
@ -207,7 +207,7 @@ jobs:
|
||||
build:
|
||||
runs-on: windows-latest # The first job utilizes windows-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
@ -227,7 +227,7 @@ jobs:
|
||||
needs: [build] # The second job must depend on the first one to complete before running, and uses ubuntu-latest instead of windows.
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
- name: Checkout 🛎️
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
persist-credentials: false
|
||||
@ -237,7 +237,7 @@ jobs:
|
||||
with:
|
||||
name: site
|
||||
|
||||
- name: Build and Deploy
|
||||
- name: Build and Deploy 🚀
|
||||
uses: JamesIves/github-pages-deploy-action@releases/v3
|
||||
with:
|
||||
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
|
||||
|
@ -9,7 +9,7 @@
|
||||
"scripts": {
|
||||
"build": "rm -rf lib && tsc --declaration",
|
||||
"test": "jest",
|
||||
"lint": "tslint -p tsconfig.json --project '.' || (echo Project needs formatting)",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"format": "prettier --write './**/*.ts'"
|
||||
},
|
||||
"repository": {
|
||||
@ -44,7 +44,9 @@
|
||||
"jest-circus": "^25.1.0",
|
||||
"prettier": "^1.19.1",
|
||||
"ts-jest": "^25.0.0",
|
||||
"tslint": "^6.0.0",
|
||||
"eslint": "^5.16.0",
|
||||
"eslint-plugin-github": "^2.0.0",
|
||||
"eslint-plugin-jest": "^22.21.0",
|
||||
"typescript": "^3.7.4"
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import {isNullOrUndefined} from './util'
|
||||
const {pusher, repository} = github.context.payload
|
||||
|
||||
/* For more information please refer to the README: https://github.com/JamesIves/github-pages-deploy-action */
|
||||
export interface actionInterface {
|
||||
export interface ActionInterface {
|
||||
/** Deployment access token. */
|
||||
accessToken?: string | null
|
||||
/** The base branch that the deploy should be made from. */
|
||||
@ -15,7 +15,7 @@ export interface actionInterface {
|
||||
/** If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to true. */
|
||||
clean?: string | boolean
|
||||
/** If you need to use CLEAN but you'd like to preserve certain files or folders you can use this option. */
|
||||
cleanExclude?: string | Array<string>
|
||||
cleanExclude?: string | string[]
|
||||
/** If you need to customize the commit message for an integration you can do so. */
|
||||
commitMessage?: string
|
||||
/** Unhides the Git commands from the function terminal. */
|
||||
@ -49,7 +49,7 @@ export interface actionInterface {
|
||||
}
|
||||
|
||||
/* Required action data that gets initialized when running within the GitHub Actions environment. */
|
||||
export const action: actionInterface = {
|
||||
export const action: ActionInterface = {
|
||||
accessToken: getInput('ACCESS_TOKEN'),
|
||||
baseBranch: getInput('BASE_BRANCH'),
|
||||
folder: getInput('FOLDER'),
|
||||
|
@ -23,6 +23,6 @@ export async function execute(cmd: string, cwd: string): Promise<any> {
|
||||
return Promise.resolve(output)
|
||||
}
|
||||
|
||||
export function stdout(data: any) {
|
||||
export function stdout(data: any): string | void {
|
||||
output += data.toString().trim()
|
||||
}
|
||||
|
17
src/git.ts
17
src/git.ts
@ -1,4 +1,4 @@
|
||||
import {actionInterface} from './constants'
|
||||
import {ActionInterface} from './constants'
|
||||
import {execute} from './execute'
|
||||
import {
|
||||
hasRequiredParameters,
|
||||
@ -7,7 +7,7 @@ import {
|
||||
} from './util'
|
||||
|
||||
/* Initializes git in the workspace. */
|
||||
export async function init(action: actionInterface): Promise<void | Error> {
|
||||
export async function init(action: ActionInterface): Promise<void | Error> {
|
||||
try {
|
||||
hasRequiredParameters(action)
|
||||
|
||||
@ -37,7 +37,7 @@ export async function init(action: actionInterface): Promise<void | Error> {
|
||||
|
||||
/* Switches to the base branch. */
|
||||
export async function switchToBaseBranch(
|
||||
action: actionInterface
|
||||
action: ActionInterface
|
||||
): Promise<void> {
|
||||
try {
|
||||
hasRequiredParameters(action)
|
||||
@ -59,7 +59,7 @@ export async function switchToBaseBranch(
|
||||
}
|
||||
|
||||
/* Generates the branch if it doesn't exist on the remote. */
|
||||
export async function generateBranch(action: actionInterface): Promise<void> {
|
||||
export async function generateBranch(action: ActionInterface): Promise<void> {
|
||||
try {
|
||||
hasRequiredParameters(action)
|
||||
|
||||
@ -90,7 +90,7 @@ export async function generateBranch(action: actionInterface): Promise<void> {
|
||||
}
|
||||
|
||||
/* Runs the necessary steps to make the deployment. */
|
||||
export async function deploy(action: actionInterface): Promise<void> {
|
||||
export async function deploy(action: ActionInterface): Promise<void> {
|
||||
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder'
|
||||
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch'
|
||||
console.log('Starting to commit changes...')
|
||||
@ -127,9 +127,10 @@ export async function deploy(action: actionInterface): Promise<void> {
|
||||
typeof action.cleanExclude === 'string'
|
||||
? JSON.parse(action.cleanExclude)
|
||||
: action.cleanExclude
|
||||
excludedItems.forEach(
|
||||
(item: string) => (excludes += `--exclude ${item} `)
|
||||
)
|
||||
|
||||
for (const item of excludedItems) {
|
||||
excludes += `--exclude ${item} `
|
||||
}
|
||||
} catch {
|
||||
console.log(
|
||||
'There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌'
|
||||
|
@ -1,13 +1,13 @@
|
||||
import {exportVariable, setFailed} from '@actions/core'
|
||||
import {action, actionInterface} from './constants'
|
||||
import {action, ActionInterface} from './constants'
|
||||
import {deploy, generateBranch, init} from './git'
|
||||
import {generateRepositoryPath, generateTokenType} from './util'
|
||||
|
||||
/** Initializes and runs the action. */
|
||||
export default async function run(
|
||||
configuration: actionInterface
|
||||
configuration: ActionInterface
|
||||
): Promise<void> {
|
||||
let errorState: boolean = false
|
||||
let errorState = false
|
||||
|
||||
try {
|
||||
console.log('Checking configuration and starting deployment...🚦')
|
||||
@ -42,4 +42,4 @@ export default async function run(
|
||||
}
|
||||
}
|
||||
|
||||
export {init, deploy, generateBranch, actionInterface}
|
||||
export {init, deploy, generateBranch, ActionInterface}
|
||||
|
12
src/util.ts
12
src/util.ts
@ -1,12 +1,12 @@
|
||||
import {getInput} from '@actions/core'
|
||||
import {actionInterface} from './constants'
|
||||
import {ActionInterface} from './constants'
|
||||
|
||||
/* Utility function that checks to see if a value is undefined or not. */
|
||||
export const isNullOrUndefined = (value: any): boolean =>
|
||||
typeof value === 'undefined' || value === null || value === ''
|
||||
|
||||
/* Generates a token type used for the action. */
|
||||
export const generateTokenType = (action: actionInterface): string =>
|
||||
export const generateTokenType = (action: ActionInterface): string =>
|
||||
action.ssh
|
||||
? 'SSH Deploy Key'
|
||||
: action.accessToken
|
||||
@ -16,7 +16,7 @@ export const generateTokenType = (action: actionInterface): string =>
|
||||
: '...'
|
||||
|
||||
/* Generates a the repository path used to make the commits. */
|
||||
export const generateRepositoryPath = (action: actionInterface): string =>
|
||||
export const generateRepositoryPath = (action: ActionInterface): string =>
|
||||
action.ssh
|
||||
? `git@github.com:${action.repositoryName}`
|
||||
: `https://${action.accessToken ||
|
||||
@ -25,7 +25,7 @@ export const generateRepositoryPath = (action: actionInterface): string =>
|
||||
}.git`
|
||||
|
||||
/* Checks for the required tokens and formatting. Throws an error if any case is matched. */
|
||||
export const hasRequiredParameters = (action: actionInterface): void => {
|
||||
export const hasRequiredParameters = (action: ActionInterface): void => {
|
||||
if (
|
||||
(isNullOrUndefined(action.accessToken) &&
|
||||
isNullOrUndefined(action.gitHubToken) &&
|
||||
@ -55,8 +55,8 @@ export const hasRequiredParameters = (action: actionInterface): void => {
|
||||
/* Suppresses sensitive information from being exposed in error messages. */
|
||||
export const suppressSensitiveInformation = (
|
||||
str: string,
|
||||
action: actionInterface
|
||||
) => {
|
||||
action: ActionInterface
|
||||
): string => {
|
||||
let value = str
|
||||
|
||||
if (getInput('DEBUG')) {
|
||||
|
37
tslint.json
37
tslint.json
@ -1,37 +0,0 @@
|
||||
{
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": true,
|
||||
"ban-comma-operator": true,
|
||||
"no-namespace": true,
|
||||
"no-parameter-reassignment": true,
|
||||
"no-reference": true,
|
||||
"no-unnecessary-type-assertion": true,
|
||||
"label-position": true,
|
||||
"no-conditional-assignment": true,
|
||||
"no-construct": true,
|
||||
"no-duplicate-super": true,
|
||||
"no-duplicate-switch-case": true,
|
||||
"no-duplicate-variable": [true, "check-parameters"],
|
||||
"no-shadowed-variable": true,
|
||||
"no-empty": [true, "allow-empty-catch"],
|
||||
"no-floating-promises": false,
|
||||
"no-implicit-dependencies": true,
|
||||
"no-invalid-this": true,
|
||||
"no-string-throw": true,
|
||||
"no-unsafe-finally": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-void-expression": [true, "ignore-arrow-function-shorthand"],
|
||||
"no-duplicate-imports": true,
|
||||
"no-empty-interface": {"severity": "warning"},
|
||||
"no-import-side-effect": {"severity": "warning"},
|
||||
"no-var-keyword": {"severity": "warning"},
|
||||
"triple-equals": {"severity": "warning"},
|
||||
"deprecation": {"severity": "warning"},
|
||||
"prefer-for-of": {"severity": "warning"},
|
||||
"unified-signatures": {"severity": "warning"},
|
||||
"prefer-const": {"severity": "warning"},
|
||||
"trailing-comma": {"severity": "warning"}
|
||||
},
|
||||
|
||||
"defaultSeverity": "error"
|
||||
}
|
Loading…
Reference in New Issue
Block a user