Skip to content

Commit 081c42e

Browse files
committed
Queue PR previews and cover review regressions
Keep manual publishing and exact SDK previews available. Serialize preview requests for each pull request and allow multiple queued runs. Document how to reinstall the version hook from the isolated uv tool, and verify preview queue configuration and FOSSA CVSS output.
1 parent 282b7bd commit 081c42e

5 files changed

Lines changed: 105 additions & 8 deletions

File tree

‎.github/workflows/pr-preview.yml‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,36 @@ name: Publish PR Preview
33
on:
44
pull_request:
55
types: [labeled]
6+
workflow_dispatch:
7+
inputs:
8+
pr_number:
9+
description: Pull request number to publish
10+
required: true
11+
type: string
12+
publish_test_pypi:
13+
description: Publish the Python package to TestPyPI
14+
required: true
15+
default: true
16+
type: boolean
17+
publish_docker:
18+
description: Publish socketdev/cli:pr-<number> to Docker Hub
19+
required: true
20+
default: false
21+
type: boolean
22+
sdk_preview_version:
23+
description: Optional exact TestPyPI socketdev prerelease for the Docker image
24+
required: false
25+
type: string
626

727
concurrency:
8-
group: publish-pr-preview-${{ github.event.pull_request.number }}
28+
group: publish-pr-preview-${{ github.event.pull_request.number || inputs.pr_number || github.run_id }}
929
cancel-in-progress: false
30+
queue: max
1031

