1Password / load-secrets-action

Load secrets from 1Password into your GitHub Actions jobs
https://developer.1password.com
MIT License
190 stars 25 forks source link

Migrate action to Typescript #36

Closed edif2008 closed 7 months ago

edif2008 commented 1 year ago

This PR migrates most of the functionality of the GitHub Action to Typescript.

Key elements used in the migration

Element Explanation
op-js Typescript package that wraps 1Password CLI commands. It enables us to easily work with the output returned by the 1Password CLI.
core.setOutput Make the secret available as a step's output (works with multiline secrets as well).
core.exportVariable Make the secret available as an environment variable (works with multiline secrets as well).
core.setSecret Ensures the secret is masked in logs.
core.setPath Add the path to the CLI to be able to call it in further parts of the action, as well as other steps in the pipeline.

Migration process

The commits should show an overview of the steps of the migration. I will present here the details of the main migration step highlighted in 6c9a28c: Functionality from entrypoint.sh Functionality in index.ts
unset_prev_secrets unsetPrevious
auth validation (no dedicated function) validateAuth
install_cli installCLI
extract_secrets loadSecrets
populating_secret extractSecret

Notes

dustin-ruetz commented 1 year ago

Overall note: awesome work on this TypeScript migration, @edif2008! 👏

Everything looks very solid and works well from my testing. I left a bunch of file-specific feedback in my review yesterday and some additional comments today.

Just a few remaining general thoughts:

  1. src/utils.ts currently has four functions in it, so I'd be in favour of splitting these out into their own files in a src/utils/ directory. They could each then get their own test suites too under src/utils/__tests__/*.test.ts. IMO this change would make future maintenance/refactoring easier.
  2. Can we split out installCLI and loadSecrets into their own files in src/utils/ as well?
  3. This would leave src/index.ts with just the run function in it. Is there a clearer name that we can use for this function? Perhaps even just something like loadSecretsAction, since it's representative of the main functionality for this package?
  4. It'd be great if we could add unit tests for installCLI, loadSecrets and run as well.

Happy to help wherever I can with the above list, especially the unit tests.

To conclude this review - once again, great work on this PR!

kylekurz commented 1 year ago

Any chance this can get merged and an update to this action released? We'd like to incorporate it into some of our pipelines, but would like to have it pull in a modern build instead of the 2.10 that is in the current "live" action.