fac78884c8835ee4570b491f042b7584344345f2
2 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2792fede48 |
Migrate action to Typescript (#36)
* Make function for executing script * Migrate auth validation * Migrate load secret functionality We make use of the following in the migration: - `op-js` package (make direct calls to the CLI and nicely get the output of the commands) - `core.exportVariable` to nicely export a secret as an environment variable - `core.setOutput` to nicely export a secret a the step’s output. - `core.setSecret` to mask the value of the secret if logged on the action’s output. Note: `core.exportVariable` and `core.setOutput` work with multiline secrets without any additional work on our side. Also, we export the temporary path where the CLI is installed to make sure the `op-js` package can find it. * Fix CLI installation process * Fix conditional of appending protocol Fix conditional of appending `http://` to the Connect host. * Update CLI version and improve script * Use core.addPath This is a safer and nicer way to ensure the path to the CLI is included later in the pipeline (including this GitHub action). * Use version from package.json This eliminates the duplication of version in the code * Upgrade to Typescript 5 * Prettify test.yml * Move constants to constants.ts This shows better what constants we use and they will be later used in both code and tests. * Move 'validateAuth' to 'utils.ts' * Add validate auth tests * Extract functionality for extracting a secret This will enable us to easily test the functionality of the action regarding the extraction of secret and how it provides it to the rest of the pipeline based on user's input * Add tests for extracting secret * Move 'unsetPrevious' to 'utils.ts' * Add unit test pipeline * Add tests for 'unsetPrevious' * Improve disabling eslint rules Disable the ES Lint rules only for the next line and add a comment explaining why it’s disabled. * Improve code based on PR review feedback This contains code improvements that were easy to address based on PR review feedback. * Improve CLI installation functionality Two key elements are improved: - The action will now automatically fetch the latest stable version of the CLI. There’s no longer the need to hardcode the version and manually update it. - The action will now perform a check if the CLI exists in the pipeline and install it if it’s not available. * Simplify extractSecret functionality Eliminate the nested conditionals to have a cleaner and more readable code. * Fix CLI version The curl would return the version number, but we forgot to append the `v` in the version (i.e. from 2.18.0 to v2.18.0). Now it should be fixed. * Move loadSecrets function to utils.ts This is done to keep things modular and narrow down the scope and complexity of index.ts. `installCLI` will be kept in `index.ts` for the following reasons: - Moving it to utils brings complications (`import.meta.url` doesn’t work) - This code will be removed once the action will make use of the separate install CLI action * Simplify code related to mocking * Use semverToInt from op-js Version `0.1.9` of the `op-js` exports function `semverToInt`, therefore we no longer need to duplicate it in our code. * Improve CLI installation script - Add architectures for Linux runners. Fail if the architecture is not supported. - Fail if the runner’s operating system is not supported. * Change from debug messages to info In pre-TS GitHub Action, we’d print some messages to the output as info (e.g. authenticated as, populating variable, unsetting previous values). Therefore, we apply the same principle here since there’s useful info. * use toHaveBeenCalled consistently in tests `toBeCalled` is an alias for `toHaveBeenCalled` and `toBeCalledWith` is an alias for `toHaveBeenCalledWith`. For consistency, we will use `toHaveBeenCalled` and `toHaveBeenCalledWith` consistently across our tests. * Add warning if both configs are provided 1Password CLI will prioritize Connect config (with `OP_CONNECT_HOST` and `OP_CONNECT_TOKEN`) over service account one (with `OP_SERVICE_ACCOUNT_TOKEN`). This shouldn’t happen, therefore we print a warning to the user if both are provided. * Add comment about cli validation process The code itself seems a bit confusing, therefore we add a comment explaining how it works. * test: assertions for loadSecrets function * Improve loadSecrets function Return early if no env vars with valid secret references are found * Update dependencies * Upgrade action to use Node20 --------- Co-authored-by: Dustin Ruetz <dustin.ruetz@agilebits.com> |
||
|
|
ade3078eb5 |
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 |