Skip to content

fix(impact): name the changed files it could not analyse (#454) #460

fix(impact): name the changed files it could not analyse (#454)

fix(impact): name the changed files it could not analyse (#454) #460

Workflow file for this run

# .github/workflows/action-smoke.yml
name: Action smoke
'on':
pull_request:
branches: ['**']
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# The composite installs `diffctx==<default>` from PyPI, so `uses: ./` alone
# exercised this branch's action.yml around the RELEASED wheel: a PR renaming
# --tau or moving diffctx.tokens.count_tokens passed every leg and broke on
# every Marketplace consumer once cd.yml bumped the default. This job builds
# the branch's own wheel; the legs below point pip at it with PIP_NO_INDEX so
# the install cannot silently come from PyPI. pathspec rides along because
# no-index has nowhere else to take the one runtime dependency from.
# Known-bad: rename --tau on a branch — the tuned-inputs legs must go red.
build-pr-wheel:
name: Build this branch's wheel (${{ matrix.os }})
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: '3.13'
- name: Build wheel via maturin
uses: PyO3/maturin-action@e83996d129638aa358a18fbd1dfb82f0b0fb5d3b # v1.51.0
with:
manylinux: ${{ runner.os == 'Linux' && '2_28' || 'off' }}
args: --release --out dist
rust-toolchain: '1.92.0'
- name: Add the runtime dependency for a no-index install
shell: bash
run: |
python -m pip download --quiet --disable-pip-version-check \
--only-binary :all: --dest dist pathspec
ls -la dist
- name: Upload wheel
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: pr-wheel-${{ matrix.os }}
path: dist/*.whl
if-no-files-found: error
retention-days: 1
# Dogfood: run the composite action against this repository's own diff so a
# broken flag mapping, a missing output, or a yanked pinned release fails
# here instead of in a consumer repo.
action-smoke:
name: >-
Composite action (${{ matrix.label }}, ${{ matrix.os }}${{
matrix.source == 'pypi' && ', published wheel' || '' }})
needs: build-pr-wheel
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
label: [md-ego, json-bm25, yaml-full, tuned-inputs]
include:
- label: md-ego
format: md
scoring: ego
budget: '6000'
full: 'false'
- label: json-bm25
format: json
scoring: bm25
budget: '3000'
full: 'false'
- label: yaml-full
format: yaml
scoring: ego
budget: ''
full: 'true'
# The legs above leave tau/alpha/timeout/output-path empty, and every
# one of those is consumed behind an `if [ -n "$IN_X" ]` guard in
# action.yml — so renaming --tau in the CLI kept all three green. This
# leg is the only thing that actually threads them through.
- label: tuned-inputs
format: md
scoring: ppr
budget: '4000'
full: 'false'
tau: '0.05'
alpha: '0.9'
timeout: '300'
output-path: tuned-context.md
# One leg stays on PyPI: a yanked or broken published wheel is what a
# consumer pinning the default gets, and only this cell sees it.
- os: ubuntu-latest
label: md-ego
source: pypi
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
# Both endpoints of the analyzed range must exist locally.
fetch-depth: 0
- name: Download this branch's wheel
if: matrix.source != 'pypi'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-wheel-${{ matrix.os }}
path: dist
- name: Build diff context
id: diffctx
uses: ./
env:
PIP_FIND_LINKS: ${{ matrix.source != 'pypi' && format('{0}/dist', github.workspace) || '' }}
PIP_NO_INDEX: ${{ matrix.source != 'pypi' && '1' || '' }}
with:
format: ${{ matrix.format }}
scoring: ${{ matrix.scoring }}
budget: ${{ matrix.budget }}
full: ${{ matrix.full }}
tau: ${{ matrix.tau }}
alpha: ${{ matrix.alpha }}
timeout: ${{ matrix.timeout }}
output-path: ${{ matrix.output-path }}
- name: Assert the action produced usable context
shell: bash
env:
CONTEXT_FILE: ${{ steps.diffctx.outputs.context-file }}
TOKEN_COUNT: ${{ steps.diffctx.outputs.token-count }}
BYTE_SIZE: ${{ steps.diffctx.outputs.byte-size }}
DIFF_RANGE: ${{ steps.diffctx.outputs.diff-range }}
EMPTY: ${{ steps.diffctx.outputs.empty }}
run: |
set -euo pipefail
if [ -z "$DIFF_RANGE" ]; then
echo "diff-range output is empty"
exit 1
fi
if [ -z "$CONTEXT_FILE" ]; then
echo "context-file output is empty"
exit 1
fi
if [ ! -s "$CONTEXT_FILE" ]; then
echo "context file '$CONTEXT_FILE' is missing or empty"
exit 1
fi
case "$TOKEN_COUNT" in
'' | *[!0-9]*)
echo "token-count output is not a number: '$TOKEN_COUNT'"
exit 1
;;
esac
if [ "$TOKEN_COUNT" -le 0 ]; then
echo "token-count output must be positive, got $TOKEN_COUNT"
exit 1
fi
case "$BYTE_SIZE" in
'' | *[!0-9]*)
echo "byte-size output is not a number: '$BYTE_SIZE'"
exit 1
;;
esac
if [ "$EMPTY" != "true" ] && [ "$EMPTY" != "false" ]; then
echo "empty output must be true or false, got '$EMPTY'"
exit 1
fi
echo "range=$DIFF_RANGE tokens=$TOKEN_COUNT bytes=$BYTE_SIZE empty=$EMPTY"
- name: Upload context artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: diffctx-context-${{ matrix.label }}-${{ matrix.os }}${{ matrix.source == 'pypi' && '-pypi' || '' }}
path: ${{ steps.diffctx.outputs.context-file }}
if-no-files-found: error
retention-days: 7
# The action's one documented failure mode was a shallow checkout, and every
# leg above sidesteps it with fetch-depth: 0. This leg takes the checkout
# default (depth 1) and expects the action to fetch the range's endpoints
# itself — the fix that replaced the "add fetch-depth: 0" advice.
action-shallow-checkout:
name: Composite action (shallow checkout)
needs: build-pr-wheel
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code (depth 1)
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Assert the checkout really is shallow
run: test "$(git rev-parse --is-shallow-repository)" = "true"
- name: Download this branch's wheel
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-wheel-ubuntu-latest
path: dist
- name: Build diff context on the shallow clone
id: diffctx
uses: ./
env:
PIP_FIND_LINKS: ${{ github.workspace }}/dist
PIP_NO_INDEX: '1'
with:
format: md
budget: '4000'
- name: Assert the range resolved and produced context
env:
DIFF_RANGE: ${{ steps.diffctx.outputs.diff-range }}
CONTEXT_FILE: ${{ steps.diffctx.outputs.context-file }}
run: |
set -euo pipefail
test -n "$DIFF_RANGE"
test -s "$CONTEXT_FILE"
echo "OK: shallow checkout analyzed $DIFF_RANGE"
# Dogfood the *review*, not only the mechanism: the legs above prove the
# action runs; this job produces the artifact a reviewer of THIS pull
# request is meant to read instead of the raw diff, and pins it to the PR as
# one sticky comment. `/qa` reads it (QA.md § Diff-context review), and a
# selection that looks wrong on our own PRs is a product finding before any
# consumer sees it.
pr-review-context:
name: Review context for this PR
if: github.event_name == 'pull_request'
needs: build-pr-wheel
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Download this branch's wheel
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-wheel-ubuntu-latest
path: dist
- name: Build review context
id: diffctx
uses: ./
env:
PIP_FIND_LINKS: ${{ github.workspace }}/dist
PIP_NO_INDEX: '1'
with:
format: md
scoring: ego
budget: '8000'
# The impact view first: what this PR reaches outside its own diff is
# the part of the review that the raw diff cannot show, and it is small
# enough to sit in the comment itself.
- name: Build impact view
id: impact
uses: ./
env:
PIP_FIND_LINKS: ${{ github.workspace }}/dist
PIP_NO_INDEX: '1'
with:
mode: impact
format: md
output-path: ${{ runner.temp }}/diffctx-impact.md
- name: Upload review context
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: diffctx-review-context
path: |
${{ steps.diffctx.outputs.context-file }}
${{ steps.impact.outputs.context-file }}
if-no-files-found: error
retention-days: 14
- name: Summarise into the step summary
env:
CONTEXT_FILE: ${{ steps.diffctx.outputs.context-file }}
IMPACT_FILE: ${{ steps.impact.outputs.context-file }}
TOKEN_COUNT: ${{ steps.diffctx.outputs.token-count }}
DIFF_RANGE: ${{ steps.diffctx.outputs.diff-range }}
EMPTY: ${{ steps.diffctx.outputs.empty }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
OUT: ${{ runner.temp }}/comment.md
run: bash .github/scripts/pr-review-summary.sh
# A fork's GITHUB_TOKEN is read-only, so the POST 403s and took the whole
# job red with it; the step summary above is what a fork PR gets.
- name: Pin to the PR as one sticky comment
if: github.event.pull_request.head.repo.full_name == github.repository
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
COMMENT: ${{ runner.temp }}/comment.md
run: |
set -euo pipefail
marker=$(head -n 1 "$COMMENT")
api="repos/${GITHUB_REPOSITORY}/issues"
existing=$(gh api "${api}/${PR_NUMBER}/comments" --paginate \
--jq "[.[] | select(.body | startswith(\"${marker}\"))] | first | .id // empty")
if [ -n "$existing" ]; then
gh api -X PATCH "${api}/comments/${existing}" -F body=@"$COMMENT" >/dev/null
else
gh api -X POST "${api}/${PR_NUMBER}/comments" -F body=@"$COMMENT" >/dev/null
fi
# The fork-PR path of the job above, run on every event: the summary script
# with no token in the environment must still exit 0 and write the comment.
pr-review-summary-offline:
name: Review summary without a token
needs: build-pr-wheel
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Download this branch's wheel
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-wheel-ubuntu-latest
path: dist
- name: Build review context
id: diffctx
uses: ./
env:
PIP_FIND_LINKS: ${{ github.workspace }}/dist
PIP_NO_INDEX: '1'
with:
diff-range: HEAD~1..HEAD
budget: '4000'
- name: Summarise with GH_TOKEN unset
env:
CONTEXT_FILE: ${{ steps.diffctx.outputs.context-file }}
TOKEN_COUNT: ${{ steps.diffctx.outputs.token-count }}
DIFF_RANGE: ${{ steps.diffctx.outputs.diff-range }}
EMPTY: ${{ steps.diffctx.outputs.empty }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
OUT: ${{ runner.temp }}/comment.md
run: |
set -euo pipefail
env -u GH_TOKEN -u GITHUB_TOKEN bash .github/scripts/pr-review-summary.sh
head -n 1 "$OUT" | grep -qx '<!-- diffctx-review-context -->'
echo "OK: summary renders without a token"
# `fail-on-empty` gates whether a consumer's build breaks when a diff yields
# no semantic context. It sits behind an `if [ "$empty" = "true" ] && ...`
# branch in action.yml that no smoke leg ever entered, so the flag could stop
# working with every job still green. An empty range (HEAD..HEAD) forces the
# branch; the job passes only when the action actually fails.
action-fail-on-empty:
name: Composite action (fail-on-empty)
needs: build-pr-wheel
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout Code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: Download this branch's wheel
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: pr-wheel-ubuntu-latest
path: dist
- name: Build diff context over an empty range
id: diffctx
continue-on-error: true
uses: ./
env:
PIP_FIND_LINKS: ${{ github.workspace }}/dist
PIP_NO_INDEX: '1'
with:
diff-range: HEAD..HEAD
fail-on-empty: 'true'
- name: Assert the action reported failure
shell: bash
env:
OUTCOME: ${{ steps.diffctx.outcome }}
EMPTY: ${{ steps.diffctx.outputs.empty }}
run: |
set -euo pipefail
if [ "$OUTCOME" != "failure" ]; then
echo "fail-on-empty did not fail the step on an empty range (outcome=$OUTCOME)"
exit 1
fi
if [ "$EMPTY" != "true" ]; then
echo "expected empty=true on an empty range, got '$EMPTY'"
exit 1
fi
echo "OK: fail-on-empty failed the step as designed"