diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index e68c2e37..7ebc74ac 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -5,7 +5,7 @@ "plugins": [ { "name": "visualci", - "version": "0.1.57", + "version": "0.1.59", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.claude-plugin/plugin.json b/.claude-plugin/plugin.json index 41714f2f..45d23bbe 100644 --- a/.claude-plugin/plugin.json +++ b/.claude-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.57", + "version": "0.1.59", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring", "url": "https://visualci.com" }, "homepage": "https://visualci.com/docs/skills/", diff --git a/.cursor-plugin/plugin.json b/.cursor-plugin/plugin.json index 91bfc4ab..4b8d888f 100644 --- a/.cursor-plugin/plugin.json +++ b/.cursor-plugin/plugin.json @@ -1,7 +1,7 @@ { "name": "visualci", "displayName": "VisualCI", - "version": "0.1.57", + "version": "0.1.59", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "author": { "name": "DocSpring" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 794b7582..ef1da708 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -367,6 +367,44 @@ jobs: timeout-minutes: 15 steps: - uses: actions/checkout@v4 + # The GitHub Action (sc-9246): with no token and no VISUALCI_TOKEN it fails, so a missing or misnamed secret + # can't pass quietly; with VISUALCI_TOKEN only in env, every CLI call gets it. It skips fork and Dependabot + # runs, so these checks run only on this repository's own. + - id: no-token + if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) + uses: ./clients/github-action + continue-on-error: true + - if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) + env: + OUTCOME: ${{ steps.no-token.outcome }} + SKIPPED: ${{ steps.no-token.outputs.skipped }} + run: | + if [ "$OUTCOME" != failure ] || [ -n "$SKIPPED" ]; then + echo "::error::the action without a token should fail at its token step (outcome $OUTCOME, skipped '$SKIPPED')" + exit 1 + fi + # A stub CLI that records the token each call gets. + cat > "$RUNNER_TEMP/visualci-stub" <<'STUB' + #!/bin/sh + echo "$1 $VISUALCI_TOKEN" >> "$RUNNER_TEMP/visualci-stub.log" + [ "$1" = build ] && [ "$2" = create ] && echo 1 + exit 0 + STUB + - id: env-token + if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) + uses: ./clients/github-action + env: + VISUALCI_TOKEN: env-only-token + with: + cli: ${{ runner.temp }}/visualci-stub + upload: some/dir + - if: github.actor != 'dependabot[bot]' && !github.event.repository.fork && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository) + env: + SKIPPED: ${{ steps.env-token.outputs.skipped }} + run: | + cat "$RUNNER_TEMP/visualci-stub.log" + [ "$SKIPPED" = false ] || { echo "::error::skipped with VISUALCI_TOKEN in env ($SKIPPED)"; exit 1; } + [ "$(grep -c ' env-only-token$' "$RUNNER_TEMP/visualci-stub.log")" = 3 ] || { echo "::error::not every CLI call got the env token"; exit 1; } - uses: ruby/setup-ruby@v1 with: ruby-version: "3.4" diff --git a/clients/github-action/action.yml b/clients/github-action/action.yml index 98f09943..2a1dcbec 100644 --- a/clients/github-action/action.yml +++ b/clients/github-action/action.yml @@ -8,8 +8,10 @@ branding: inputs: token: description: > - A VisualCI project token (secrets.VISUALCI_TOKEN). Empty on pull requests from forks, which are skipped with a - notice; send theirs from a workflow_run workflow instead (visualci.com/docs/ci/github-actions/#pull-requests-from-forks). + A VisualCI project token (secrets.VISUALCI_TOKEN). Left out, the action reads VISUALCI_TOKEN from the workflow's + or job's env. With neither, the step fails, except where GitHub passes no repository secrets (a fork's pull + request, a run in a fork, Dependabot's pull requests), which are skipped with a notice; send theirs from a workflow_run workflow instead + (visualci.com/docs/ci/github-actions/#pull-requests-from-forks). required: false default: "" upload: @@ -66,7 +68,7 @@ outputs: description: The build's id (empty when skipped). value: ${{ steps.build.outputs.id }} skipped: - description: true when there was no token (a fork's pull request). + description: true when VisualCI was skipped for lack of secrets (a fork's pull request, a run in a fork, or Dependabot's). value: ${{ steps.token.outputs.skipped }} runs: @@ -75,13 +77,30 @@ runs: - id: token shell: bash env: - TOKEN: ${{ inputs.token }} + TOKEN: ${{ inputs.token || env.VISUALCI_TOKEN }} + EVENT: ${{ github.event_name }} + HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} + REPO: ${{ github.repository }} + ACTOR: ${{ github.actor }} + IS_FORK: ${{ github.event.repository.fork }} run: | - if [ -z "$TOKEN" ]; then - echo "::notice title=VisualCI skipped::No VisualCI token (secrets aren't passed to pull requests from forks)." + # Skipped only where GitHub passes no repository secrets: a fork's pull request (its head repository differs, + # or was deleted), a run in a fork itself, and Dependabot's own events (Dependabot secrets only). Everywhere + # else, pull_request_target and workflow_run included, a missing token is a mistake and fails. + if [ -n "$TOKEN" ]; then + echo "skipped=false" >> "$GITHUB_OUTPUT" + elif [ "$IS_FORK" = true ]; then + echo "::notice title=VisualCI skipped::No VisualCI token: this workflow runs in a fork, which has no VisualCI token. Its pull request is sent from the upstream repository." + echo "skipped=true" >> "$GITHUB_OUTPUT" + elif [ "$EVENT" = pull_request ] && [ "$HEAD_REPO" != "$REPO" ]; then + echo "::notice title=VisualCI skipped::No VisualCI token: GitHub passes no secrets to a pull request from a fork. Send its snapshots from a workflow_run workflow: https://visualci.com/docs/ci/github-actions/#pull-requests-from-forks" + echo "skipped=true" >> "$GITHUB_OUTPUT" + elif [ "$ACTOR" = "dependabot[bot]" ] && [ "$EVENT" != workflow_run ] && [ "$EVENT" != pull_request_target ]; then + echo "::notice title=VisualCI skipped::No VisualCI token: Dependabot's runs get only Dependabot secrets. Add VISUALCI_TOKEN to the repository's Dependabot secrets to review its pull requests too." echo "skipped=true" >> "$GITHUB_OUTPUT" else - echo "skipped=false" >> "$GITHUB_OUTPUT" + echo "::error title=No VisualCI token::Pass the project token as the action's token input (the VISUALCI_TOKEN secret) or set VISUALCI_TOKEN in the job's env. If the secret is set, check its name and that this workflow can read it." + exit 1 fi # In a workflow_run workflow (a fork's pull request, sent with secrets afterwards), the build belongs to the @@ -156,7 +175,7 @@ runs: if: steps.token.outputs.skipped == 'false' shell: bash env: - VISUALCI_TOKEN: ${{ inputs.token }} + VISUALCI_TOKEN: ${{ inputs.token || env.VISUALCI_TOKEN }} VISUALCI_API_URL: ${{ inputs.api-url }} NAME: ${{ inputs.name }} run: | @@ -167,7 +186,7 @@ runs: - if: steps.token.outputs.skipped == 'false' && inputs.finalize-only != 'true' shell: bash env: - VISUALCI_TOKEN: ${{ inputs.token }} + VISUALCI_TOKEN: ${{ inputs.token || env.VISUALCI_TOKEN }} VISUALCI_API_URL: ${{ inputs.api-url }} VISUALCI_BUILD_ID: ${{ steps.build.outputs.id }} UPLOAD: ${{ inputs.upload }} @@ -192,7 +211,7 @@ runs: - if: steps.token.outputs.skipped == 'false' && (inputs.finalize == 'true' || inputs.finalize-only == 'true') shell: bash env: - VISUALCI_TOKEN: ${{ inputs.token }} + VISUALCI_TOKEN: ${{ inputs.token || env.VISUALCI_TOKEN }} VISUALCI_API_URL: ${{ inputs.api-url }} VISUALCI_BUILD_ID: ${{ steps.build.outputs.id }} WAIT: ${{ inputs.wait }} diff --git a/frontend/content/docs/ci/github-actions.md b/frontend/content/docs/ci/github-actions.md index cdf0f8d7..8695bc76 100644 --- a/frontend/content/docs/ci/github-actions.md +++ b/frontend/content/docs/ci/github-actions.md @@ -26,11 +26,11 @@ jobs: screenshots --platform chromium-linux --threshold 0.1 ``` -The action installs the CLI, creates the build, uploads and finalizes it. `upload` takes one `visualci upload` per line, as its arguments (paths, `--from`, `--prefix`, `--platform`, `--format`); leave it out to send the `uploads` in [visualci.yml](/docs/reference/config/). Pull requests from forks get no secrets, so the action skips them with a notice; [send theirs from a second workflow](#pull-requests-from-forks). +The action installs the CLI, creates the build, uploads and finalizes it. `upload` takes one `visualci upload` per line, as its arguments (paths, `--from`, `--prefix`, `--platform`, `--format`); leave it out to send the `uploads` in [visualci.yml](/docs/reference/config/). Without a token the step fails, so a misnamed secret can't pass quietly. The token comes from `token`, or from `VISUALCI_TOKEN` in the workflow's or job's `env`. The exceptions are where GitHub passes no repository secrets: a fork's pull request and runs in a fork get none, and Dependabot's pull requests get only Dependabot secrets. The action skips those with a notice; [send a fork's from a second workflow](#pull-requests-from-forks), and add `VISUALCI_TOKEN` to the Dependabot secrets to review Dependabot's. | Input | What it does | | --- | --- | -| `token` | The project token. Empty skips VisualCI with a notice. | +| `token` | The project token, else `VISUALCI_TOKEN` from `env`. With neither, the step fails (see above for the runs it skips). | | `upload` | What to send, one `visualci upload` argument line per line. | | `name` | The build's name, one per suite, each with its own GitHub check. Default `default`. | | `wait` | Wait for the result, and fail the step when the project's CI mode says CI should fail. | diff --git a/gemini-extension.json b/gemini-extension.json index d2396d19..681c2af9 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "visualci", - "version": "0.1.57", + "version": "0.1.59", "description": "Visual regression and snapshot review for PDFs, screenshots, JSON, HTML and text: VisualCI's MCP server and its skills for each CI provider and test tool.", "mcpServers": { "visualci": { diff --git a/skills/visualci-github-actions/SKILL.md b/skills/visualci-github-actions/SKILL.md index 9db823a2..eca99362 100644 --- a/skills/visualci-github-actions/SKILL.md +++ b/skills/visualci-github-actions/SKILL.md @@ -31,11 +31,11 @@ jobs: screenshots --platform chromium-linux --threshold 0.1 ``` -The action installs the CLI, creates the build, uploads and finalizes it. `upload` takes one `visualci upload` per line, as its arguments (paths, `--from`, `--prefix`, `--platform`, `--format`); leave it out to send the `uploads` in [visualci.yml](https://visualci.com/docs/reference/config.md). Pull requests from forks get no secrets, so the action skips them with a notice; [send theirs from a second workflow](#pull-requests-from-forks). +The action installs the CLI, creates the build, uploads and finalizes it. `upload` takes one `visualci upload` per line, as its arguments (paths, `--from`, `--prefix`, `--platform`, `--format`); leave it out to send the `uploads` in [visualci.yml](https://visualci.com/docs/reference/config.md). Without a token the step fails, so a misnamed secret can't pass quietly. The token comes from `token`, or from `VISUALCI_TOKEN` in the workflow's or job's `env`. The exceptions are where GitHub passes no repository secrets: a fork's pull request and runs in a fork get none, and Dependabot's pull requests get only Dependabot secrets. The action skips those with a notice; [send a fork's from a second workflow](#pull-requests-from-forks), and add `VISUALCI_TOKEN` to the Dependabot secrets to review Dependabot's. | Input | What it does | | --- | --- | -| `token` | The project token. Empty skips VisualCI with a notice. | +| `token` | The project token, else `VISUALCI_TOKEN` from `env`. With neither, the step fails (see above for the runs it skips). | | `upload` | What to send, one `visualci upload` argument line per line. | | `name` | The build's name, one per suite, each with its own GitHub check. Default `default`. | | `wait` | Wait for the result, and fail the step when the project's CI mode says CI should fail. |