Skip to content

ci: refresh popular.json inline in deploy workflow - #51

Merged
Nick Brady (nicholasdbrady) merged 5 commits into
mainfrom
nicholasdbrady/update-popular-use-github-app-token
Jun 15, 2026
Merged

Nick Brady (nicholasdbrady) merged 5 commits into
mainfrom
nicholasdbrady/update-popular-use-github-app-token

Conversation

@nicholasdbrady

@nicholasdbrady Nick Brady (nicholasdbrady) commented Jun 15, 2026 •

Copy link
Copy Markdown
Member

Why

update-popular.yml has been failing every scheduled run since 2026-05-28 with:

##[error]GitHub Actions is not permitted to create or approve pull requests.

The App Insights query inside the workflow actually succeeds — only the peter-evans/create-pull-request@v8 step fails. The repo-level toggle to allow the Actions bot to open PRs is greyed out because the microsoftopensource enterprise disabled it permanently as part of the SSIRP 23011 mitigation.

The documented workaround (using a GitHub App identity for the create-pull-request token) is explicitly flagged "Here be dragons! This is NOT recommended if you are attaching to production systems." in Microsoft OSPO's GitHub Actions Security Announcement. For a non-blocking popularity refresh, that's not the right trade.

What

Fold the App Insights fetch directly into deploy.yml so the refreshed popular.json is consumed by the build and pushed via the existing GitHub Pages deploy — no commits, no pull requests, no new identities.

  • deploy.yml
    • Add schedule: "0 6 * * *" daily trigger so freshness matches the previous behaviour.
    • Add id-token: write permission and Azure OIDC login (mirrors what update-popular.yml used).
    • New step Refresh popular notebooks data from App Insights runs scripts/fetch-popular.ts before astro build. Marked continue-on-error: true so a transient telemetry outage degrades to using the committed popular.json instead of failing the deploy.
    • Companion step logs a ::warning:: if the refresh failed, so the miss is visible in the Actions UI.
  • update-popular.yml — deleted.
  • validate-popular-fetch.yml — new manual-only diagnostic that runs Azure OIDC login + fetch-popular.ts without touching the build or gh-pages. Useful for one-off validation and ongoing debugging.
  • AGENTS.md + .github/AGENTS.md — updated CI table and the "Popular Notebooks" section to describe the new behaviour.
  • preview.yml — intentionally unchanged. Fork PRs must not receive Azure credentials, and they're fine using the committed fallback.

Verification

  • cd site && npm ci && npm run build passes locally using the committed popular.json fallback path (exercising the same code path CI will hit on App Insights failure).
  • The validation workflow was exercised on this branch via a temporary pull_request trigger (now removed). It failed at the Azure login step with AADSTS700213: No matching federated identity record found for presented assertion subject 'repo:microsoft-foundry/forgebook:pull_request' — which is the correct security posture. The Entra app's federated credential is scoped to ref:refs/heads/main, so:
    • PR runs (including from forks) cannot acquire Azure tokens ✅
    • push to main, schedule, and workflow_dispatch from main all produce the trusted ref:refs/heads/main subject and will authenticate, exactly like the old update-popular.yml did.
  • No new secrets required — AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID, and vars.APP_INSIGHTS_RESOURCE_ID already exist from the deleted workflow.

Rollout

After merging, dispatch the diagnostic workflow from main once:

gh workflow run validate-popular-fetch.yml --ref main
gh run watch

It will log the freshly-fetched popular.json without touching production. Once that's green, the next push to main (or the 06:00 UTC cron) will use the same code path inside deploy.yml.

The standalone update-popular.yml has been failing every day since

2026-05-28 because it relies on the GITHUB_TOKEN opening a pull

request, which the microsoftopensource enterprise has disabled

permanently (SSIRP 23011). The documented workaround is a GitHub App,

but OSPO labels that 'Here be dragons' and it isn't appropriate for

this low-stakes, non-blocking data refresh.

Instead, fold the App Insights fetch into deploy.yml so the freshly

queried data is written into the build directly. Add a daily cron

trigger to deploy.yml so freshness matches the previous behaviour.

If the App Insights query fails, the step is marked continue-on-error

and the build falls back to the committed site/src/data/popular.json,

with a workflow warning recording the miss. preview.yml is left alone

so fork PRs never receive Azure credentials.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

🔍 Preview

A live preview of this PR is available at:
https://microsoft-foundry.github.io/forgebook/preview/pr-51/

Lets us exercise Azure OIDC login + scripts/fetch-popular.ts on demand

without rebuilding the site or pushing to gh-pages, so we can prove the

federated credential and App Insights query work before relying on

deploy.yml's scheduled refresh.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…alidation

Removed before merge. workflow_dispatch isn't dispatchable on a workflow

that doesn't yet exist on the default branch, so we let this PR trigger it

via pull_request on relevant paths.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The trigger surfaced an expected fed-cred mismatch (PR events use subject

'repo:.../forgebook:pull_request' which the Entra app intentionally

doesn't trust). The production triggers in deploy.yml (push to main,

schedule, workflow_dispatch from main) all map to the existing

ref:refs/heads/main subject and will continue to authenticate.

Run \gh workflow run validate-popular-fetch.yml\ from main after merge

to confirm end to end before relying on the scheduled refresh.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nicholasdbrady
Nick Brady (nicholasdbrady) enabled auto-merge (squash) June 15, 2026 18:18
@nicholasdbrady
Nick Brady (nicholasdbrady) merged commit 8ed3a97 into main Jun 15, 2026
5 of 6 checks passed
@nicholasdbrady
Nick Brady (nicholasdbrady) deleted the nicholasdbrady/update-popular-use-github-app-token branch June 15, 2026 18:19
github-actions Bot added a commit that referenced this pull request Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant