πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ci): record PR previews as native GitHub deployments (#15158)
Max Deichmann48ef24e5141d
diff --git a/.agents/skills/langfuse-previews/SKILL.md b/.agents/skills/langfuse-previews/SKILL.mdindex a5a5803e4e..dfbacd9bd9 100644--- a/.agents/skills/langfuse-previews/SKILL.md+++ b/.agents/skills/langfuse-previews/SKILL.md@@ -36,8 +36,9 @@ Pushing updates it; closing the PR tears it down.## Using a preview- **Spin up** β open a same-repo PR. It's auto-labeled and builds (~5 min); a- bot comment then posts the preview URL and login. No manual step, no label to- add.+ bot comment then posts the preview URL and login, and a GitHub deployment+ (environment `pr-<n>`) gives the PR a **View deployment** button. No manual+ step, no label to add.- **Log in** β use the credentials in the **bot's PR comment** (the source oftruth). The demo project's shared seed identity is `[email protected]` /`password`, with API keys `pk-lf-1234567890` / `sk-lf-1234567890` β shared anddiff --git a/.github/workflows/preview-build.yml b/.github/workflows/preview-build.ymlindex 6d9562291f..f82e1e4e8a 100644--- a/.github/workflows/preview-build.yml+++ b/.github/workflows/preview-build.yml@@ -3,7 +3,9 @@ name: AWS preview build# Build the PR's web + worker images and push them to ECR as pr-<n>-<sha>.# The Argo CD ApplicationSet in the infrastructure repo deploys whichever image# tag exists for a labeled PR; this workflow only builds and pushes, then posts-# the preview URL on the PR.+# the preview URL on the PR β as the marker-tagged status comment and as a+# native GitHub deployment (the "View deployment" button), so the URL is+# findable without scrolling the timeline.## The two images are independent artifacts pushed to two independent ECR repos# under the same tag, with no ordering dependency between them. They therefore@@ -239,6 +241,9 @@ jobs:permissions:contents: readpull-requests: write+ # createDeployment/createDeploymentStatus for the native "View deployment"+ # button on the PR (see "Record GitHub deployment" below).+ deployments: writesteps:- name: Checkout base local actionsuses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3@@ -277,6 +282,63 @@ jobs:Synthetic preview data only. Never add production data to public accounts.+ # Record a native GitHub deployment for the preview, so the PR shows+ # "deployed to pr-<n>" with a "View deployment" button in the timeline /+ # merge box, and the environment appears on the repo's Deployments page.+ # Inline step (not the base-checkout composite action): it needs no shared+ # logic, and inline steps run from the PR's own workflow file.+ #+ # `state: success` mirrors the π’ comment's semantics β images pushed,+ # Argo CD rolling out; the URL is usually live minutes later. Like the+ # comment, it cannot see the infra-repo deploy allowlist, so for a+ # non-allowlisted author the deployment records but the URL 404s (same+ # caveat as the comment's debug-guide link). `auto_inactive` retires the+ # previous SHA's deployment on every new push; the preview-deactivate+ # workflow retires the last one when the PR closes.+ - name: Record GitHub deployment+ if: needs.build.result == 'success'+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0+ env:+ PREVIEW_SHA: ${{ needs.meta.outputs.commit_sha }}+ PREVIEW_HOST: ${{ needs.meta.outputs.preview_host }}+ PREVIEW_ENVIRONMENT: pr-${{ github.event.pull_request.number }}+ with:+ script: |+ const { owner, repo } = context.repo;+ const environment = process.env.PREVIEW_ENVIRONMENT;++ const { data: deployment } = await github.rest.repos.createDeployment({+ owner,+ repo,+ ref: process.env.PREVIEW_SHA,+ environment,+ // The images are the deployable; don't gate on commit statuses+ // (this very workflow is one of them) and never let GitHub+ // auto-merge base into the ref.+ required_contexts: [],+ auto_merge: false,+ transient_environment: true,+ description: `Langfuse PR preview at https://${process.env.PREVIEW_HOST}`,+ });+ // required_contexts: [] makes a non-201 unrepresentable in practice,+ // but createDeployment's 202 "merged deployment" response has no id+ // β fail loudly rather than posting a status against undefined.+ if (!deployment?.id) {+ core.setFailed(`createDeployment did not return a deployment id: ${JSON.stringify(deployment)}`);+ return;+ }++ await github.rest.repos.createDeploymentStatus({+ owner,+ repo,+ deployment_id: deployment.id,+ state: "success",+ environment_url: `https://${process.env.PREVIEW_HOST}`,+ log_url: `${process.env.GITHUB_SERVER_URL}/${owner}/${repo}/actions/runs/${process.env.GITHUB_RUN_ID}`,+ auto_inactive: true,+ });+ core.info(`Recorded deployment ${deployment.id} for ${environment}.`);+# Two distinct failure paths, each keyed on `== 'failure'` (NOT# `!= 'success'`): that keeps them from firing on `cancelled` (a# superseding push cancels the run via cancel-in-progress, and always()diff --git a/.github/workflows/preview-deactivate.yml b/.github/workflows/preview-deactivate.ymlnew file mode 100644index 0000000000..616929e5c4--- /dev/null+++ b/.github/workflows/preview-deactivate.yml@@ -0,0 +1,74 @@+name: AWS preview deactivate++# Mark the PR's GitHub deployments (environment pr-<n>, recorded by+# preview-build's "Record GitHub deployment" step) inactive when the PR closes.+# Closing/merging is what tears the preview down β the Argo CD ApplicationSet+# only generates Applications for OPEN labeled PRs β so without this the PR and+# the repo's Deployments page keep advertising an "Active" environment whose+# URL is gone.+#+# Deactivation only: GITHUB_TOKEN cannot delete environments (that needs repo+# administration permission), and inactive deployments are the standard way+# GitHub renders retired preview environments.+#+# Safe trigger: plain `pull_request: closed` with no checkout, no PR-code+# execution, no cloud credentials β only deployment-status mutations β so it+# stays off zizmor's dangerous-triggers list.+on:+ pull_request:+ types: [closed]++permissions: {}++jobs:+ deactivate:+ name: Mark preview deployments inactive+ runs-on: ubuntu-latest+ # AWS_PREVIEW_ECR_PUSH_ROLE_ARN is the preview-system feature flag (same+ # gate as preview-build / preview-autolabel): unset => system off, no+ # deployments were ever recorded.+ if: vars.AWS_PREVIEW_ECR_PUSH_ROLE_ARN != ''+ permissions:+ deployments: write+ steps:+ - name: Deactivate pr-<n> deployments+ uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0+ env:+ PREVIEW_ENVIRONMENT: pr-${{ github.event.pull_request.number }}+ with:+ script: |+ const { owner, repo } = context.repo;+ const environment = process.env.PREVIEW_ENVIRONMENT;++ const deployments = await github.paginate(github.rest.repos.listDeployments, {+ owner,+ repo,+ environment,+ per_page: 100,+ });+ if (deployments.length === 0) {+ core.info(`No deployments recorded for ${environment}; nothing to deactivate.`);+ return;+ }++ // Isolate failures per deployment (same pattern as the stale-cleanup+ // sweep): one transient 5xx must not skip the rest, and partial+ // failure should surface as a failed run rather than silent green.+ let failures = 0;+ for (const deployment of deployments) {+ try {+ await github.rest.repos.createDeploymentStatus({+ owner,+ repo,+ deployment_id: deployment.id,+ state: "inactive",+ });+ } catch (e) {+ failures++;+ core.warning(`Deployment ${deployment.id}: ${e.message} β continuing`);+ }+ }+ core.info(`Marked ${deployments.length - failures} of ${deployments.length} deployment(s) for ${environment} inactive.`);+ if (failures) {+ core.setFailed(`${failures} of ${deployments.length} deployment(s) could not be deactivated.`);+ }diff --git a/.github/workflows/preview-stale-cleanup.yml b/.github/workflows/preview-stale-cleanup.ymlindex 952024d96e..2d53471137 100644--- a/.github/workflows/preview-stale-cleanup.yml+++ b/.github/workflows/preview-stale-cleanup.yml@@ -46,6 +46,10 @@ jobs:# (NOT issues), even though they go through the issues REST endpoints β# same pattern as preview-autolabel / preview-build. Also covers pulls.list.pull-requests: write+ # Mark the reaped preview's GitHub deployments (environment pr-<n>,+ # recorded by preview-build) inactive alongside the label removal, so the+ # PR stops advertising an "Active" environment whose URL is gone.+ deployments: writesteps:- name: Reap stale previewsuses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0@@ -107,6 +111,25 @@ jobs:body: `π§Ή Preview environment torn down after **${staleDays} days** of inactivity `+ `(last update ${pr.updated_at}). Re-add the \`${label}\` label to redeploy.`,});++ // Retire the PR's GitHub deployments along with the preview+ // itself, so the PR stops showing an "Active" environment.+ // Re-adding the label redeploys, and the next build records a+ // fresh deployment.+ const deployments = await github.paginate(github.rest.repos.listDeployments, {+ owner,+ repo,+ environment: `pr-${pr.number}`,+ per_page: 100,+ });+ for (const deployment of deployments) {+ await github.rest.repos.createDeploymentStatus({+ owner,+ repo,+ deployment_id: deployment.id,+ state: "inactive",+ });+ }}} catch (e) {failures++;