Repository navigation
feat(token-report): org-wide weekly Token Cost Observatory report #456
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b5215c6
feat(token-report): org-wide weekly Token Cost Observatory report
e69063f
fix(reviews): address review comments [skip ci-relay]
donpetry-bot 2b400b3
chore: apply manual instructions [skip ci-relay]
donpetry-bot b96f7b8
chore: apply manual instructions [skip ci-relay]
donpetry-bot d20291e
fix(reviews): address review comments [skip ci-relay]
donpetry-bot f2efafe
feat(token-report): add effective-dated USD cost + unify ET with pric…
227ba1a
ci(token-report): lint model-pricing.sh + model_pricing.bats; documen…
f8008fb
fix(token-report): avoid SIGPIPE abort when trimming PR list
483337f
feat(token-metrics): capture real token usage incl. cache (all engines)
3382c0d
Merge branch 'main' into feat/token-report-weekly
don-petry 3144818
Merge branch 'main' into feat/token-report-weekly
don-petry 67b6b95
fix(reviews): address review comments [skip ci-relay]
donpetry-bot 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
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
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,119 @@ | ||
| # ───────────────────────────────────────────────────────────────────────────── | ||
| # SOURCE OF TRUTH: petry-projects/.github-private/.github/workflows/token-report.yml | ||
| # | ||
| # AGENTS — READ BEFORE EDITING: | ||
| # • Weekly Token Cost Observatory report. The org-wide collection + aggregation | ||
| # logic lives in scripts/token_report.sh (unit-tested in tests/token_report.bats). | ||
| # • The script reads token-usage artifacts from EVERY non-archived repo in the org, | ||
| # so it needs GH_PAT_WORKFLOWS (cross-org actions:read) — github.token cannot read | ||
| # other repos' artifacts. | ||
| # • The report is posted as a comment on a single pinned tracking issue | ||
| # (label: token-report) in .github-private, so github.token suffices for the | ||
| # comment step. | ||
| # • Do NOT change checkout ref from 'main'. | ||
| # ───────────────────────────────────────────────────────────────────────────── | ||
| name: Token Cost Report | ||
|
|
||
| on: | ||
| schedule: | ||
| # Mondays at 08:00 UTC — weekly cost rollup before the work week | ||
| - cron: '0 8 * * 1' | ||
| workflow_dispatch: | ||
| inputs: | ||
| org: | ||
| description: "GitHub org to scan" | ||
| required: false | ||
| default: "petry-projects" | ||
| type: string | ||
| lookback_days: | ||
| description: "Days of token-usage history to include" | ||
| required: false | ||
| default: "7" | ||
| type: string | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| concurrency: | ||
| group: token-report-${{ inputs.org || 'petry-projects' }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| report: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| env: | ||
| ORG: ${{ inputs.org || 'petry-projects' }} | ||
| LOOKBACK_DAYS: ${{ inputs.lookback_days || '7' }} | ||
|
|
||
| steps: | ||
| - name: Checkout agent repo | ||
| uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | ||
| with: | ||
| repository: petry-projects/.github-private | ||
| ref: main | ||
| token: ${{ secrets.GH_PAT_WORKFLOWS }} | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| - name: Generate org-wide token report | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GH_PAT_WORKFLOWS }} | ||
| TOKEN_REPORT_OUT: token_report.md | ||
| run: | | ||
| bash scripts/token_report.sh >> "$GITHUB_STEP_SUMMARY" | ||
|
|
||
| - name: Post report to tracking issue | ||
| if: hashFiles('token_report.md') != '' | ||
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| with: | ||
| github-token: ${{ github.token }} | ||
| script: | | ||
| const fs = require('fs'); | ||
| const MAX = 65000; | ||
| let report = fs.readFileSync('token_report.md', 'utf8'); | ||
| if (!report.trim()) { core.setFailed('Report file is empty'); return; } | ||
|
|
||
| const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`; | ||
| if (report.length > MAX) { | ||
| report = report.slice(0, MAX) + | ||
| `\n\n---\n_Report truncated — full output in the [workflow run summary](${runUrl})._`; | ||
| } | ||
|
|
||
| const LABEL = 'token-report'; | ||
| const TITLE = '📊 Token Cost Observatory — Weekly Report'; | ||
|
|
||
| // Ensure the tracking label exists. | ||
| try { | ||
| await github.rest.issues.getLabel({ owner: context.repo.owner, repo: context.repo.repo, name: LABEL }); | ||
| } catch (e) { | ||
| await github.rest.issues.createLabel({ | ||
| owner: context.repo.owner, repo: context.repo.repo, | ||
| name: LABEL, color: '5319e7', | ||
| description: 'Weekly Token Cost Observatory report', | ||
| }); | ||
| } | ||
|
|
||
| // Find-or-create the single pinned tracking issue. | ||
| const existing = await github.paginate(github.rest.issues.listForRepo, { | ||
| owner: context.repo.owner, repo: context.repo.repo, | ||
| labels: LABEL, state: 'open', per_page: 100, | ||
| }); | ||
|
|
||
| let issue = existing.find(i => i.title === TITLE); | ||
| if (!issue) { | ||
| const created = await github.rest.issues.create({ | ||
| owner: context.repo.owner, repo: context.repo.repo, | ||
| title: TITLE, labels: [LABEL], | ||
| body: 'Tracking issue for the weekly Token Cost Observatory report. ' + | ||
| 'Each run posts a new comment below with org-wide Effective Tokens (ET) usage.\n\n' + | ||
| 'Source: `scripts/token_report.sh` · `.github/workflows/token-report.yml`', | ||
| }); | ||
| issue = created.data; | ||
| core.notice(`Created tracking issue #${issue.number}: ${issue.html_url}`); | ||
| } | ||
|
|
||
| const comment = await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, repo: context.repo.repo, | ||
| issue_number: issue.number, body: report, | ||
| }); | ||
| core.notice(`Posted weekly token report: ${comment.data.html_url}`); | ||
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
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
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.