Skip to content

[WIP] Parallelize env var reads#163

Draft
jhnns wants to merge 2 commits into
1Password:mainfrom
peerigon:poc-load-secrets-batched
Draft

[WIP] Parallelize env var reads#163
jhnns wants to merge 2 commits into
1Password:mainfrom
peerigon:poc-load-secrets-batched

Conversation

@jhnns
Copy link
Copy Markdown

@jhnns jhnns commented Apr 24, 2026

Adds support for loading secrets from an environment file in batches, improving the performance for workflows that rely on multiple secrets.

Closes #91 #101

@jhnns
Copy link
Copy Markdown
Author

jhnns commented Apr 24, 2026

Hi everyone 👋,

first of all: thank you for this GitHub action! I really like the approach of storing my .env secrets in 1Password :)

This PR is a PoC implementation for a performance improvement:

In our application, we have about 15 environment variables that need to be loaded from 1Password. In the current implementation, this takes about 25–30 seconds. It appears that "Populating variables" is executed sequentially. For us, this is kind of unacceptable because the whole action just takes 1 minute (30 seconds of it just loading env variables).

I know that this has been brought up before (#91 #101), but the referenced PR #82 has been closed. I also think that this could be fixed now without waiting for a complete rewrite.

This PR is a proof-of-concept implementation of how parallel loading of environment variables might work. As a disclaimer upfront: this implementation was generated by AI. It includes some changes that I believe are useful but have nothing to do with this fix.

I just wanted to know if you're interested in this change and if you think the approach is generally okay before I invest any more time in it.

I tested this PR in our setup and it brought the action down to 4s.

Comment thread dist/index.js
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want the dist to be included in the PR?

Comment thread src/index.ts
message = error.message;
} else {
String(error);
message = String(error);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated, but useful change. I can open a separate PR for it.

Comment thread src/utils.test.ts
Comment on lines +153 to +158
expect(setClientInfo).toHaveBeenCalledWith(
expect.objectContaining({
name: "1Password GitHub Action",
id: "GHA",
}),
);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change. I can revert that :)

Comment thread src/utils.test.ts
id: "GHA",
}),
);
expect(exec.getExecOutput).toHaveBeenCalledWith("op", ["env", "ls"]);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unrelated, see my comment at the implementation

Comment thread src/utils.ts
Comment on lines +102 to +123
const nodeScript =
'const keys=JSON.parse(process.env.OP_KEYS_JSON||"[]");const out={};for(const k of keys){out[k]=process.env[k]??"";}process.stdout.write(JSON.stringify(out));';

const res = await exec.getExecOutput(
"op",
[
"run",
`--env-file=${envFile}`,
"--no-masking",
"--",
"node",
"-e",
nodeScript,
],
{
silent: true,
env: {
...process.env,
[envFileKeysEnvVar]: JSON.stringify(envNames),
},
},
);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can put nodeScript into a dedicated file. Do you think the approach of "abusing" op run is ok?

Comment thread src/utils.ts
// Iterate over them to find 1Password references, extract the secret values,
// and make them available in the next steps either as step outputs or as environment variables.
const res = await exec.getExecOutput(`sh -c "op env ls"`);
const res = await exec.getExecOutput("op", ["env", "ls"]);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is also unrelated.

Personally, I think the change makes sense, but maybe there's a specific reason for sh -c? I can do a separate PR if you're interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading refs concurrently

1 participant