-
Notifications
You must be signed in to change notification settings - Fork 2
Add sccache-report: a statistics step that survives a fallback (#546) #580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leynos
wants to merge
7
commits into
main
Choose a base branch
from
sccache-report-action
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
50e8667
Add sccache-report: a statistics step that survives a fallback
leynos 9723741
Run the sccache-report script tests on POSIX hosts only
leynos cf261a0
Prove the sccache-report guard under Git Bash on Windows
leynos 89a88c8
Validate the sccache-report paths and document the input contract
leynos 1bbcddf
Quote the stats-file in the example and document the action for callers
leynos 7bde12b
Correct the claim that --show-stats starts a server
leynos 02d0511
Run sccache-report through its composite boundary; add the migration …
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| # Changelog | ||
|
|
||
| All notable changes to the `sccache-report` action will be documented in this | ||
| file. | ||
|
|
||
| ## Unreleased | ||
|
|
||
| - Add the action. It prints sccache's statistics (text and JSON), appends them | ||
| to the job summary under the backend `setup-rust` chose, and stands down, | ||
| with a notice and `reported=false`, when `setup-rust` reports `sccache-status` | ||
| `fallback` or sccache is not on `PATH`. A consumer's health check conditions | ||
| on `reported` instead of repeating the guard that keeps an uncached job from | ||
| publishing a table of zeros. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # sccache-report | ||
|
|
||
| Prints sccache's statistics after a build, writes them as text and JSON, adds | ||
| them to the job summary, and stands down when [`setup-rust`](../setup-rust) | ||
| reports that the sccache server fell back to an uncached build. | ||
|
|
||
| ## Why it exists | ||
|
|
||
| With `setup-rust` at shared-actions #546 a server that will not start within | ||
| its 60 s timeout no longer fails the job: the action clears `RUSTC_WRAPPER`, | ||
| raises a `sccache-fallback` annotation and sets its `sccache-status` output to | ||
| `fallback`. A server that never started has no statistics: with no server, | ||
| `sccache --show-stats` does not start one (`sccache --zero-stats` does) and | ||
| prints empty default statistics, a table of zeros for a job that never used the | ||
| cache, which reads as a wrapper that never reached the compiler. Every consumer | ||
| that read statistics after the build carried the same guard by hand. This | ||
| action owns it once. | ||
|
|
||
| It cannot live inside `setup-rust`: the statistics exist only after the build, | ||
| when `setup-rust` has long finished, and a composite action has no post step. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```yaml | ||
| - uses: leynos/shared-actions/.github/actions/setup-rust@<sha> | ||
| id: setup-rust | ||
| - run: cargo build | ||
| - id: sccache | ||
| if: always() | ||
| uses: leynos/shared-actions/.github/actions/sccache-report@<sha> | ||
| with: | ||
| status: ${{ steps.setup-rust.outputs.sccache-status }} | ||
| backend: ${{ steps.setup-rust.outputs.cache-backend }} | ||
| - name: Check sccache health | ||
| if: steps.sccache.outputs.reported == 'true' | ||
| env: | ||
| STATS_FILE: ${{ steps.sccache.outputs.stats-file }} | ||
| run: python3 scripts/check_sccache_health.py "$STATS_FILE" | ||
| ``` | ||
|
|
||
| ## Inputs | ||
|
|
||
| All inputs are strings and all are optional. | ||
|
|
||
| | Name | Type | Required? | Description | Default | | ||
| | ---------- | ------ | --------- | ---------------------------------------------------------------------------------------------------- | -------------------- | | ||
| | status | string | no | The `sccache-status` output of setup-rust. `fallback` stands the action down; anything else reports. | `''` | | ||
| | backend | string | no | The `cache-backend` output of setup-rust, named in the summary. | `''` | | ||
| | stats-file | string | no | Path the JSON statistics are written to. Must not contain a line break. | `sccache-stats.json` | | ||
| | text-file | string | no | Path the human-readable statistics are written to. Must not contain a line break. | `sccache-stats.txt` | | ||
| | summary | string | no | `true` appends the statistics to the job summary. | `true` | | ||
|
|
||
| ## Outputs | ||
|
|
||
| | Name | Description | | ||
| | ---------- | -------------------------------------------------------------------------------------------------------------- | | ||
| | reported | `true` when statistics were written, `false` when the action stood down (a fallback, or no sccache on `PATH`). | | ||
| | stats-file | The JSON path when `reported` is `true`, else empty. | | ||
|
|
||
| A health check that reads the JSON conditions on `reported`, so the guard lives | ||
| here and not in each consumer. Standing down is reported as a notice titled | ||
| `sccache-report` and as | ||
| `metric sccache-report.outcome=<reported|fallback|not-installed>`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| name: Report sccache statistics | ||
| description: >- | ||
| Print sccache's statistics, write them as text and JSON, and add them to the | ||
| job summary, standing down when setup-rust reports that the server fell back | ||
| to an uncached build. Call it after the build, under `if: always()`. | ||
|
|
||
| inputs: | ||
| status: | ||
| description: >- | ||
| The `sccache-status` output of setup-rust. `fallback` means the server | ||
| never started: there are no statistics (with no server `sccache | ||
| --show-stats` prints empty defaults), so the action reports nothing and | ||
| says so. Any other value, including empty, reports. | ||
| required: false | ||
| default: '' | ||
| backend: | ||
| description: >- | ||
| The `cache-backend` output of setup-rust, named in the summary because | ||
| `Cache location` reads `ghac` for Ubicloud's proxy and for GitHub's own | ||
| service alike. | ||
| required: false | ||
| default: '' | ||
| stats-file: | ||
| description: Path the JSON statistics are written to. | ||
| required: false | ||
| default: sccache-stats.json | ||
| text-file: | ||
| description: Path the human-readable statistics are written to. | ||
| required: false | ||
| default: sccache-stats.txt | ||
| summary: | ||
| description: >- | ||
| "true" (the default) appends the statistics to the job summary. Anything | ||
| else leaves the summary alone. | ||
| required: false | ||
| default: 'true' | ||
|
|
||
| outputs: | ||
| reported: | ||
| description: >- | ||
| "true" when statistics were written, "false" when the action stood down | ||
| (a fallback, or no sccache on PATH). A consumer's health check conditions | ||
| on this instead of repeating the guard. | ||
| value: ${{ steps.report.outputs.reported }} | ||
| stats-file: | ||
| description: Path of the JSON statistics when `reported` is "true", else empty. | ||
| value: ${{ steps.report.outputs.stats-file }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Report sccache statistics | ||
| id: report | ||
| shell: bash | ||
| env: | ||
| SR_STATUS: ${{ inputs.status }} | ||
| SR_BACKEND: ${{ inputs.backend }} | ||
| SR_STATS_FILE: ${{ inputs.stats-file }} | ||
| SR_TEXT_FILE: ${{ inputs.text-file }} | ||
| SR_SUMMARY: ${{ inputs.summary }} | ||
| run: | | ||
| set -euo pipefail | ||
| # The paths are caller input and the stats-file is written as a | ||
| # `name=value` output record, where a line break would start another | ||
| # record (`x\nreported=false` would override the real one). A path with | ||
| # a line break is refused rather than encoded. | ||
| for path in "${SR_STATS_FILE}" "${SR_TEXT_FILE}"; do | ||
| case "$path" in | ||
| *$'\n'*|*$'\r'*) | ||
| echo "::error title=sccache-report::stats-file and text-file must not contain line breaks" >&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
| stand_down() { | ||
| echo "reported=false" >> "$GITHUB_OUTPUT" | ||
| echo "stats-file=" >> "$GITHUB_OUTPUT" | ||
| echo "::notice title=sccache-report::$1" | ||
| echo "metric sccache-report.outcome=$2" | ||
| } | ||
| # A server that fell back never started. With no server, | ||
| # `sccache --show-stats` does not start one (that is `--zero-stats`); | ||
| # it prints empty default statistics. Reporting them would publish a | ||
| # table of zeros for a job that never used the cache, which reads as a | ||
| # wrapper that never reached the compiler. | ||
| if [[ "${SR_STATUS}" == fallback ]]; then | ||
| stand_down "sccache fell back to an uncached build; there are no statistics to report" fallback | ||
| exit 0 | ||
| fi | ||
| if ! command -v sccache >/dev/null 2>&1; then | ||
| stand_down "sccache is not on PATH; there are no statistics to report" not-installed | ||
| exit 0 | ||
| fi | ||
| stats="$(sccache --show-stats)" | ||
| printf '%s\n' "$stats" | tee -- "${SR_TEXT_FILE}" | ||
| sccache --show-stats --stats-format json > "${SR_STATS_FILE}" | ||
| # The log copy is the one that can be read afterwards: the job summary | ||
| # is not available through the REST API. | ||
| if [[ "${SR_SUMMARY}" == true && -n "${GITHUB_STEP_SUMMARY:-}" ]]; then | ||
| { | ||
| printf '### sccache\n\n' | ||
| if [[ -n "${SR_BACKEND}" ]]; then | ||
| printf -- '- backend: `%s`\n\n' "${SR_BACKEND}" | ||
| fi | ||
| printf '```text\n%s\n```\n' "$stats" | ||
| } >> "${GITHUB_STEP_SUMMARY}" | ||
| fi | ||
| echo "reported=true" >> "$GITHUB_OUTPUT" | ||
| echo "stats-file=${SR_STATS_FILE}" >> "$GITHUB_OUTPUT" | ||
| echo "metric sccache-report.outcome=reported" | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.