Skip to content

Commit

Permalink
[Ops] Fix deployment/project purging logic (elastic#172082)
Browse files Browse the repository at this point in the history
## Summary
We've noticed that on certain PRs, the deployments are cleaned up right
after they're creating, with the indication that it was stale.
(elastic#170579 - cleaned up in
https://buildkite.com/elastic/kibana-purge-cloud-deployments/builds/15440#018c1605-144b-4db5-b29a-e3af3c9b1c70)

Turns out, the logic that acquires the last commit's timestamp is
relying on the `gh pr` api, and commits are limited there to 100. It's
easier to look at the pr's `updatedAt` value.

- change purge logic to be based on the PRs updatedAt label instead of
the max-100th commit's timestamp

See: https://elastic.slack.com/archives/C5UDAFZQU/p1701093461763989
  • Loading branch information
delanni authored Nov 29, 2023
1 parent e3d95e9 commit becae46
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 2 additions & 3 deletions .buildkite/scripts/steps/cloud/purge_deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ const DAY_IN_SECONDS = 60 * 60 * 24;
for (const deployment of prDeployments) {
try {
const prNumber = deployment.name.match(/^kibana-pr-([0-9]+)$/)[1];
const prJson = execSync(`gh pr view '${prNumber}' --json state,labels,commits`).toString();
const prJson = execSync(`gh pr view '${prNumber}' --json state,labels,updatedAt`).toString();
const pullRequest = JSON.parse(prJson);
const prOpen = pullRequest.state === 'OPEN';

const lastCommit = pullRequest.commits.slice(-1)[0];
const lastCommitTimestamp = new Date(lastCommit.committedDate).getTime() / 1000;
const lastCommitTimestamp = new Date(pullRequest.updatedAt).getTime() / 1000;

const persistDeployment = Boolean(
pullRequest.labels.filter((label: any) => label.name === 'ci:cloud-persist-deployment').length
Expand Down
5 changes: 2 additions & 3 deletions .buildkite/scripts/steps/cloud/purge_projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ async function purgeProjects() {
const NOW = new Date().getTime() / 1000;
const DAY_IN_SECONDS = 60 * 60 * 24;
const prJson = execSync(
`gh pr view '${project.prNumber}' --json state,labels,commits`
`gh pr view '${project.prNumber}' --json state,labels,updatedAt`
).toString();
const pullRequest = JSON.parse(prJson);
const prOpen = pullRequest.state === 'OPEN';
const lastCommit = pullRequest.commits.slice(-1)[0];
const lastCommitTimestamp = new Date(lastCommit.committedDate).getTime() / 1000;
const lastCommitTimestamp = new Date(pullRequest.updatedAt).getTime() / 1000;

const persistDeployment = Boolean(
pullRequest.labels.filter((label: any) => label.name === 'ci:project-persist-deployment')
Expand Down

0 comments on commit becae46

Please sign in to comment.