1132
jobs:
1233
context:
1334
if: >-
35+
github.event_name == 'workflow_dispatch' ||
1436
(github.event.label.name == 'publish-preview' ||
1537
github.event.label.name == 'publish-docker-preview') &&
1638
github.event.pull_request.head.repo.full_name == github.repository
@@ -27,15 +49,28 @@ jobs:
2749
id: context
2850
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
2951
env:
52+
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
3053
EVENT_PR_NUMBER: ${{ github.event.pull_request.number }}
54+
INPUT_PR_NUMBER: ${{ inputs.pr_number }}
55+
WORKFLOW_REF: ${{ github.ref }}
3156
with:
3257
script: |
33-
const rawPrNumber = process.env.EVENT_PR_NUMBER;
58+
const rawPrNumber = context.eventName === 'workflow_dispatch'
59+
? process.env.INPUT_PR_NUMBER
60+
: process.env.EVENT_PR_NUMBER;
3461
if (!/^[1-9][0-9]*$/.test(rawPrNumber || '')) {
3562
core.setFailed('Pull request number must contain ASCII digits only.');
3663
return;
3764
}
3865
66+
if (context.eventName === 'workflow_dispatch') {
67+
const defaultRef = `refs/heads/${process.env.DEFAULT_BRANCH}`;
68+
if (process.env.WORKFLOW_REF !== defaultRef) {
69+
core.setFailed(`Run manual previews from ${defaultRef}.`);
70+
return;
71+
}
72+
}
73+
3974
const prNumber = Number(rawPrNumber);
4075
if (!Number.isSafeInteger(prNumber)) {
4176
core.setFailed('Pull request number is outside the supported range.');
@@ -128,7 +163,9 @@ jobs:
128163

129164
publish-package:
130165
needs: [context, build]
131-
if: github.event.label.name == 'publish-preview'
166+
if: >-
167+
github.event.label.name == 'publish-preview' ||
168+
(github.event_name == 'workflow_dispatch' && inputs.publish_test_pypi)
132169
runs-on: ubuntu-latest
133170
timeout-minutes: 10
134171
permissions:
@@ -192,7 +229,9 @@ jobs:
192229
193230
publish-docker:
194231
needs: [context, build]
195-
if: github.event.label.name == 'publish-docker-preview'
232+
if: >-
233+
github.event.label.name == 'publish-docker-preview' ||
234+
(github.event_name == 'workflow_dispatch' && inputs.publish_docker)
196235
runs-on: ubuntu-latest
197236
timeout-minutes: 15
198237
permissions:
@@ -236,6 +275,8 @@ jobs:
236275
# arm64 layer builds under emulation, so expect roughly double the runtime.
237276
platforms: linux/amd64,linux/arm64
238277
tags: socketdev/cli:pr-${{ needs.context.outputs.pr_number }}
278+
build-args: |
279+
SDK_PREVIEW_VERSION=${{ inputs.sdk_preview_version }}
239280
240281
- name: Comment on pull request
241282
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0

‎CONTRIBUTING.md‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ dependencies:
1111
uv sync --all-extras
1212
```
1313

14+
To install or migrate the version-sync Git hook, see the
15+
[development guide](docs/development.md#version-sync-hook).
16+
1417
Before opening a pull request, run:
1518

1619
```bash
@@ -44,11 +47,19 @@ needs testing:
4447
`socketdev/cli:pr-<pull-request-number>` image to Docker Hub and adds or
4548
updates a pull request comment with the image tag.
4649

47-
Previews are limited to open pull requests whose branches belong to this
48-
repository. Each label is handled as a separate event, so applying both labels
49-
starts two workflow runs.
50+
Both label-triggered and manually dispatched previews are limited to open pull
51+
requests whose branches belong to this repository. Each label starts a separate
52+
run. Preview runs for the same pull request wait in a queue so both labels can
53+
publish when a preview is already running.
5054

5155
The workflow reacts when a label is added; pushing another commit while the
5256
label remains on the pull request does not publish a new preview. To publish the
5357
new pull request head or retry a failed publication, remove the relevant label
5458
and apply it again.
59+
60+
Maintainers can also open **Actions > Publish PR Preview > Run workflow**, run
61+
it from the repository's default branch, enter the pull request number, and
62+
choose whether to publish to TestPyPI, Docker Hub, or both. When testing the CLI
63+
against an SDK preview, enter the exact TestPyPI `socketdev` prerelease in
64+
`sdk_preview_version`; publish the SDK preview first and allow time for
65+
TestPyPI to expose it before starting the CLI Docker preview.

‎docs/development.md‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,17 @@ GitLab:
8989
python -m venv .venv
9090
source .venv/bin/activate
9191
uv sync
92+
```
93+
94+
## Version-sync hook
95+
96+
Install `pre-commit` outside the project's virtual environment. If your existing
97+
hook was installed from `.venv`, reinstall it with the commands below so it
98+
continues to work after `uv sync` removes the project copy of `pre-commit`.
99+
100+
```bash
92101
uv tool install pre-commit
93-
pre-commit install
102+
"$(uv tool dir --bin)/pre-commit" install
94103
```
95104

96105
## Related docs

‎tests/unit/test_fossa_compat.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ def test_fossa_report_payload_vulnerability_shape_is_stable():
142142
assert generated_vulnerability["source"]["packageManager"] == "pip"
143143
assert generated_vulnerability["vulnId"] == "GHSA-9hjg-9r4m-mvj7"
144144
assert generated_vulnerability["cve"] == "CVE-2024-47081"
145+
expected_metrics = [
146+
{"name": "Attack Vector", "value": "Network"},
147+
{"name": "Attack Complexity", "value": "High"},
148+
{"name": "Privileges Required", "value": "None"},
149+
{"name": "User Interaction", "value": "Required"},
150+
{"name": "Scope", "value": "Unchanged"},
151+
{"name": "Confidentiality Impact", "value": "High"},
152+
{"name": "Integrity Impact", "value": "None"},
153+
{"name": "Availability Impact", "value": "None"},
154+
]
155+
assert generated_vulnerability["metrics"] == expected_metrics
156+
157+
diff.new_alerts[0].props["attackComplexity"] = ""
158+
del diff.new_alerts[0].props["availabilityImpact"]
159+
assert build_fossa_report_payload(diff, config)["vulnerability"][0]["metrics"] == [
160+
metric
161+
for metric in expected_metrics
162+
if metric["name"] not in {"Attack Complexity", "Availability Impact"}
163+
]
164+
165+
diff.new_alerts[0].props["metrics"] = [{"name": "Attack Vector", "value": "Local"}]
166+
assert build_fossa_report_payload(diff, config)["vulnerability"][0]["metrics"] == [
167+
{"name": "Attack Vector", "value": "Local"},
168+
]
145169

146170

147171
def test_project_metadata_uses_dollar_revision_separator():
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import re
2+
from pathlib import Path
3+
4+
WORKFLOW = Path(__file__).resolve().parents[2] / ".github/workflows/pr-preview.yml"
5+
6+
7+
def test_pr_preview_queue_keeps_multiple_pending_runs():
8+
workflow = WORKFLOW.read_text(encoding="utf-8")
9+
concurrency = re.search(r"^concurrency:\n((?:^ .+\n)+)", workflow, re.MULTILINE)
10+
11+
assert concurrency is not None
12+
assert " queue: max" in concurrency[1].splitlines()

0 commit comments

Comments
 (0)