-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate action to Typescript #36
Conversation
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 conditional of appending `http://` to the Connect host.
This is a safer and nicer way to ensure the path to the CLI is included later in the pipeline (including this GitHub action).
This eliminates the duplication of version in the code
This shows better what constants we use and they will be later used in both code and tests.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a quick pass at this, I love what you've done here so great job! I'm in agreement with Dustin's comments as well.
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.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, Eddy! This looks so good.
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. |
Verion `0.1.9` of the `op-js` exports function `semverToInt`, therefore we no longer need to duplicate it in our code.
- Add architectures for Linux runners. Fail if the architecture is not supported. - Fail if the runner’s operating system is not supported.
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.
`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.
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.
The code itself seems a bit confusing, therefore we add a comment explaining how it works.
commit 10ed075 Author: Eduard Filip <[email protected]> Date: Wed Jul 5 16:50:31 2023 +0100 Improve the shell script (#49) * Improve CLI installation script - Add additional architectures for Linux. - Stop the action if the runner is executed in an unsupported OS. - Fetch automatically the latest stable CLI version. * Switch to new syntax for setting step output. GitHub has deprecated the syntax we were using for setting a step’s output (https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/). Therefore, we’re switching to the new one. * Stop action if arch is unsupported for Linux runners. commit 539eaa6 Author: Eduard Filip <[email protected]> Date: Wed Jul 5 11:36:30 2023 +0100 Improve the repo’s README (#48) Use a new template for the README file to better present the content. commit 08315da Merge: d8ac5d7 0e91b4a Author: Eduard Filip <[email protected]> Date: Mon Jul 3 16:54:07 2023 +0100 Merge pull request #44 from settlemint/main feat: install the right op for arm on linux commit 0e91b4a Author: roderik.eth <[email protected]> Date: Thu May 18 21:48:54 2023 +0200 fix: arm uname commit 9c2d98e Author: roderik.eth <[email protected]> Date: Thu May 18 20:51:49 2023 +0200 feat: install the right op for arm on linux commit d8ac5d7 Merge: 8fd274c 15d95ae Author: volodymyrZotov <[email protected]> Date: Tue May 16 20:09:59 2023 +0300 Merge pull request #42 from 1Password/ruetz-service-accounts-exiting-beta Remove 'BETA' references from Service Accounts commit 15d95ae Author: Dustin Ruetz <[email protected]> Date: Tue May 9 14:23:45 2023 -0400 style: auto-formatting fixes via Prettier commit a48d1fc Author: Dustin Ruetz <[email protected]> Date: Tue May 9 14:21:13 2023 -0400 docs: remove 'BETA' references from Service Accounts commit 8fd274c Merge: 663ac22 f4303b2 Author: Eduard Filip <[email protected]> Date: Mon Apr 24 11:19:45 2023 +0200 Merge pull request #39 from 1Password/eddy/service-account-docs Add documentation related to Service Accounts (currently in beta) commit f4303b2 Author: Eddy Filip <[email protected]> Date: Mon Apr 24 11:17:52 2023 +0200 Improve wording commit f4a99d4 Author: Eddy Filip <[email protected]> Date: Thu Apr 20 20:50:59 2023 +0200 Make small edits commit 9c1afd6 Author: Eddy Filip <[email protected]> Date: Thu Apr 20 18:53:49 2023 +0200 Adjust action versions used in examples In this way we keep them relevant with the latest versions commit a02ee66 Author: Eddy Filip <[email protected]> Date: Thu Apr 20 18:50:07 2023 +0200 Add documentation for service accounts
Return early if no env vars with valid secret references are found
6abf126
to
62959c4
Compare
# Conflicts: # dist/index.js # package-lock.json # package.json
This PR migrates most of the functionality of the GitHub Action to Typescript.
Key elements used in the migration
op-js
core.setOutput
core.exportVariable
core.setSecret
core.setPath
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
:entrypoint.sh
index.ts
unset_prev_secrets
unsetPrevious
validateAuth
install_cli
installCLI
extract_secrets
loadSecrets
populating_secret
extractSecret
Notes
installCLI
inindex.tx
only executes the shell script that will perform the CLI installation. No real migration has been performed for this part of the action.!process.env[envConnectHost].startsWith("http://")
no-restricted-syntax
Use https instead of http in URLs
) since we perform a check for the prefixhttp://
.const installCLI = async (): Promise<void> =>
@typescript-eslint/naming-convention
CLI
being all capitalized.expect(process.env[envConnectHost]).toBe("http://localhost:8080");
no-restricted-syntax
Use https instead of http in URLs
) since we perform a check on whether the prefixhttp://
was properly appended.