@vzn/vx-ci 0.0.636 → 0.0.637
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/README.md +8 -8
- package/package.json +2 -2
- package/src/cache-scope.ts +4 -4
- package/src/index.ts +1 -1
- package/src/plugin.ts +5 -5
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install -D @vzn/vx @vzn/vx-ci # or: pnpm add -D -w · yarn add -D (-W on Y
|
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
// vx
|
|
14
|
+
// .vx/workspace.ts
|
|
15
15
|
import { defineWorkspace } from '@vzn/vx/config'
|
|
16
16
|
import { github } from '@vzn/vx-ci'
|
|
17
17
|
|
|
@@ -55,16 +55,16 @@ github({
|
|
|
55
55
|
|
|
56
56
|
## Cache scope
|
|
57
57
|
|
|
58
|
-
On Actions (`GITHUB_ACTIONS=true`), when
|
|
58
|
+
On Actions (`GITHUB_ACTIONS=true`), when `.vx/workspace.ts` sets no `cache.scope`, the plugin's
|
|
59
59
|
`config` stage sets it from the ref (`GITHUB_REF`, `GITHUB_REF_NAME`, and
|
|
60
|
-
the default branch from the `GITHUB_EVENT_PATH` payload): a push to the default branch
|
|
61
|
-
|
|
60
|
+
the default branch from the `GITHUB_EVENT_PATH` payload): a push to the default branch sets
|
|
61
|
+
none (reads and writes the default keys), a pull request becomes
|
|
62
62
|
`pr-<n>` (so is a `pull_request_target`, `issue_comment` or `workflow_run`
|
|
63
|
-
run on a PR's behalf, by `GITHUB_EVENT_NAME`, though its ref is main's) and any other branch or tag `ref-<name>`, which read
|
|
64
|
-
|
|
65
|
-
reads. `VX_CACHE_SCOPE` or a `
|
|
63
|
+
run on a PR's behalf, by `GITHUB_EVENT_NAME`, though its ref is main's) and any other branch or tag `ref-<name>`, which read the
|
|
64
|
+
default keys, then their own, and write only their own. A PR never writes what main
|
|
65
|
+
reads. Whether a run writes at all is `cache.policy`'s call. `VX_CACHE_SCOPE` or a `cache.scope` in `.vx/workspace.ts` overrides it. This is a client-side convention: the real boundary is a cache
|
|
66
66
|
token the server limits, so give PR jobs one that cannot write the
|
|
67
|
-
|
|
67
|
+
default keys (`docs/security.md` § Cache poisoning).
|
|
68
68
|
|
|
69
69
|
## How it works
|
|
70
70
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vzn/vx-ci",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.637",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "GitHub Actions integration for vx — a telemetry plugin that writes the run as a GitHub Actions job summary.",
|
|
6
6
|
"keywords": [
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@vzn/vx": "^0.0.
|
|
36
|
+
"@vzn/vx": "^0.0.637"
|
|
37
37
|
},
|
|
38
38
|
"repository": {
|
|
39
39
|
"type": "git",
|
package/src/cache-scope.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// The cache scope a GitHub Actions run gets when the workspace names none:
|
|
2
|
-
// the default branch
|
|
2
|
+
// the default branch writes the default keys, anything else its own scope.
|
|
3
3
|
import { readFile } from 'node:fs/promises'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* `undefined` (
|
|
6
|
+
* `undefined` (the default keys) on a push to the
|
|
7
7
|
* default branch, outside Actions, or when the ref is unknown; else
|
|
8
8
|
* `pr-<n>` for a pull request and `ref-<name>` for any other branch or tag.
|
|
9
9
|
* An event that runs in the default branch's context on a pull request's
|
|
10
10
|
* behalf (`pull_request_target`, `issue_comment` on a PR, a `workflow_run`
|
|
11
11
|
* a PR started) is the PR's, whatever `GITHUB_REF` says: a workflow that
|
|
12
|
-
* checks out the PR's head there would otherwise write the
|
|
12
|
+
* checks out the PR's head there would otherwise write the default keys.
|
|
13
13
|
*/
|
|
14
14
|
export async function githubCacheScope(
|
|
15
15
|
env: Readonly<Record<string, string | undefined>>,
|
|
@@ -26,7 +26,7 @@ export async function githubCacheScope(
|
|
|
26
26
|
const branch = event?.repository?.default_branch
|
|
27
27
|
if (typeof branch === 'string' && branch !== '' && ref === `refs/heads/${branch}`)
|
|
28
28
|
return undefined
|
|
29
|
-
// `
|
|
29
|
+
// `cache.scope` takes letters, digits and . _ - / @; a ref may hold more.
|
|
30
30
|
return `ref-${name.replace(/[^\w.@/-]/g, '_').slice(0, 124)}`
|
|
31
31
|
}
|
|
32
32
|
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Public API for @vzn/vx-ci — the GitHub Actions integration plugin.
|
|
2
2
|
//
|
|
3
|
-
// Usage in vx
|
|
3
|
+
// Usage in .vx/workspace.ts:
|
|
4
4
|
// import { defineWorkspace } from '@vzn/vx'
|
|
5
5
|
// import { github } from '@vzn/vx-ci'
|
|
6
6
|
// export default defineWorkspace({ plugins: [github()] })
|
package/src/plugin.ts
CHANGED
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
import type { FetchFn } from './checks.js'
|
|
16
16
|
import { githubCacheScope } from './cache-scope.js'
|
|
17
17
|
|
|
18
|
-
// Every run evaluates
|
|
18
|
+
// Every run evaluates `.vx/workspace.ts`; the sink, the summary renderer
|
|
19
19
|
// and the Checks API client load only where a summary file is set. The
|
|
20
20
|
// telemetry hook is synchronous, so the module loads by `require`.
|
|
21
21
|
const loadSink = (): typeof import('./sink.js') => createRequire(import.meta.url)('./sink.js')
|
|
@@ -40,8 +40,8 @@ export interface GithubPluginOptions {
|
|
|
40
40
|
/** Check-run name. Default: `'vx'`. */
|
|
41
41
|
checkName?: string
|
|
42
42
|
/**
|
|
43
|
-
* Set the workspace's `
|
|
44
|
-
* a push to the default branch
|
|
43
|
+
* Set the workspace's `cache.scope` from the run's ref when it names none:
|
|
44
|
+
* a push to the default branch keeps the default keys, a pull request writes to
|
|
45
45
|
* `pr-<n>`, any other ref to `ref-<name>`. Default: on; `false` opts out.
|
|
46
46
|
*/
|
|
47
47
|
cacheScope?: boolean
|
|
@@ -95,9 +95,9 @@ export function github(options: GithubPluginOptions = {}): VxPlugin | undefined
|
|
|
95
95
|
}
|
|
96
96
|
return definePlugin(import.meta, {
|
|
97
97
|
async config(workspace) {
|
|
98
|
-
if (options.cacheScope === false || workspace.
|
|
98
|
+
if (options.cacheScope === false || workspace.cache?.scope !== undefined) return
|
|
99
99
|
const scope = await githubCacheScope(process.env)
|
|
100
|
-
if (scope !== undefined) workspace.
|
|
100
|
+
if (scope !== undefined) workspace.cache = { ...workspace.cache, scope }
|
|
101
101
|
},
|
|
102
102
|
telemetry(ctx) {
|
|
103
103
|
const file = options.summaryFile ?? process.env['GITHUB_STEP_SUMMARY']
|