Tooling improvements (#34)

* feat: update tsconfig, uninstall vercel/ncc package and use tsc to build project

* feat: install 1password/front-end-style and configure Prettier

* feat: configure ESLint and fix lint errors

* build(deps): update types/node package to latest version

* feat: configure Jest

* feat: add 'validate' script to run formatting/linting/testing/building all together

* build: rebuild the dist/index.js file

* feat: make NPM scripts more granular

* refactor: make it clearer that Prettier config is being loaded from an existing dependency

* feat: add Husky and lint-staged to run pre-commit and pre-push checks

* fix: lint-staged testing step and Jest config file

* build(deps): update types/node package to latest version

* refactor: remove findrelated test script

* fix: move tsconfig.json to root directory, reinstall vercel/ncc for building

* fix: call to run function in index.ts

* build: rebuild the dist/index.js file

* fix: replace CommonJS __dirname with an ESModule equivalent

* fix: ignore config/.husky during ShellCheck

* fix: ignore .husky directory during ShellCheck

* fix: update lint.yml config to match ShellCheck README.md

* fix: remove coveragePathIgnorePatterns option from Jest config since node_modules is already the default value

* refactor: use './' prefix to refer to folders in the current directory in tsconfig.json

* fix: handle edge case where Error constructor is modified and add comments for context

* feat: bump package.json version to 1.2.0 to match current release

* fix: update lint.yml to use ShellCheck 2.0.0 exact version

* build(deps): update types/node package to latest version

* fix: update package-lock.json version 1.2.0

* feat: remove pre-commit and pre-push NPM scripts to simplify package.json

* fix: remove empty 'Default' column from 'configure Action Inputs' table

* fix: change the default values in action.yml to strings as per YAML validation
This commit is contained in:
Dustin Ruetz
2023-03-29 11:34:37 -04:00
committed by GitHub
parent 4ee6567f7b
commit ade3078eb5
15 changed files with 16087 additions and 401 deletions

View File

@@ -5,6 +5,9 @@ jobs:
lint: lint:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- name: ShellCheck - name: Run ShellCheck
uses: ludeeus/action-shellcheck@1.1.0 uses: ludeeus/action-shellcheck@2.0.0
with:
ignore_paths: >-
.husky

1
.gitignore vendored
View File

@@ -1 +1,2 @@
coverage/
node_modules/ node_modules/

View File

@@ -6,7 +6,6 @@ Specify in your workflow YAML file which secrets from 1Password should be loaded
Read more on the [1Password Developer Portal](https://developer.1password.com/docs/ci-cd/github-actions). Read more on the [1Password Developer Portal](https://developer.1password.com/docs/ci-cd/github-actions).
## Requirements ## Requirements
Before you get started, you'll need to: Before you get started, you'll need to:
@@ -16,7 +15,6 @@ Before you get started, you'll need to:
_Supported runners_: You can run the action on Mac and Linux runners. Windows is currently not supported. _Supported runners_: You can run the action on Mac and Linux runners. Windows is currently not supported.
## Usage ## Usage
You can configure the action to use your 1Password Connect instance. You can configure the action to use your 1Password Connect instance.
@@ -224,7 +222,7 @@ So if one of these values accidentally gets printed, it'll get replaced with `**
## 1Password Configuration ## 1Password Configuration
To use the action with Connect, you need to have a [1Password Connect](https://support.1password.com/secrets-automation/#step-1-set-up-a-secrets-automation-workflow) instance deployed somewhere. To use the action with Connect, you need to have a [1Password Connect](https://support.1password.com/secrets-automation/#step-1-set-up-a-secrets-automation-workflow) instance deployed somewhere.
To configure the action with your Connect host and token, set the `OP_CONNECT_HOST` and `OP_CONNECT_TOKEN` environment variables. To configure the action with your Connect host and token, set the `OP_CONNECT_HOST` and `OP_CONNECT_TOKEN` environment variables.
If you're using the `load-secrets` action more than once in a single job, you can use the `configure` action to avoid duplicate configuration: If you're using the `load-secrets` action more than once in a single job, you can use the `configure` action to avoid duplicate configuration:
@@ -249,10 +247,10 @@ jobs:
### `configure` Action Inputs ### `configure` Action Inputs
| Name | Default | Environment variable | Description | | Name | Environment variable | Description |
| ----------------------- | ------- | -------------------------- | -------------------------------------------------------- | | --------------- | -------------------- | -------------------------------------------------------- |
| `connect-host` | | `OP_CONNECT_HOST` | Your 1Password Connect instance URL | | `connect-host` | `OP_CONNECT_HOST` | Your 1Password Connect instance URL |
| `connect-token` | | `OP_CONNECT_TOKEN` | Token to authenticate to your 1Password Connect instance | | `connect-token` | `OP_CONNECT_TOKEN` | Token to authenticate to your 1Password Connect instance |
## Supported Runners ## Supported Runners

View File

@@ -7,10 +7,10 @@ branding:
inputs: inputs:
unset-previous: unset-previous:
description: Whether to unset environment variables populated by 1Password in earlier job steps description: Whether to unset environment variables populated by 1Password in earlier job steps
default: false default: "false"
export-env: export-env:
description: Export the secrets as environment variables description: Export the secrets as environment variables
default: true default: "true"
runs: runs:
using: 'node16' using: "node16"
main: 'dist/index.js' main: "dist/index.js"

4
config/.husky/pre-commit Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx lint-staged --config ./config/lint-staged.config.js

4
config/.husky/pre-push Executable file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npm run validate

3
config/.prettierignore Normal file
View File

@@ -0,0 +1,3 @@
coverage/
dist/
node_modules/

19
config/jest.config.js Normal file
View File

@@ -0,0 +1,19 @@
const jestConfig = {
/**
* Jest docs: "We recommend placing the extensions most commonly used in your project
* on the left, so if you are using TypeScript, you may want to consider
* moving 'ts' to the beginning of the array."
*
* https://jestjs.io/docs/configuration#modulefileextensions-arraystring
*/
moduleFileExtensions: ["ts", "js", "json"],
rootDir: "../src/",
testEnvironment: "node",
testRegex: "(/__tests__/.*|(\\.|/)test)\\.ts",
transform: {
".ts": ["ts-jest"],
},
verbose: true,
};
export default jestConfig;

View File

@@ -0,0 +1,9 @@
const lintStagedConfig = {
// run formatting and linting on all supported file types
"*.{js,json,md,ts,yaml,yml}": "npm run format:write",
"*.{js,ts}": ["npm run lint:fix"],
// run testing on all supported file types within the src/ directory
"src/**/*.{js,ts}": ["npm run test -- --findRelatedTests"],
};
export default lintStagedConfig;

2526
dist/index.js vendored

File diff suppressed because it is too large Load Diff

3
dist/package.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"type": "module"
}

13712
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,37 +1,66 @@
{ {
"name": "load-secrets-action", "name": "load-secrets-action",
"version": "1.1.0", "version": "1.2.0",
"description": "Load Secrets from 1Password", "description": "Load Secrets from 1Password",
"main": "dist/index.js", "type": "module",
"directories": { "main": "dist/index.js",
"test": "tests" "directories": {
}, "test": "tests"
"scripts": { },
"build": "ncc build src/index.ts" "scripts": {
}, "build": "ncc build ./src/index.ts",
"repository": { "format": "prettier --ignore-path ./config/.prettierignore",
"type": "git", "format:check": "npm run format -- --check ./",
"url": "git+https://github.com/1Password/load-secrets-action.git" "format:write": "npm run format -- --write ./",
}, "lint": "eslint ./",
"keywords": [ "lint:fix": "npm run lint -- --fix",
"actions", "prepare": "husky install ./config/.husky",
"1password", "test": "jest --config=./config/jest.config.js",
"load secrets", "test:clearcache": "jest --clearCache",
"connect" "test:coverage": "npm run test -- --coverage",
], "test:watch": "npm run test -- --watch",
"author": "1Password", "typecheck": "tsc",
"license": "MIT", "validate": "npm run format:check && npm run lint && npm run test:coverage && npm run typecheck && npm run build"
"bugs": { },
"url": "https://github.com/1Password/load-secrets-action/issues" "repository": {
}, "type": "git",
"homepage": "https://github.com/1Password/load-secrets-action#readme", "url": "git+https://github.com/1Password/load-secrets-action.git"
"dependencies": { },
"@actions/core": "^1.10.0", "keywords": [
"@actions/exec": "^1.1.1" "actions",
}, "1password",
"devDependencies": { "load secrets",
"@types/node": "^18.14.2", "connect"
"@vercel/ncc": "^0.36.1", ],
"typescript": "^4.9.5" "author": "1Password",
} "license": "MIT",
"bugs": {
"url": "https://github.com/1Password/load-secrets-action/issues"
},
"homepage": "https://github.com/1Password/load-secrets-action#readme",
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1"
},
"devDependencies": {
"@1password/front-end-style": "^6.0.1",
"@types/jest": "^29.5.0",
"@types/node": "^18.15.10",
"@vercel/ncc": "^0.36.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"lint-staged": "^13.2.0",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"
},
"eslintConfig": {
"extends": "./node_modules/@1password/front-end-style/eslintrc.yml",
"ignorePatterns": [
"coverage/"
],
"parserOptions": {
"project": "./tsconfig.json"
}
},
"prettier": "./node_modules/@1password/front-end-style/prettierrc.json"
} }

View File

@@ -1,21 +1,32 @@
import * as core from '@actions/core'; import path from "path";
import * as exec from '@actions/exec'; import url from "url";
import path from 'path'; import * as core from "@actions/core";
import * as exec from "@actions/exec";
async function run(): Promise<void> { const run = async () => {
try { try {
const parentDir = path.resolve(__dirname, '..'); const currentFile = url.fileURLToPath(import.meta.url);
const currentDir = path.dirname(currentFile);
// Get action inputs const parentDir = path.resolve(currentDir, "..");
process.env.INPUT_UNSET_PREVIOUS = core.getInput('unset-previous');
process.env.INPUT_EXPORT_ENV = core.getInput('export-env');
// Execute bash script // Get action inputs
await exec.exec(`sh -c "` + parentDir + `/entrypoint.sh"`); process.env.INPUT_UNSET_PREVIOUS = core.getInput("unset-previous");
process.env.INPUT_EXPORT_ENV = core.getInput("export-env");
} catch (error: any) { // Execute bash script
core.setFailed(error.message); await exec.exec(`sh -c "` + parentDir + `/entrypoint.sh"`);
} } catch (error) {
} // It's possible for the Error constructor to be modified to be anything
// in JavaScript, so the following code accounts for this possibility.
// https://kentcdodds.com/blog/get-a-catch-block-error-message-with-typescript
let message = "Unknown Error";
if (error instanceof Error) {
message = error.message;
} else {
String(error);
}
core.setFailed(message);
}
};
run(); void run();

View File

@@ -1,13 +1,25 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "es6", "allowJs": false,
"module": "commonjs", "allowUnreachableCode": false,
"moduleResolution": "node", "allowUnusedLabels": false,
"outDir": "./dist", "esModuleInterop": true,
"rootDir": "./src", "exactOptionalPropertyTypes": true,
"strict": true, "forceConsistentCasingInFileNames": true,
"noImplicitAny": true, "importsNotUsedAsValues": "error",
"esModuleInterop": true "isolatedModules": true,
}, "module": "esnext",
"exclude": ["node_modules"] "moduleResolution": "node",
"noEmit": true,
"noEmitOnError": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"noUncheckedIndexedAccess": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./dist/",
"rootDir": "./src/",
"strict": true,
"target": "es2022"
}
} }