apify-test-tools 0.10.2-beta.17 → 0.10.2-beta.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes CHANGED
@@ -1,2 +1,3 @@
1
1
  # Generated by `npm run bundle`: collapsed in GitHub diffs and shown as binary by git diff.
2
2
  .github/cli/apify-test-tools.mjs linguist-generated=true -diff
3
+ .github/scripts/run-with-apify-tokens.mjs linguist-generated=true -diff
@@ -1,129 +1,3 @@
1
1
  #!/usr/bin/env node
2
- // Runs apify-test-tools and passes it only secrets needed for the Actors, no other secrets are leaked.
3
- //
4
- // jq ... | node .github/scripts/run-with-apify-tokens.mjs apify-test-tools build --version-number 0.99
5
- //
6
- // The step passes the reusable workflow's whole secrets map as WORKFLOW_SECRETS. The token names
7
- // come from `tokenEnvVar` in the repo's apify-test-tools.config.json, which is the same file
8
- // apify-test-tools itself reads, so the two can't drift. Everything else in the secrets map (npm,
9
- // Slack, GitHub, anything else the repo holds) is left out, and WORKFLOW_SECRETS itself is dropped,
10
- // so the blob never reaches the CLI or anything under node_modules.
11
- //
12
- // Each token is looked up in the CONFIG_SECRETS secret first, a JSON object of secret name -> value,
13
- // and then among the top-level secrets, which is where `secrets: inherit` puts them. The secrets the
14
- // workflows read by name (NPM_TOKEN, TESTER_APIFY_TOKEN, ...) never come from CONFIG_SECRETS.
15
- //
16
- // The command runs without a shell, so branch names and other interpolated arguments are passed
17
- // through as literal argv entries.
18
-
19
- import { spawnSync } from 'node:child_process';
20
- import fs from 'node:fs';
21
- import path from 'node:path';
22
-
23
- // Resolved against the working directory, matching how apify-test-tools' own readConfigFile
24
- // locates it.
25
- const CONFIG_FILE_NAME = 'apify-test-tools.config.json';
26
-
27
- const fail = (message) => {
28
- console.error(message);
29
- process.exit(1);
30
- };
31
-
32
- const [command, ...args] = process.argv.slice(2);
33
- if (!command) fail('Usage: run-with-apify-tokens.mjs <command> [args...]');
34
-
35
- const { WORKFLOW_SECRETS, ...baseEnv } = process.env;
36
- if (!WORKFLOW_SECRETS) {
37
- fail('WORKFLOW_SECRETS is not set. Add `WORKFLOW_SECRETS: ${{ toJSON(secrets) }}` to the step env.');
38
- }
39
-
40
- let workflowSecrets;
41
- try {
42
- workflowSecrets = JSON.parse(WORKFLOW_SECRETS);
43
- } catch (error) {
44
- fail(`WORKFLOW_SECRETS is not valid JSON: ${error.message}`);
45
- }
46
-
47
- // Never includes the parse error: Node quotes the input in it, and the input is a secret.
48
- const unpackConfigSecrets = () => {
49
- const packed = workflowSecrets.CONFIG_SECRETS;
50
- if (!packed) return {};
51
- let value;
52
- try {
53
- value = JSON.parse(packed);
54
- } catch {
55
- fail('The CONFIG_SECRETS secret is not valid JSON.');
56
- }
57
- if (typeof value !== 'object' || value === null || Array.isArray(value)) {
58
- fail('The CONFIG_SECRETS secret must be a JSON object.');
59
- }
60
- return value;
61
- };
62
-
63
- const secrets = { ...workflowSecrets, ...unpackConfigSecrets() };
64
-
65
- const configPath = path.resolve(process.cwd(), CONFIG_FILE_NAME);
66
- let config;
67
- try {
68
- config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
69
- } catch (error) {
70
- fail(`Cannot read "${configPath}": ${error.message}`);
71
- }
72
-
73
- if (!Array.isArray(config.actors)) {
74
- fail(`"${configPath}" must have an "actors" array at the top level.`);
75
- }
76
-
77
- const tokenNames = [];
78
- const entriesWithoutToken = [];
79
-
80
- for (const [index, actor] of config.actors.entries()) {
81
- const tokenEnvVar = actor?.tokenEnvVar;
82
- if (typeof tokenEnvVar !== 'string' || tokenEnvVar === '') {
83
- entriesWithoutToken.push(actor?.actorFullName ?? `entry at index ${index}`);
84
- continue;
85
- }
86
- if (!tokenNames.includes(tokenEnvVar)) tokenNames.push(tokenEnvVar);
87
- }
88
-
89
- tokenNames.sort();
90
-
91
- if (entriesWithoutToken.length > 0) {
92
- console.error(
93
- `Warning: no "tokenEnvVar" in ${CONFIG_FILE_NAME} for: ${entriesWithoutToken.join(', ')}. ` +
94
- `Building those Actors will fail.`,
95
- );
96
- }
97
-
98
- // Declared but absent is a warning, not an error. A repo can carry an Actor whose token isn't
99
- // configured and still build fine as long as that Actor never changes, and apify-test-tools raises
100
- // a precise error naming the Actor at the point it actually needs the token.
101
- const missing = tokenNames.filter((name) => !(name in secrets));
102
- if (missing.length > 0) {
103
- console.error(
104
- `Warning: ${CONFIG_FILE_NAME} declares ${missing.join(', ')}, but no such secret was passed ` +
105
- `to this workflow, neither inside CONFIG_SECRETS nor inherited. Check the repository secrets ` +
106
- `and the workflow's \`secrets:\` if a build fails on a missing token.`,
107
- );
108
- }
109
-
110
- const present = tokenNames.filter((name) => name in secrets);
111
-
112
- // Names only. The values are secrets and must never be printed, even though the runner masks
113
- // registered secrets in logs.
114
- console.error(`Passing ${present.length} Actor token(s) to \`${command}\`: ${present.join(', ') || '(none)'}`);
115
-
116
- const env = { ...baseEnv };
117
- for (const name of present) {
118
- env[name] = secrets[name];
119
- }
120
-
121
- const result = spawnSync(command, args, { stdio: 'inherit', env });
122
-
123
- if (result.error) {
124
- fail(`Failed to run \`${command}\`: ${result.error.message}`);
125
- }
126
-
127
- // Preserve the child's exit code so the step fails exactly when the command does. A child killed
128
- // by a signal reports a null status, which would otherwise be read as success.
129
- process.exit(result.status ?? 1);
2
+ import{createRequire as __createRequire}from'node:module';const require=__createRequire(import.meta.url);
3
+ import{spawnSync as m}from"node:child_process";import k from"node:fs";import w from"node:path";var S="apify-test-tools.config.json";function t(e){console.error(e),process.exit(1)}function o(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var[c,...C]=process.argv.slice(2);c||t("Usage: run-with-apify-tokens.mjs <command> [args...]");var{WORKFLOW_SECRETS:E,...v}=process.env;E||t("WORKFLOW_SECRETS is not set. Add `WORKFLOW_SECRETS: ${{ toJSON(secrets) }}` to the step env.");var h;try{h=JSON.parse(E)}catch(e){t(`WORKFLOW_SECRETS is not valid JSON: ${e instanceof Error?e.message:String(e)}`)}var d=h;o(d)||t("WORKFLOW_SECRETS must be a JSON object of secret names and values.");var y=()=>{let e=d.CONFIG_SECRETS;if(!e)return{};typeof e!="string"&&t("The CONFIG_SECRETS secret is not valid JSON.");let n;try{n=JSON.parse(e)}catch{t("The CONFIG_SECRETS secret is not valid JSON.")}return o(n)||t("The CONFIG_SECRETS secret must be a JSON object."),n},g={...d,...y()},a=w.resolve(process.cwd(),S),i;try{i=JSON.parse(k.readFileSync(a,"utf8"))}catch(e){t(`Cannot read "${a}": ${e instanceof Error?e.message:String(e)}`)}(!o(i)||!Array.isArray(i.actors))&&t(`"${a}" must have an "actors" array at the top level.`);var r=[],f=[],N=i.actors;for(let[e,n]of N.entries()){let s=o(n)?n.tokenEnvVar:void 0;if(typeof s!="string"||s===""){f.push((o(n)?n.actorFullName:void 0)??`entry at index ${e}`);continue}r.includes(s)||r.push(s)}r.sort();f.length>0&&console.error(`Warning: no "tokenEnvVar" in ${S} for: ${f.join(", ")}. Building those Actors will fail.`);var p=r.filter(e=>!(e in g));p.length>0&&console.error(`Warning: ${S} declares ${p.join(", ")}, but no such secret was passed to this workflow, neither inside CONFIG_SECRETS nor inherited. Check the repository secrets and the workflow's \`secrets:\` if a build fails on a missing token.`);var l=r.filter(e=>e in g);console.error(`Passing ${l.length} Actor token(s) to \`${c}\`: ${l.join(", ")||"(none)"}`);var O={...v};for(let e of l){let n=g[e];typeof n!="string"&&t(`Secret "${e}" must be a string.`),O[e]=n}var u=m(c,C,{stdio:"inherit",env:O});u.error&&t(`Failed to run \`${c}\`: ${u.error.message}`);process.exit(u.status??1);
@@ -77,10 +77,10 @@ jobs:
77
77
  - name: Build
78
78
  run: npm run build
79
79
 
80
- # The composite action runs the CLI from .github/cli/apify-test-tools.mjs, which the pre-commit
81
- # hook rebuilds. This catches commits that skipped the hook, so a stale bundle never ships.
80
+ # The composite action runs the CLI and workflow helper bundles, which the pre-commit hook rebuilds.
81
+ # This catches commits that skipped the hook, so stale bundles never ship.
82
82
  cli_bundle:
83
- name: CLI bundle
83
+ name: CLI and workflow bundles
84
84
  runs-on: ubuntu-latest
85
85
  steps:
86
86
  - name: Checkout repository
@@ -96,8 +96,8 @@ jobs:
96
96
  - name: Check the bundle is up to date
97
97
  run: |
98
98
  npm run bundle
99
- if ! git diff --quiet -- .github/cli/; then
100
- echo "::error::.github/cli/apify-test-tools.mjs is out of date. Run \`npm run bundle\` and commit the result."
99
+ if ! git diff --quiet -- .github/cli/ .github/scripts/run-with-apify-tokens.mjs; then
100
+ echo "::error::A CLI or workflow script bundle is out of date. Run \`npm run bundle\` and commit the result."
101
101
  exit 1
102
102
  fi
103
103
  node .github/cli/apify-test-tools.mjs --help > /dev/null
package/.husky/pre-commit CHANGED
@@ -1,10 +1,10 @@
1
1
  echo "pre-commit: typechecking, linting, testing, checking code formatting, checking for unused exports & validating schemas"
2
2
 
3
3
 
4
- # The workflows run the CLI from this bundle, so it ships with every commit that changes bin/ or its
5
- # dependencies. Rebuilding takes well under a second.
4
+ # The workflows run the CLI and token wrapper from these bundles, so they ship with every commit
5
+ # that changes their sources or dependencies.
6
6
  npm run -s bundle
7
- git add .github/cli/apify-test-tools.mjs
7
+ git add .github/cli/apify-test-tools.mjs .github/scripts/run-with-apify-tokens.mjs
8
8
 
9
9
  npm test
10
10
  npm run format:check
@@ -15,4 +15,4 @@ npx lint-staged
15
15
  # Activate once we resolv unused delete old builds
16
16
  # npm run check-unused
17
17
 
18
- echo "pre-commit: passed"
18
+ echo "pre-commit: passed"
package/.prettierignore CHANGED
@@ -11,3 +11,4 @@ test/fixtures
11
11
 
12
12
  # Generated by `npm run bundle`
13
13
  .github/cli/
14
+ .github/scripts/run-with-apify-tokens.mjs